Solved

How to restart computer on WIN05 with WSH and VBS?

Posted on 2001-06-11
4
435 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
Comment Utility
'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
Comment Utility
Buddy!
I'm talking about VBS, VB scripting and WINDOWS SCRIPTING HOST.
0
 
LVL 43

Expert Comment

by:TimCottee
Comment Utility
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
Comment Utility
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now