+ Post New Thread
Results 1 to 4 of 4
Windows Thread, restart system from startup script in Technical; I've seen other threads with some info but nothing I've tried and has actually worked. I need a way to ...
  1. #1

    Join Date
    Apr 2009
    Posts
    4
    Thank Post
    1
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    restart system from startup script

    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.

  2. #2

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,680
    Thank Post
    3,210
    Thanked 1,030 Times in 955 Posts
    Rep Power
    361
    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

  3. #3

    Join Date
    Apr 2009
    Posts
    4
    Thank Post
    1
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Quote Originally Posted by mac_shinobi View Post
    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.

  4. #4

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,680
    Thank Post
    3,210
    Thanked 1,030 Times in 955 Posts
    Rep Power
    361
    Code:
    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
    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
    Code:
           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
    Code:
           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
    Last edited by mac_shinobi; 30th July 2009 at 08:32 PM.

  5. 2 Thanks to mac_shinobi:

    dhicks (30th July 2009), spaterso (5th August 2009)

SHARE:
+ Post New Thread

Similar Threads

  1. Replies: 26
    Last Post: 15th December 2011, 04:05 PM
  2. Windows Update in a startup script.
    By MaxBerzon in forum Windows
    Replies: 2
    Last Post: 30th April 2009, 03:48 PM
  3. Startup Script
    By Chuckster in forum Windows
    Replies: 5
    Last Post: 26th February 2009, 12:53 PM
  4. Restart when script completes
    By djones in forum Scripts
    Replies: 4
    Last Post: 18th May 2008, 10:26 PM
  5. RM CC3 Startup Script
    By randle in forum Windows
    Replies: 4
    Last Post: 30th July 2007, 02:56 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •