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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Restart computer 5

Status
Not open for further replies.

redlair

Technical User
Jun 29, 2004
54
US
Hello everyone,
I have a script ready to deploy, but I would like to add the ability to reboot the computer. I would like to prompt the user to reboot and if they click yes then reboot the computer. If this is not to difficult, could someone provide an example. Thank-You

oh, We are talking about Windows XP and maybee some 2K.
 
Search the net for the Windows XP Professional Shutdown Tool. It will allow you to restart all the PCs on your network or just the ones you select. It will also display a warning that the computer is about to restart in a set amount of time that you define. You can also leave a little explaination of why the computer needs to be rebooted.

It worked well with my 100 machine network untill I got SMS 2003 and now I just run a fake program to get my machines to restart. I believe the user has the option to cancel or delay that one.

Good Luck,
Anthony
 
Code:
'==========================================================================
'
' NAME: RebootWS.vbs
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL: [URL unfurl="true"]http://www.thespidersparlor.com[/URL]
' DATE  : 9/18/2002
'
' COMMENT: Remotely reboots a PC.  May use machine name or IP address.
' 
' MODIFICATIONS: 10/7/2002 Added support for confirmation box
'==========================================================================

On Error Resume Next
mname = InputBox("Enter Machine Name", "Reboot Machine")
If Len(mname) = 0 Then Wscript.Quit

if Msgbox("Are you sure you want to reboot machine " & mname, vbYesNo, "Reboot Machine") = vbYes then

		Set OpSysSet = GetObject("winmgmts:{impersonationLevel=impersonate,(RemoteShutdown)}//" & mname).ExecQuery("select * from Win32_OperatingSystem where Primary=true")
		for each OpSys in OpSysSet
			OpSys.Reboot()
 		next
end if

I hope you find this post helpful.

Regards,

Mark
 
Thank you for your input. I found two lines that seem to reboot the system fine. Here is the code I found. Let me know if there is wrong with using this.

Set WSHShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "C:\WINDOWS\system32\shutdown.exe -r -t 0"

RL
 
Mark,

I am running this script and it seems as if it's working properly but the machines I try to shutdown never do shutdown.

Thanks,

Aaron
 
Aaron,

Please confirm that you are in a Domain environment and that you are running the script logged on as a Domain Admin.

I hope you find this post helpful.

Regards,

Mark
 
No problem Mark,

I am in a Windows domain environment (2K3 forest). I was logged in as a domain admin on my box where I ran the script. It asked for a Computer Name I give it and it prompts if I am sure I want to restart it and I say yes. Everything looks kosher but the shutdown never happens.

Thanks and if you want more info as to the environment just ask.

Aaron
 
OK, only thing (besides XP firewall) that might prevent it is if the loal policy does not allow it. Make sure you have rights to Force Shutdown from a Remote System.

Edit local policy and check here:

Computer Configuration
Windows Settings
Security Settings
Local Policies
User Rights Assignment

I hope you find this post helpful.

Regards,

Mark
 
Cool Mark,

I didn't know of checking that setting I will check right now.

Thanks,

Aaron
 
Mark,

It was the firewall. Is there a way to allow the script for any user on my network through the firewall via another script. Or is there a command I can add to the shutdown script that first disables the firewall then sends the shutdown command?

Thanks,

Aaron
 
You can configure the firewall via GPO.

I hope you find this post helpful.

Regards,

Mark
 
Awesome script Mark,

Just one question what other methods are available to you after the binding of OpSysSet in your example.

I want to make a quick script to Logoff and not reset unattended machines after 15mins.(I dont want code, I wanna figure that most of that part out)

have a basic understanding of VBScripting from examples(some of which out of your FAQ), are you able to point me in the right direction?

ta

 
Reboot and Shutdown are the only two options I am aware of.

I hope you find this post helpful.

Regards,

Mark
 
BTW Mark,

I just decided to disable the firewall network wide at login with GP. Then the script runs fine. I imagine that command does not work with 95 & 98 (yes I still have to support quite a few old boxes). However do you know if it works on 2K?

Thanks,

Aaron
 
hessa

script works on 2k but again it all comes back to mark's earlier posting about privillages.

bingo PHV n tsuji ta plenty just the thing I am looking for
 
The rights are there so I should be good to go.

Thanks for the quick response. I have a doc someone linked from the forums that lists what does and doesn't work but finding 1 item in there isn't always fast.

Thanks,

Aaron
 
Regarding the Win95 & Win98:

If you are still supporting Windows 95, I'd help that along to have an "accident." [sadeyes] I don't think the following will work for Windows 95.

The Windows 98 you may have a chance with. You will need to install the WMI Core and WSH 5.6 Engines. Also make some registry changes that this script can manage for you.

Code:
'==========================================================================
'
' NAME: WMIon9x.vbs
'
' AUTHOR: Mark D. MacLachlan , itSynergy
' URL: [URL unfurl="true"]http://www.itSynergy.com[/URL]
' (c)2004 All Rights Reserved
' DATE  : 1/29/2004
'
' COMMENT: Sets registry keys to enable WMI on Win9x computers.
'
'==========================================================================
 
on error resume next
 
Dim path
 
Set WSHShell = Wscript.CreateObject("WScript.Shell")
SET oFSO = Wscript.CreateObject("Scripting.FileSystemObject")
'set the key path here.  IF you don't end with a '\' then WSH assumes you are pathing to a value.
path = "HKLM\Software\Microsoft\"
 
WSHShell.RegWrite path & "OLE\EnableDCOM","Y","REG_SZ"
WSHShell.RegWrite path & "OLE\EnableRemoteConnect","Y","REG_SZ"
WSHShell.RegWrite path & "WBEM\cimom\EnableAnonConnections","1","REG_SZ"
WSHShell.RegWrite path & "WBEM\cimom\AutostartWin9x","1","REG_SZ"
 
strSup = WshShell.SpecialFolders("Startup")
strshortcut = strSup & "\WindowsManagement.lnk"
If Not oFSO.FileExists(strshortcut) Then
 SET oUrlLink = WshShell.CreateShortcut(strshortcut)
 oUrlLink.TargetPath = "C:\WINDOWS\SYSTEM\WBEM\WINMGMT.EXE"
 oUrlLink.Save
End If

I hope you find this post helpful.

Regards,

Mark
 
I will check it out for sure Mark I appreciate the info. Trust me I've been clumsy enough to drop/kick a few machines into submission but if they all break at the same time it's a little harder to explain.

Aaron
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top