Shutdown Script

Anything VBScript-related, including Windows Script Host, WMI, ADSI, and more.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 11 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
octoj2011
Posts: 8
Last visit: Tue May 01, 2012 8:15 pm

Shutdown Script

Post by octoj2011 »

Hi All,

Getting an error when running this script but don't quite know where to go.

I orginally was using it as a plain vbs file, but after discovering SCCM doesnt run these properly I converted it to a wsf file. However, it know doesnt work and comes up with the error:

Could not locate automation class named "Wscript.Shell".

Was wondering if anybody has any ideas?


<job id="main">
<script language="VBScript">


Const wshYes = 6
Const wshNo = 7
Const wshYesNoDialog = 4
Const wshQuestionMark = 32

Set objShell = CreateObject("Wscript.Shell")

intReturn = objShell.Popup("System maintainence shutdown, are you sure you wish to shutdown? If no response within 5 minutes system will automatically shutdown", _
300, "System maintainence shutdown", wshYesNoDialog + wshQuestionMark)

If intReturn = wshYes Then

Set WSHShell = WScript.CreateObject("WScript. Shell")
WSHShell.Run "%windir%system32shutdown.exe -s -t 360"


ElseIf intReturn = wshNo Then
Wscript.Echo "Shutdown Cancelled."
Else

Set WSHShell = WScript.CreateObject("WScript. Shell")
WSHShell.Run "%windir%system32shutdown.exe -s -t 360"


End If


</script>
</job>
User avatar
octoj2011
Posts: 8
Last visit: Tue May 01, 2012 8:15 pm

Shutdown Script

Post by octoj2011 »

Hi All,

Getting an error when running this script but don't quite know where to go.

I orginally was using it as a plain vbs file, but after discovering SCCM doesnt run these properly I converted it to a wsf file. However, it know doesnt work and comes up with the error:

Could not locate automation class named "Wscript.Shell".

Was wondering if anybody has any ideas?


<job id="main">
<script language="VBScript">


Const wshYes = 6
Const wshNo = 7
Const wshYesNoDialog = 4
Const wshQuestionMark = 32

Set objShell = CreateObject("Wscript.Shell")

intReturn = objShell.Popup("System maintainence shutdown, are you sure you wish to shutdown? If no response within 5 minutes system will automatically shutdown", _
300, "System maintainence shutdown", wshYesNoDialog + wshQuestionMark)

If intReturn = wshYes Then

Set WSHShell = WScript.CreateObject("WScript. Shell")
WSHShell.Run "%windir%system32shutdown.exe -s -t 360"


ElseIf intReturn = wshNo Then
Wscript.Echo "Shutdown Cancelled."
Else

Set WSHShell = WScript.CreateObject("WScript. Shell")
WSHShell.Run "%windir%system32shutdown.exe -s -t 360"


End If


</script>
</job>
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Shutdown Script

Post by jvierra »

Sorry but that cannot be done by a script remotely.

SCCM cannot instantiate certain objects. The shell cannot be remoted.

There are third party products that you can use to accomplish this. You can also write a custom shutdown service.
This topic is 11 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked