Prev: Converting a process to an object
Next: Karl, slight bone to pick with ccrpCountdown.Duration = 0 causingcrash
From: Phil Hunt on 27 May 2010 18:07 I try to execute a vb6 statement Shell (Environ$("comspec") & " Shutdown -s -f") All I got was a command window, why ? I can type in shutdown in that window, it works. Just be careful should you decide to test it, it may shut you down. Thanks
From: Karl E. Peterson on 27 May 2010 19:06 Phil Hunt submitted this idea : > I try to execute a vb6 statement > Shell (Environ$("comspec") & " Shutdown -s -f") > > All I got was a command window, why ? I can type in shutdown in that window, > it works. Because you're not telling the shell what to do. If you were to type this at the command prompt, it wouldn't work either: C:\>cmd shutdown -s -f If you want to understand how to use the command processor, try asking it: C:\>cmd /? "Use the Force..." -- ..NET: It's About Trust! http://vfred.mvps.org Customer Hatred Knows No Bounds at MSFT ClassicVB Users Regroup! comp.lang.basic.visual.misc Free usenet access at http://www.eternal-september.org
From: Dave O. on 28 May 2010 05:14
You want to shut down your system in code, try this: I'm sure you can work out how the line wrapping should go. If you want to reboot the system use EWX_REBOOT instead of EWX_POWEROFF. (Thanks to whoever originally wrote the code that I appropriated this bit from) **** USE WITH CARE ***** Private Const ANYSIZE_ARRAY As Long = 1 Private Const EWX_POWEROFF As Long = 8 'Private Const EWX_REBOOT As Long = 2 Private Const SE_PRIVILEGE_ENABLED As Long = 2 Private Const SE_SHUTDOWN_NAME As String = "SeShutdownPrivilege" Private Const TOKEN_ADJUST_PRIVILEGES As Long = 32 Private Const TOKEN_QUERY As Long = 8 Private Type LUID LowPart As Long HighPart As Long End Type Private Type LUID_AND_ATTRIBUTES pLuid As LUID Attributes As Long End Type Private Type TOKEN_PRIVILEGES PrivilegeCount As Long Privileges(ANYSIZE_ARRAY) As LUID_AND_ATTRIBUTES End Type Private Declare Function AdjustTokenPrivileges Lib "advapi32" (ByVal TokenHandle As Long, ByVal DisableAllPrivileges As Long, ByRef NewState As TOKEN_PRIVILEGES, ByVal BufferLength As Long, ByRef PreviousState As TOKEN_PRIVILEGES, ByRef ReturnLength As Long) As Long Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long Private Declare Function GetCurrentProcess Lib "kernel32" () As Long Private Declare Function LookupPrivilegeValue Lib "advapi32" Alias "LookupPrivilegeValueA" (ByVal lpSystemName As String, ByVal lpName As String, ByRef lpLuid As LUID) As Long Private Declare Function OpenProcessToken Lib "advapi32" (ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, ByRef TokenHandle As Long) As Long Private Sub ShutDownSystem() On Error Resume Next Dim hProc As Long Dim hToken As Long Dim mLUID As LUID Dim mPriv As TOKEN_PRIVILEGES Dim mNewPriv As TOKEN_PRIVILEGES hProc = GetCurrentProcess() Call OpenProcessToken(hProc, TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY, hToken) Call LookupPrivilegeValue("", SE_SHUTDOWN_NAME, mLUID) mPriv.PrivilegeCount = 1 mPriv.Privileges(0).Attributes = SE_PRIVILEGE_ENABLED mPriv.Privileges(0).pLuid = mLUID If AdjustTokenPrivileges(hToken, False, mPriv, 4 + (12 * mPriv.PrivilegeCount), mNewPriv, 4 + (12 * mNewPriv.PrivilegeCount)) <> 0 Then ExitWindowsEx EWX_POWEROFF, 0 End Sub Regards DaveO "Phil Hunt" <aaa(a)aaa.com> wrote in message news:eNARKke$KHA.3176(a)TK2MSFTNGP05.phx.gbl... >I try to execute a vb6 statement > Shell (Environ$("comspec") & " Shutdown -s -f") > > All I got was a command window, why ? I can type in shutdown in that > window, it works. > Just be careful should you decide to test it, it may shut you down. > > Thanks > |