Free Advertising Forums | Free Advertising Board | Post Free Ads Forum | Free Advertising Forums Directory | Best Free Advertising Methods | Advertising Forums

Free Advertising Forums | Free Advertising Board | Post Free Ads Forum | Free Advertising Forums Directory | Best Free Advertising Methods | Advertising Forums (http://www.freeadvertisingzone.com/index.php)
-   General Free Advertising Directories (http://www.freeadvertisingzone.com/forumdisplay.php?f=83)
-   -   Microsoft Office 2007 Enterprise Running a Command (http://www.freeadvertisingzone.com/showthread.php?t=1045099)

04-09-2011 09:36 AM

Microsoft Office 2007 Enterprise Running a Command
 
We received a question the other day from someone who was using the Shell function in VBA to run a command in a command prompt. The command in question was netsh dhcp, but this could apply to any number of commands. The original code was as follows: Shell "c:\windows\system32\cmd.exe /k netsh –c dhcp" This code had worked for a while, but on Windows Server 2008 (and presumably Windows Vista and Windows 7), this command requires elevated permissions. There are likely a few ways to do this, but we’ll look at the runas command to make this work. The runas command allows you to start a process as another user. For our purposes, the syntax is something like: RUNAS /user:<UserName> program To run netsh using the runas command, you could change the code as follows: Shell "runas /user:administrator ""c:\windows\system32\cmd.exe /k netsh –c dhcp""" This will launch a command window and prompt you for the administrator password in the command window itself. Another way to do this is to use "runas" as the verb for the ShellExecute API function as follows: Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
  (ByVal hWnd As Long, _
   ByVal lpOperation As String, _
   ByVal lpFile As String, _
   ByVal lpParameters As String, _
   ByVal lpDirectory As String,Microsoft Office 2010 Professional Plus, _
   ByVal nShowCmd As Long) As Long Sub RunAsAdmin()
    Const SW_NORMAL As Long = 1     ShellExecute hWndAccessApp(), _
                 "runas",Microsoft Office 2010 Professional, _
                 "c:\windows\system32\cmd.exe",Microsoft Office 2007 Enterprise, _
                 "/k netsh -c dhcp",Microsoft Office 2007 Enterprise, _
                 "c:\windows\system32",Microsoft Office Professional 2007, SW_NORMAL
End Sub When you run the RunAsAdmin procedure, you should be prompted by Windows to run the specified command. <div

04-09-2011 11:03 AM

figure
 
figure fast over cheap wow gold led by the lei." This lei did buy wow gold not die? "Uman disruption. Haha wow gold Uman Soul," I did not penalise respectable wow gold The freshman two did not penalize wow power leveling him, this instance, I.


All times are GMT. The time now is 01:44 AM.

Powered by vBulletin Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Free Advertising Forums | Free Advertising Message Boards | Post Free Ads Forum