Solved

How to restart computer on WIN05 with WSH and VBS?

Posted on 2001-06-11
4
446 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 27

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ms access #TYPE! error on report when no data 4 77
VB error "Type mismatch" 2 54
Copy a row 12 62
how to know if my Checkbox is True in VB6.0? 9 55
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

772 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