spaterso Posted July 30, 2009 Posted July 30, 2009 I've seen other threads with some info but nothing I've tried and has actually worked. I need a way to restart a system once (easily done with flags) after running a particular startup script. I've tried the following methods to no avail: from Batch files - Shutdown and Reboot WMIC OS Where Primary=TRUE Call Reboot (happily installs the WMIC client then fails with a bad parameter) shutdown -r -t 1 (get a device not ready error -have tried psshutdown as well with no effect) from this article msgoodies: Restarting Windows XP from a startup script is not easy I've tried: psexec -accepteula -sd shutdown -r -t 1 . It seems to start but never calls the reboot (ran with startup scripts visible to check) Anyways, if anyone has a surefire method I'd love to know.
mac_shinobi Posted July 30, 2009 Posted July 30, 2009 you can use vbscript to do a reboot / forced reboot after writing to the local C drive a simple text file with either a 1 or a zero and if it reads the text file has a 1 then ignore it otherwise reboot on startup
spaterso Posted July 30, 2009 Author Posted July 30, 2009 you can use vbscript to do a reboot / forced reboot after writing to the local C drive a simple text file with either a 1 or a zero and if it reads the text file has a 1 then ignore it otherwise reboot on startup That'd be great ... if I knew VBS.
mac_shinobi Posted July 30, 2009 Posted July 30, 2009 (edited) On Error Resume Next [b]mname = InputBox("Enter Machine Name", "Reboot Machine")[/b] If Len(mname) = 0 Then Wscript.Quit [b]if Msgbox("Are you sure you want to reboot machine " & mname, vbYesNo, "Reboot Machine") = vbYes then[/b] 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 Obviously in the code above you can get rid of the messagebox by deleting code in bold and that should reboot it VBScript Tutorial. How FSO writes data file OpenTextFile FileSystemObject Refer to above link for creating / opening etc a text file which am sure you can add to the above code before the reboot code applies and instead of using an if statement with a msgbox you could use an if statement with conjunction to if the text file contains a 1 or 0 or w/e You can also replace mname with these 2 lines so it gets the machine name on which the script is running on Set WshNetwork = WScript.CreateObject("WScript.Network") WScript.Echo "Domain = " & WshNetwork.UserDomain WScript.Echo "Computer Name = " & WshNetwork.ComputerName WScript.Echo "User Name = " & WshNetwork.UserName obviously if you just want the computer name then it would be Set WshNetwork = WScript.CreateObject("WScript.Network") mname = WshNetwork.ComputerName I can compile it together but am not running windows right now and am being lazy - am sure srochford or someone could compile something similiar and put it all together. Basically open notepad and enter in said code and save to desktop ( if you have file extensions showing ) then you can rename said file from .txt to .vbs and run - if there are any errors you will get error message boxes telling you what line and character etc Edited July 30, 2009 by mac_shinobi 2
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now