Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ShutdownWindows

Status
Not open for further replies.

deltarho

Technical User
Apr 22, 2003
36
0
0
GB
I've got the following as part of an If...Then construct at the end of a normal vbs file:
.....
Set sa=CreateObject("Shell.Application")
sa.ShutdownWindows
Else
Wscript.Quit
End If

As you can see if we pass through ShutdownWindows we will fall through to the end of the script and we are presented with the ShutdownWindows dialog.

The application is fine and I can live it as it stands but I wanted to extend the code so that if the Cancel option was chosen then I would follow on with something else. Unfortunately, sa.ShutdownWindows has no return value and if I follow with a MsgBox the ShutdownWindows dialog unceremoniously vanishes before I get a chance to opt for anything. I've tried a long sleep before the MsgBox but that doesn't sit right with me.

Any ideas?

Regards,
David
 
Option Explicit
Dim Shell, Title, obj
' Fetch the object reference for the Shell
Set Shell = WScript.CreateObject ("Shell.Application")
Set obj = WScript.CreateObject("WScript.Shell")
' invoke the End-method?
If (MsgBox("Logoff?",vbYesNo + vbQuestion, Title) = vbYes) then
obj.Run "RunDll32.exe Shell32.dll,SHExitWindowsEx 0x0"
end if
if (MsgBox("Logoff?",vbYesNo + vbQuestion, Title) = vbno) then
obj.popup "Never Mind"
end if

You can add any calls etc. that you require to the last few lines.
 
RoobarbnCustard

Thanks for that.

I actually handle Logoff earlier in my code.

I cannot figure out where the object Shell plays a role in your code.

I've done further experimenting and it seems to me that the sa.ShutdownWindows (in my code) or Shell.ShutdownWindows (if invoked in your code) was never designed to have anything following it.

I am currently using Wscript.Sleep to follow sa.ShutdownWindows such that a time out will effectively be a 'Cancel' with 'Shut down' and 'Restart' acted upon immediately.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top