Shutdown script

Hi there,

We're currently are using this script to shut down the computers at 10pm each night if that don’t have Outlook or Word opened.. We want to include a popup msg on the remote computer so they the end user have the option to cancel it if they need to.

Can someone please help me out.

Regards

' Specify the OU within AD that contains all the machines to be audited - all sub OU's will be used as well
Const RootOU = "OU=Workstations,OU=Computer Accounts,DC=nsw,DC=gadens,dc=local"

' Set to TRUE to generate the list of PC's from Active Directory using the OU specified by RootOU
' Set to FALSE to use the existing Computers.txt file
Const GeneratePCList = TRUE

Const ADS_SCOPE_SUBTREE = 2
Const ForReading = 1
Const ForWriting = 2

' Check if the script was run with WSCRIPT.EXE and relaunch using CSCRIPT.EXE (command line version)
' This prevents all the pauses from dialog boxes appearing whenever text is output
if LCase(Right(wscript.FullName,11)) = "wscript.exe" then
	set oShell=CreateObject("WScript.Shell")
	oShell.Run "cscript.exe /nologo """ & wscript.ScriptFullName & """", 1, False
	wscript.Quit
end if

Set objFSO = CreateObject("Scripting.FileSystemObject")

sStartTime = Now

iTotalFromAD = 0

if GeneratePCList then
	Set objPCList = objFSO.CreateTextFile(objFSO.GetParentFolderName(WScript.ScriptFullName) & "\" & CompanyName & "Computers.txt", ForWriting)
	Set objConnection = CreateObject("ADODB.Connection")
	Set objCommand =   CreateObject("ADODB.Command")

	on error resume next
	objConnection.Provider = "ADsDSOObject"
	objConnection.Open "Active Directory Provider"
	Set objCOmmand.ActiveConnection = objConnection
	objCommand.CommandText = "Select Name from 'LDAP://" & RootOU & "' where objectClass='computer'"  
	objCommand.Properties("Page Size") = 1000
	objCommand.Properties("Timeout") = 30 
	objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 
	objCommand.Properties("Cache Results") = False 
	Set objRecordSet = objCommand.Execute
	objRecordSet.MoveFirst
	Do Until objRecordSet.EOF
		objPCList.WriteLine objRecordSet.Fields("Name").Value
		iTotalFromAD = iTotalFromAD + 1
        	objRecordSet.MoveNext
	Loop

	objPCList.Close
	on error goto 0
end if

Dim OutputComputer

strInputFile = "Computers.txt"
strOutputfile = "CloseComputers" & ".txt"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Wscript.Shell")

Const intForReading = 1
Const intForWriting = 2

Set objInputFile = objFSO.OpenTextFile(strInputFile, intForReading, False)
Set objOutputFile = objFSO.OpenTextFile(strOutputfile, intForWriting, True)

While Not objInputFile.AtEndOfStream
	strComputer = objInputFile.ReadLine
	If Trim(strComputer) <> "" Then
		boolPinged = Ping(strComputer)
		If boolPinged = True Then
			On Error Resume Next
			Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 
			Set colProcess = objWMIService.ExecQuery ("Select Name from Win32_Process")
			If Err.Number = 0 Then
				strProcessList = ""
				For Each objProcess in colProcess
					If strProcessList = "" Then
						strProcessList = LCase(objProcess.Name)
					Else
						strProcessList = strProcessList & VbCrLf & LCase(objProcess.Name)
					End If
				Next
				
				If InStr(strProcessList, "outlook.exe") = 0 And InStr(strProcessList, "winword.exe") = 0 Then
					strCommand = "cmd /c shutdown -s -m \\" & strComputer & " -t 00 -f"
					'MsgBox strComputer & " would be shut down."					
					objShell.Run strCommand, 0, True 
					objOutputFile.WriteLine(strComputer)
				End If
								
			End If
			Err.Clear
			On Error GoTo 0
		Else
			'MsgBox strComputer & " could not be pinged.", vbOKOnly, "Ping Failed"
		End If
	End If
Wend 
objInputFile.Close
objOutputFile.Close
Set objInputFile = Nothing
'MsgBox "Done" 
 
Function Ping(strComputer)
	Dim objShell, boolCode
	Set objShell = CreateObject("WScript.Shell")
	boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
	If boolCode = 0 Then
		Ping = True
	Else
		Ping = False
	End If
End Function

Open in new window

gladminsAsked:
Who is Participating?
 
yelbaglfCommented:
So I was able to test some things, and this is what I've come up with...  The first post of code is the 'original script' with the shutdown cmd portion removed.  It uses psexec and calls the second post of code, after it is copied over to the remote machine.  

The third post of code is the batch file, that will call the vbs.  At this point, both the batch and vbs have been copied over to the local machine.  The elevation powertoys can be found at the below link, and you'll use this to elevate the cmd prompt on Win 7/Vista/2008 machines.

With this, I was able to prompt the user for a shutdown as long as outlook and winword were not running.  If the user hits yes, then shutdown.  If the user hits no, then abort, but if the timeout is reached, then shutdown anyways. (assumes no user is at the PC)  Also, be sure to update all of the new variables with the appropriate paths, etc.

http://technet.microsoft.com/en-us/magazine/2008.06.elevation.aspx

' Specify the OU within AD that contains all the machines to be audited - all sub OU's will be used as well
Const RootOU = "OU=Workstations,OU=Computer Accounts,DC=nsw,DC=gadens,dc=local"

' Set to TRUE to generate the list of PC's from Active Directory using the OU specified by RootOU
' Set to FALSE to use the existing Computers.txt file
Const GeneratePCList = TRUE

Const ADS_SCOPE_SUBTREE = 2
Const ForReading = 1
Const ForWriting = 2

' Check if the script was run with WSCRIPT.EXE and relaunch using CSCRIPT.EXE (command line version)
' This prevents all the pauses from dialog boxes appearing whenever text is output
if LCase(Right(wscript.FullName,11)) = "wscript.exe" then
	set oShell=CreateObject("WScript.Shell")
	oShell.Run "cscript.exe /nologo """ & wscript.ScriptFullName & """", 1, False
	wscript.Quit
end if

Set objFSO = CreateObject("Scripting.FileSystemObject")

sStartTime = Now

iTotalFromAD = 0

if GeneratePCList then
	Set objPCList = objFSO.CreateTextFile(objFSO.GetParentFolderName(WScript.ScriptFullName) & "\" & CompanyName & "Computers.txt", ForWriting)
	Set objConnection = CreateObject("ADODB.Connection")
	Set objCommand =   CreateObject("ADODB.Command")

	on error resume next
	objConnection.Provider = "ADsDSOObject"
	objConnection.Open "Active Directory Provider"
	Set objCOmmand.ActiveConnection = objConnection
	objCommand.CommandText = "Select Name from 'LDAP://" & RootOU & "' where objectClass='computer'"  
	objCommand.Properties("Page Size") = 1000
	objCommand.Properties("Timeout") = 30 
	objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 
	objCommand.Properties("Cache Results") = False 
	Set objRecordSet = objCommand.Execute
	objRecordSet.MoveFirst
	Do Until objRecordSet.EOF
		objPCList.WriteLine objRecordSet.Fields("Name").Value
		iTotalFromAD = iTotalFromAD + 1
        	objRecordSet.MoveNext
	Loop

	objPCList.Close
	on error goto 0
end if

Dim OutputComputer

strInputFile = "Computers.txt"
strOutputfile = "CloseComputers" & ".txt"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Wscript.Shell")

Const intForReading = 1
Const intForWriting = 2

Set objInputFile = objFSO.OpenTextFile(strInputFile, intForReading, False)
Set objOutputFile = objFSO.OpenTextFile(strOutputfile, intForWriting, True)

While Not objInputFile.AtEndOfStream
	strComputer = objInputFile.ReadLine
	If Trim(strComputer) <> "" Then
		boolPinged = Ping(strComputer)
		If boolPinged = True Then
			On Error Resume Next
			Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 
			Set colProcess = objWMIService.ExecQuery ("Select Name from Win32_Process")
			If Err.Number = 0 Then
				strProcessList = ""
				For Each objProcess in colProcess
					If strProcessList = "" Then
						strProcessList = LCase(objProcess.Name)
					Else
						strProcessList = strProcessList & VbCrLf & LCase(objProcess.Name)
					End If
				Next
				
				If InStr(strProcessList, "outlook.exe") = 0 And InStr(strProcessList, "winword.exe") = 0 Then
					strSrc1 = "Source_VBS"
					strDest1 = "Destination_VBS"
					strSrc2 = "Source_Batch"
					strDest2 = "Destination_Batch"
					strPSEXEC = "psexec -s -i \\" & strComputer & " -u username -p password C:\RemoteMachine_Local_Destination_Batch"
					strFolder = "\\" & strComputer & "\C$\Folder_Name_To_CopyFiles"
					
					If objFSO.FolderExists (strFolder) Then
						objFSO.CopyFile strSrc2, strDest2, True
						objFSO.CopyFile strSrc1, strDest1, True
						objShell.Run strPSEXEC, 0, True
					Else
						objFSO.CreateFolder strFolder
						objFSO.CopyFile strSrc2, strDest2, True
						objFSO.CopyFile strSrc1, strDest1, True
						objShell.Run strPSEXEC, 0, True
					End If
				End If
					
			End If
			Err.Clear
			On Error GoTo 0
		Else
			'MsgBox strComputer & " could not be pinged.", vbOKOnly, "Ping Failed"
		End If
	End If
Wend 
objInputFile.Close
objOutputFile.Close
Set objInputFile = Nothing
'MsgBox "Done" 
 
Function Ping(strComputer)
	Dim objShell, boolCode
	Set objShell = CreateObject("WScript.Shell")
	boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
	If boolCode = 0 Then
		Ping = True
	Else
		Ping = False
	End If
End Function

Open in new window


Const TIMEOUT = 10
Const POPUP_TITLE = "Shutdown Your Computer"

Set objShell = CreateObject("Wscript.Shell")
		        strCommand = "cmd /c shutdown -s -m \\" & strComputer & " -t 00 -f"
		        strInput = objShell.Popup("Do You Want to cancel shutdown process?" & vbCrLf &_
        		        "Click Yes for shutdown, Click No to cancel", _
        		        TIMEOUT, POPUP_TITLE, vbYesNo)
		        
                          If strInput = vbYes Then
		             objShell.Run strCommand, 0, True 
		        ElseIf strInput = vbNo Then
		             objOutputFile.WriteLine(strComputer)
			    'WScript.Echo "Shutdown aborted"
		        Else
			    objShell.Run strCommand, 0, True
		        End if

Open in new window


"\\UNC_Path_To_ElevationPowerTools\Elevation\elevate.cmd" C:\Windows\System32\wscript.exe "C:\RemoteMachine_Local_Destination_VBS"

Open in new window

0
 
yelbaglfCommented:
You could try something like this...

Const TIMEOUT = 20
Const POPUP_TITLE = "Shutdown Your Computer"

rstAnswer = oShell.Popup("Are you sure you want to shutdown?" & vbCrLf &_
        "Click Yes for shutdown, Click No to cancel", _
        TIMEOUT, POPUP_TITLE, vbQuestion+vbYesNo)

If InStr(strProcessList, "outlook.exe") = 0 And InStr(strProcessList, "winword.exe") = 0 And rstAnswer = vbYes Then
	strCommand = "cmd /c shutdown -s -m \\" & strComputer & " -t 00 -f"
	'MsgBox strComputer & " would be shut down."					
	objShell.Run strCommand, 0, True 
	objOutputFile.WriteLine(strComputer)

ElseIf InStr(strProcessList, "outlook.exe") = 0 And InStr(strProcessList, "winword.exe") = 0 And rstAnswer = vbNo Then
	WScript.Echo "Shutdown was aborted"

Else
	strCommand = "cmd /c shutdown -s -m \\" & strComputer & " -t 00 -f"
	'MsgBox strComputer & " would be shut down."					
	objShell.Run strCommand, 0, True 
	objOutputFile.WriteLine(strComputer)
End If

Open in new window

0
 
gladminsAuthor Commented:
Hi mate,

Thank you for this however, I get the following error

Line 4
Char1
Error: Object required 'oShell"
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
yelbaglfCommented:
Try this...where you have this code, add the 'set oShell = ' line...

Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 
Set colProcess = objWMIService.ExecQuery ("Select Name from Win32_Process")
Set oShell = CreateObject("WScript.Shell")
			If Err.Number = 0 Then
				strProcessList = ""
				For Each objProcess in colProcess

Open in new window

0
 
gladminsAuthor Commented:
Sorry mate no quite sure where to put this code??
0
 
yelbaglfCommented:
It might be easier to just change 'oShell' to 'objShell'.  It looks like oShell is being used as a variable name at the beginning of your script, and then the name is changed to objShell further down.

In other words...where I wrote 'oShell', change that entry to objShell instead.  As for the short piece of previously posted code, you can just skip that step, since after changing the variable name it will be irrelevant.  Something like this...notice the below code now reads 'objShell.Popup' instead of 'oShell.Popup'.

Const TIMEOUT = 20
Const POPUP_TITLE = "Shutdown Your Computer"

rstAnswer = objShell.Popup("Are you sure you want to shutdown?" & vbCrLf &_
        "Click Yes for shutdown, Click No to cancel", _
        TIMEOUT, POPUP_TITLE, vbQuestion+vbYesNo)

If InStr(strProcessList, "outlook.exe") = 0 And InStr(strProcessList, "winword.exe") = 0 And rstAnswer = vbYes Then
	strCommand = "cmd /c shutdown -s -m \\" & strComputer & " -t 00 -f"
	'MsgBox strComputer & " would be shut down."					
	objShell.Run strCommand, 0, True 
	objOutputFile.WriteLine(strComputer)

ElseIf InStr(strProcessList, "outlook.exe") = 0 And InStr(strProcessList, "winword.exe") = 0 And rstAnswer = vbNo Then
	WScript.Echo "Shutdown was aborted"

Else
	strCommand = "cmd /c shutdown -s -m \\" & strComputer & " -t 00 -f"
	'MsgBox strComputer & " would be shut down."					
	objShell.Run strCommand, 0, True 
	objOutputFile.WriteLine(strComputer)
End If

Open in new window



From here, this would make your final code look something like this...

' Specify the OU within AD that contains all the machines to be audited - all sub OU's will be used as well
Const RootOU = "OU=Workstations,OU=Computer Accounts,DC=nsw,DC=gadens,dc=local"

' Set to TRUE to generate the list of PC's from Active Directory using the OU specified by RootOU
' Set to FALSE to use the existing Computers.txt file
Const GeneratePCList = TRUE

Const ADS_SCOPE_SUBTREE = 2
Const ForReading = 1
Const ForWriting = 2

' Check if the script was run with WSCRIPT.EXE and relaunch using CSCRIPT.EXE (command line version)
' This prevents all the pauses from dialog boxes appearing whenever text is output
if LCase(Right(wscript.FullName,11)) = "wscript.exe" then
	set oShell=CreateObject("WScript.Shell")
	oShell.Run "cscript.exe /nologo """ & wscript.ScriptFullName & """", 1, False
	wscript.Quit
end if

Set objFSO = CreateObject("Scripting.FileSystemObject")

sStartTime = Now

iTotalFromAD = 0

if GeneratePCList then
	Set objPCList = objFSO.CreateTextFile(objFSO.GetParentFolderName(WScript.ScriptFullName) & "\" & CompanyName & "Computers.txt", ForWriting)
	Set objConnection = CreateObject("ADODB.Connection")
	Set objCommand =   CreateObject("ADODB.Command")

	on error resume next
	objConnection.Provider = "ADsDSOObject"
	objConnection.Open "Active Directory Provider"
	Set objCOmmand.ActiveConnection = objConnection
	objCommand.CommandText = "Select Name from 'LDAP://" & RootOU & "' where objectClass='computer'"  
	objCommand.Properties("Page Size") = 1000
	objCommand.Properties("Timeout") = 30 
	objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 
	objCommand.Properties("Cache Results") = False 
	Set objRecordSet = objCommand.Execute
	objRecordSet.MoveFirst
	Do Until objRecordSet.EOF
		objPCList.WriteLine objRecordSet.Fields("Name").Value
		iTotalFromAD = iTotalFromAD + 1
        	objRecordSet.MoveNext
	Loop

	objPCList.Close
	on error goto 0
end if

Dim OutputComputer

strInputFile = "Computers.txt"
strOutputfile = "CloseComputers" & ".txt"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Wscript.Shell")

Const intForReading = 1
Const intForWriting = 2

Set objInputFile = objFSO.OpenTextFile(strInputFile, intForReading, False)
Set objOutputFile = objFSO.OpenTextFile(strOutputfile, intForWriting, True)

While Not objInputFile.AtEndOfStream
	strComputer = objInputFile.ReadLine
	If Trim(strComputer) <> "" Then
		boolPinged = Ping(strComputer)
		If boolPinged = True Then
			On Error Resume Next
			Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 
			Set colProcess = objWMIService.ExecQuery ("Select Name from Win32_Process")
			If Err.Number = 0 Then
				strProcessList = ""
				For Each objProcess in colProcess
					If strProcessList = "" Then
						strProcessList = LCase(objProcess.Name)
					Else
						strProcessList = strProcessList & VbCrLf & LCase(objProcess.Name)
					End If
				Next
				
				Const TIMEOUT = 20
				Const POPUP_TITLE = "Shutdown Your Computer"

				rstAnswer = objShell.Popup("Are you sure you want to shutdown?" & vbCrLf &_
        		        "Click Yes for shutdown, Click No to cancel", _
        		        TIMEOUT, POPUP_TITLE, vbQuestion+vbYesNo)

				If InStr(strProcessList, "outlook.exe") = 0 And InStr(strProcessList, "winword.exe") = 0 And rstAnswer = vbYes Then
					strCommand = "cmd /c shutdown -s -m \\" & strComputer & " -t 00 -f"
					'MsgBox strComputer & " would be shut down."					
					objShell.Run strCommand, 0, True 
					objOutputFile.WriteLine(strComputer)

				ElseIf InStr(strProcessList, "outlook.exe") = 0 And InStr(strProcessList, "winword.exe") = 0 And rstAnswer = vbNo Then
				WScript.Echo "Shutdown was aborted"

				Else
				strCommand = "cmd /c shutdown -s -m \\" & strComputer & " -t 00 -f"
				'MsgBox strComputer & " would be shut down."					
				objShell.Run strCommand, 0, True 
				objOutputFile.WriteLine(strComputer)
				End If
								
			End If
			Err.Clear
			On Error GoTo 0
		Else
			'MsgBox strComputer & " could not be pinged.", vbOKOnly, "Ping Failed"
		End If
	End If
Wend 
objInputFile.Close
objOutputFile.Close
Set objInputFile = Nothing
'MsgBox "Done" 
 
Function Ping(strComputer)
	Dim objShell, boolCode
	Set objShell = CreateObject("WScript.Shell")
	boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
	If boolCode = 0 Then
		Ping = True
	Else
		Ping = False
	End If
End Function

Open in new window

0
 
yehudahaCommented:
hey

change the message edit line 88
' Specify the OU within AD that contains all the machines to be audited - all sub OU's will be used as well
Const RootOU = "OU=Workstations,OU=Computer Accounts,DC=nsw,DC=gadens,dc=local"

' Set to TRUE to generate the list of PC's from Active Directory using the OU specified by RootOU
' Set to FALSE to use the existing Computers.txt file
Const GeneratePCList = TRUE

Const ADS_SCOPE_SUBTREE = 2
Const ForReading = 1
Const ForWriting = 2

' Check if the script was run with WSCRIPT.EXE and relaunch using CSCRIPT.EXE (command line version)
' This prevents all the pauses from dialog boxes appearing whenever text is output
if LCase(Right(wscript.FullName,11)) = "wscript.exe" then
	set oShell=CreateObject("WScript.Shell")
	oShell.Run "cscript.exe /nologo """ & wscript.ScriptFullName & """", 1, False
	wscript.Quit
end if

Set objFSO = CreateObject("Scripting.FileSystemObject")

sStartTime = Now

iTotalFromAD = 0

if GeneratePCList then
	Set objPCList = objFSO.CreateTextFile(objFSO.GetParentFolderName(WScript.ScriptFullName) & "\" & CompanyName & "Computers.txt", ForWriting)
	Set objConnection = CreateObject("ADODB.Connection")
	Set objCommand =   CreateObject("ADODB.Command")

	on error resume next
	objConnection.Provider = "ADsDSOObject"
	objConnection.Open "Active Directory Provider"
	Set objCOmmand.ActiveConnection = objConnection
	objCommand.CommandText = "Select Name from 'LDAP://" & RootOU & "' where objectClass='computer'"  
	objCommand.Properties("Page Size") = 1000
	objCommand.Properties("Timeout") = 30 
	objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 
	objCommand.Properties("Cache Results") = False 
	Set objRecordSet = objCommand.Execute
	objRecordSet.MoveFirst
	Do Until objRecordSet.EOF
		objPCList.WriteLine objRecordSet.Fields("Name").Value
		iTotalFromAD = iTotalFromAD + 1
        	objRecordSet.MoveNext
	Loop

	objPCList.Close
	on error goto 0
end if

Dim OutputComputer

strInputFile = "Computers.txt"
strOutputfile = "CloseComputers" & ".txt"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Wscript.Shell")

Const intForReading = 1
Const intForWriting = 2

Set objInputFile = objFSO.OpenTextFile(strInputFile, intForReading, False)
Set objOutputFile = objFSO.OpenTextFile(strOutputfile, intForWriting, True)

While Not objInputFile.AtEndOfStream
	strComputer = objInputFile.ReadLine
	If Trim(strComputer) <> "" Then
		boolPinged = Ping(strComputer)
		If boolPinged = True Then
			On Error Resume Next
			Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 
			Set colProcess = objWMIService.ExecQuery ("Select Name from Win32_Process")
			If Err.Number = 0 Then
				strProcessList = ""
				For Each objProcess in colProcess
					If strProcessList = "" Then
						strProcessList = LCase(objProcess.Name)
					Else
						strProcessList = strProcessList & VbCrLf & LCase(objProcess.Name)
					End If
				Next
				
				If InStr(strProcessList, "outlook.exe") = 0 And InStr(strProcessList, "winword.exe") = 0 Then
					strCommand = "cmd /c shutdown -s -m \\" & strComputer & " -t 00 -f"
					'MsgBox strComputer & " would be shut down."					
					objShell.Run strCommand, 0, True 
					strInput = MsgBox("Do You Want to cancel shutdown process ?",vbyesno)
					If strInput = vbYes Then
					objShell.Run "cmd /c shutdown /a /m \\" & strComputer, 0, True 
					Else
					objOutputFile.WriteLine(strComputer)
					End if
				End If
								
			End If
			Err.Clear
			On Error GoTo 0
		Else
			'MsgBox strComputer & " could not be pinged.", vbOKOnly, "Ping Failed"
		End If
	End If
Wend 
objInputFile.Close
objOutputFile.Close
Set objInputFile = Nothing
'MsgBox "Done" 
 
Function Ping(strComputer)
	Dim objShell, boolCode
	Set objShell = CreateObject("WScript.Shell")
	boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
	If boolCode = 0 Then
		Ping = True
	Else
		Ping = False
	End If
End Function

Open in new window

0
 
gladminsAuthor Commented:
Thank you for the update - Will try it out soon and report back :)
0
 
gladminsAuthor Commented:
Hi mate,

I don't know if there is a loop - as It ask (Click "yes" to shutdown, or "No" to prevent shutdown) I select "No" then I get (Do you want to cancel the shutdown process? ) Then I get this message again (Click "yes" to shutdown, or "No" to prevent shutdown)  I click on No then it goes away??

Are you able to help out again?
0
 
gladminsAuthor Commented:
Also is there a way I can have the message on the remote computer with this message? So the end user can cancel it?
0
 
yelbaglfCommented:
It sounds like you may have used my code and yehudaha's code?  yehudaha posted a different solution that should provide the same result.  You'll want to use either my code or yehudaha's code, but do not combine the two.

This will display the message on the end-user's machine, assuming you're running the script from there?  How are you running the script?  As a task on the end-user's machine, or?
0
 
gladminsAuthor Commented:
Tar yelbaglf..  
I was trying to run it from a server to a list of computer names and have the message popup on their screen..

If I add the script to the local machine called.. say (test.vbs)

If I try and add the below line into a batchfile so all users have it in their scheduled task it just runs and shuts down their computer without prompting??

for /f %%a in (C:\Stasks\computers.txt) do schtasks /create /f /s %%a /ru SYSTEM /sc daily /st 14:05:00 /tn shutdown /tr "cscript //b //nologo c:\test.vbs

Thank you for you help in advanced.
0
 
gladminsAuthor Commented:
Hi mate,

Thank you for this.. We'll be looking at it today and report back..

Cheers
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.