Hi All,
Through Excel 2007 VBA I want to run the command prompt as administrator and run "control userpasswords2".
I've tried this pasted into it's own module:
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, _
ByVal nShowCmd As Long) As Long
Sub RunAsAdmin()
Const SW_NORMAL As Long = 1
ShellExecute hWndAccessApp(), _
"runas", _
"c:\windows\system32\cmd.exe", _
"/k control userpasswords2", _
"c:\windows\system32", SW_NORMAL
End Sub
I've also tried:
Shell "runas /user:administrator ""c:\windows\system32\cmd.exe /k control userpasswords2"""The above does work as intended but isn't what I need.
What happens with the first snippet is "Compile error: Sub or Function not defined". With "
hWndAccessApp" highlighted.
I recognize that "hWnd..." isn't defined, but I don't know how to define it. And I see that all the other declarations don't play a part in what I want to do - lpOperaion, lpFile etc.
I copied the snippets from:
Access Blog - Running a Command as Administrator in VBAOther info, system: win7 enterprise, 64bit.
Any help or direction pointing would be greatly appreciated.
Thank you.