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.
Locked
User avatar
octoj2011
Posts: 8
Joined: Thu Feb 16, 2012 1:56 am

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
Joined: Thu Feb 16, 2012 1:56 am

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: 14480
Joined: Tue May 22, 2007 9:57 am
Contact:

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.

Locked