Well, I'm confused. I can't imagine you not having the SHExitWindowsEX
method in shell32.exe. All, I can guess at is either you are running
Vista 64 (I assumed 32), or some kind of error in copying what I
wrote.
The method, SHExitWindowsEx, accepts several parameters. Here are more
examples:
~*~*~*~*~
'This will log the user off.
oWshShell.Run "RunDll32.exe shell32.dll,SHExitWindowsEx 0"
'This will shutdown the computer.
oWshShell.Run "RunDll32.exe shell32.dll,SHExitWindowsEx 1"
'This will restart the computer.
oWshShell.Run "RunDll32.exe shell32.dll,SHExitWindowsEx 2"
'This will do a forced shutdown.
oWshShell.Run "RunDll32.exe shell32.dll,SHExitWindowsEx 4"
'This will power down the machine.
oWshShell.Run "RunDll32.exe shell32.dll,SHExitWindowsEx 8"
~*~*~*~*~*~*~*~*~
I myself, left a comment error ('Restart the desktop), in the sample
script that I gave you.
'1' shuts down. '2' restarts, '4' does an unfriendly shutdown. '8'
shuts off the power also unkind.
So... let's take the script from the top with correct comments and see
if this helps you. I shall show you two scripts one that uses shell32
just like the original and another that uses the WMI (maybe that will
work better for you?)
'BEGIN Copy below this line
--------------------------------------------------------
'Script to shutdown using shell32
'Defines and creates the shell object for later use so we can call it
later
Set oWshShell = WScript.CreateObject("WScript.Shell")
'This will shutdown the computer. calls the method shell32.dll.
'oWshShell.Run "RunDll32.exe shell32.dll,SHExitWindowsEx 1"
'END Copy above this line
---------------------------------------------------
Note the syntax: RunDll32.exe [space]
shell32.exe[comma]SHExitWindowsEX [space] 1
Now, let's take a look at using WMI - which is great if you can't get
the above to work. It is "safer" more elegant, but less direct and
more lines
'BEGIN Copy below this line -------Shutdown with
WMI-------------------------------------------------
'define the SHUTDOWN constant as 1
Const SHUTDOWN = 1
'set the string to this computer
strComputer = "."
'define th object that we need
Set objWMIService = GetObject_
("winmgmts:{impersonationLevel=impersonate,(Shutdown)}\\" & _
strComputer & "\root\cimv2")
'define our OS as Win32
Set colOperating Systems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
'tight loop shuts down applications, services and the session
For Each objOperatingSystem in colOperatingSystems
objOperatingSystem.Win32Shutdown(SHUTDOWN)
Next
'END Copy above this line
---------------------------------------------------
I hope this works for you.
If still no luck, then feel free to write my gmail account and I can
send attachments. I can't swear to no typo's in the above, but I did
run both scripts.
-solon fox
thanks solon fox. I like your idea, but can't make it work. When I create
'test2.vbs' and run your script I get the following error message:
Error in shell32.dll
Missing entry:SHExitWindowsEx
Also, I don't understand why your script is doing a restart?
- Show quoted text -- Hide quoted text -
- Show quoted text -