Link to home
Start Free TrialLog in
Avatar of vbhelper
vbhelper

asked on

How to restart computer on WIN05 with WSH and VBS?

WIN95 and IE5.5:

I tried with this:
WshShell.Run ("C:\WINDows\rundll.exe user32.dll,Exitwindowsex 2 0")
It give me error.
Is there anyway to do it?

One more think I found it that really surprising me:

WshShell.Run ("C:\WINdows\rundll.exe user.exe,Exitwindowsexec")
If I do this, I can successfully restart the computer, I am just wondering is this good way to call a private function of system user.exe.

PLease help me out in this, If there is another way to do,
Please tell me.
Avatar of deighton
deighton
Flag of United Kingdom of Great Britain and Northern Ireland image

'in a .bas module

Option Explicit
Declare Function ExitWindowsEx Lib "user32.dll" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long
Const EWX_FORCE = 4
'Force any applications to quit instead of prompting the user to close them.
Const EWX_LOGOFF = 0
'Log off the network.
Const EWX_POWEROFF = 8
'Shut down the system and, if possible, turn the computer off.
Const EWX_REBOOT = 2
'Perform a full reboot of the system.
Const EWX_SHUTDOWN = 1
'Shut down the system.




public Sub reboot()
Dim retval
retval = ExitWindowsEx(EWX_REBOOT Or EWX_FORCE, 0)
End Sub



'ten call reboot from anywhere
Avatar of vbhelper
vbhelper

ASKER

Buddy!
I'm talking about VBS, VB scripting and WINDOWS SCRIPTING HOST.
Seems a perfectly reasonable way of doing it to me, I am not sure that a user would be too happy to have windows shutdown when running a script but that is up to you of course.
ASKER CERTIFIED SOLUTION
Avatar of Ark
Ark
Flag of Russian Federation image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial