I'm trying to get the computer to sleep through excel VBA. For that to happen I need to disable hybernation which can only be done with elevated permissions. So I'm trying ShellExecute - following Microsoft's instructions on this page, but I'm getting an runtime error ('49' Bad DLL calling convention).
Edit: Changed the code and it works now, but the parameters are incorrect.
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _
ByVal hwnd As Long, _
ByVal lpszOp As String, _
ByVal lpszFile As String, _
ByVal lpszParams As String, _
ByVal lpszDir As String, _
ByVal FsShowCmd As Long) as long
Const SW_SHOWNORMAL as long = 1
Sub DoSleep()
ShellExecute 0, "runas", "C:\WINDOWS\System32\rundll32.exe", "powercfg -h off", "C:\", SW_SHOWNORMAL
Shell "C:\WINDOWS\System32\rundll32.exe powrprof.dll,SetSuspendState 0,1,0"
ShellExecute 0, "runas", "C:\WINDOWS\System32\rundll32.exe", "powercfg -h on", "C:\", SW_SHOWNORMAL
End Sub
SW_SHOWNORMAL
? – BondAs Long
to the end of the declaration. You're returning aVariant
because you haven't specified the return type so it doesn't match the function declaration in the DLL. – Bond