Solved

How to restart computer on WIN05 with WSH and VBS?

Posted on 2001-06-11
4
450 Views
Last Modified: 2010-05-18
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
Comment
Question by:vbhelper
4 Comments
 
LVL 18

Expert Comment

by:deighton
ID: 6176638
'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
 

Author Comment

by:vbhelper
ID: 6177391
Buddy!
I'm talking about VBS, VB scripting and WINDOWS SCRIPTING HOST.
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 6194655
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
 
LVL 28

Accepted Solution

by:
Ark earned 50 total points
ID: 6197500
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question