[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 481
  • Last Modified:

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.
0
vbhelper
Asked:
vbhelper
1 Solution
 
deightonCommented:
'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
0
 
vbhelperAuthor Commented:
Buddy!
I'm talking about VBS, VB scripting and WINDOWS SCRIPTING HOST.
0
 
TimCotteeCommented:
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.
0
 
ArkCommented:
Hi

Shutdown
     
module:  USER.EXE
     
command:  rundll32.exe user.exe,restartwindows
result:  forces Windows to perform a proper shutdown, and restart the computer
     
command:  rundll32.exe user.exe,exitwindows
result:  forces Windows to shutdown, and wait either to be turned off, or reset

So:

WshShell.Run ("rundll32 user32.dll,restartwindows")
or
WshShell.Run ("rundll32 user32.dll,exitwindows")

Cheers
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now