Results 1 to 4 of 4

Thread: Windows 2012 startup script

  1. #1
    mush-mushroom b0redom's Avatar
    Join Date
    Oct 2005
    Location
    Middlesex
    Posts
    3,306
    Thanks
    143
    Thanked
    346 times in 264 posts
    • b0redom's system
      • Motherboard:
      • Some iMac thingy
      • CPU:
      • 3.4Ghz Quad Core i7
      • Memory:
      • 24GB
      • Storage:
      • 3TB Fusion Drive
      • Graphics card(s):
      • nViidia GTX 680MX
      • PSU:
      • Some iMac thingy
      • Case:
      • Late 2012 pointlessly thin iMac enclosure
      • Operating System:
      • OSX 10.8 / Win 7 Pro
      • Monitor(s):
      • Dell 2713H
      • Internet:
      • Be+

    Windows 2012 startup script

    Hi All,
    I'm spinning up some Amazon VMs running Windows 2012 R2. I want to have a script to run whenever the server boots/reboots. Note that I don't want it to run at logon, but actually when the server starts.

    I've been googling and it seems like you can do it in powershell like this:

    $trigger = New-JobTrigger -AtStartup -RandomDelay 00:00:30
    Register-ScheduledJob -Trigger $trigger -FilePath C:\myscript.bat -Name script

    This doesn't work though.

    Ideally this needs to be in powershell. I don't have access to the GUI (or at least I can't rely on it), so things like setting up group policy in the GUI won't work.

    Can anyone help? I'm not really a Windows person.

    Ta....

    b0redom

  2. #2
    Anthropomorphic Personification shaithis's Avatar
    Join Date
    Apr 2004
    Location
    The Last Aerie
    Posts
    10,839
    Thanks
    645
    Thanked
    871 times in 735 posts
    • shaithis's system
      • Motherboard:
      • Asus P8Z77 WS
      • CPU:
      • i7 3770k @ 4.5GHz
      • Memory:
      • 32GB HyperX 1866
      • Storage:
      • Lots!
      • Graphics card(s):
      • Sapphire Fury X
      • PSU:
      • Corsair HX850
      • Case:
      • Corsair 600T (White)
      • Operating System:
      • Windows 10 x64
      • Monitor(s):
      • 2 x Dell 3007
      • Internet:
      • Zen 80Mb Fibre

    Re: Windows 2012 startup script

    have you tried setting something under:
    HKLM\Software\Microsoft\Windows\CurrentVersion\Run
    Main PC: Asus Rampage IV Extreme / 3960X@4.5GHz / Antec H1200 Pro / 32GB DDR3-1866 Quad Channel / Sapphire Fury X / Areca 1680 / 850W EVGA SuperNOVA Gold 2 / Corsair 600T / 2x Dell 3007 / 4 x 250GB SSD + 2 x 80GB SSD / 4 x 1TB HDD (RAID 10) / Windows 10 Pro, Yosemite & Ubuntu
    HTPC: AsRock Z77 Pro 4 / 3770K@4.2GHz / 24GB / GTX 1080 / SST-LC20 / Antec TP-550 / Hisense 65k5510 4K TV / HTC Vive / 2 x 240GB SSD + 12TB HDD Space / Race Seat / Logitech G29 / Win 10 Pro
    HTPC2: Asus AM1I-A / 5150 / 4GB / Corsair Force 3 240GB / Silverstone SST-ML05B + ST30SF / Samsung UE60H6200 TV / Windows 10 Pro
    Spare/Loaner: Gigabyte EX58-UD5 / i950 / 12GB / HD7870 / Corsair 300R / Silverpower 700W modular
    NAS 1: HP N40L / 12GB ECC RAM / 2 x 3TB Arrays || NAS 2: Dell PowerEdge T110 II / 24GB ECC RAM / 2 x 3TB Hybrid arrays || Network:Buffalo WZR-1166DHP w/DD-WRT + HP ProCurve 1800-24G
    Laptop: Lenovo Flex 2 / 12GB RAM / 240GB Corsair Force 3 Printer: HP CP1515n || Phone: HTC One U11 || Other: Samsung Galaxy Tab 4 Pro 10.1 CM12.1 / Playstation 4 + G29 + 2TB Hybrid drive

  3. #3
    DILLIGAF GoNz0's Avatar
    Join Date
    Jun 2006
    Location
    Derby
    Posts
    10,869
    Thanks
    632
    Thanked
    1,192 times in 945 posts
    • GoNz0's system
      • Motherboard:
      • Asus Rampage V Extreme
      • CPU:
      • i7 something X99 based
      • Memory:
      • 16gb GSkill
      • Storage:
      • 4 SSD's + WD Red
      • Graphics card(s):
      • GTX980 Strix WC
      • PSU:
      • Enermax Galaxy 1250 (9 years and counting)
      • Case:
      • Corsair 900D
      • Operating System:
      • win10 64bit
      • Monitor(s):
      • Dell 24"
      • Internet:
      • 220mb Cable

    Re: Windows 2012 startup script

    Task scheduler allows run at startup, just slap the credentials in the box when you click apply and point it to the batch file. I do seem to remember having an issue running a batch file resolved by a free program to convert batch to EXE files so it could be run as admin so the 2 may work together?

    Capitalization is the difference between helping your Uncle Jack
    off a horse and helping your uncle jack off a horse.

  4. #4
    mush-mushroom b0redom's Avatar
    Join Date
    Oct 2005
    Location
    Middlesex
    Posts
    3,306
    Thanks
    143
    Thanked
    346 times in 264 posts
    • b0redom's system
      • Motherboard:
      • Some iMac thingy
      • CPU:
      • 3.4Ghz Quad Core i7
      • Memory:
      • 24GB
      • Storage:
      • 3TB Fusion Drive
      • Graphics card(s):
      • nViidia GTX 680MX
      • PSU:
      • Some iMac thingy
      • Case:
      • Late 2012 pointlessly thin iMac enclosure
      • Operating System:
      • OSX 10.8 / Win 7 Pro
      • Monitor(s):
      • Dell 2713H
      • Internet:
      • Be+

    Re: Windows 2012 startup script

    Ok, so I've cracked it, and the answer for posterity is:

    Run this in your AWS user data or whatever is creating your servers:

    $taskName = "MyStartupTask"
    $action = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument '-File "C:\<myPowerShellScript.ps1>"'
    $principal = New-ScheduledTaskPrincipal -UserId SYSTEM -LogonType ServiceAccount -RunLevel Highest
    $trigger = New-ScheduledTaskTrigger -AtStartup -RandomDelay 00:00:30
    $definition = New-ScheduledTask -Action $action -Principal $principal -Trigger $trigger -Description "Run $($taskName) at startup"
    Register-ScheduledTask -TaskName $taskName -InputObject $definition
    This will add a new task to run on server startup which calls C:\<myPowerShellScript.ps1>

    It seems that task manager only really likes running powershell, or at least I had issues making it execute other bits and bobs, so I in my myPowerShellScript.ps1 I put:

    & c:\somebatchfile.bat
    ....and it magically springs to life.

    I'm pretty sure no one else here will ever need this, but it drives me nuts when I find someone on the Internet has the same problem and either leaves it as an unsolved problem or adds, "I fixed it." with no details....

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
  •