none
powershell bootup script for Windows XP won't run

    Question

  • I wrote a powershell script that uninstalls software, reboots and then installs new software. The script runs under a computer GPO which runs under system. It works great on windows 7/8 but not on XP. After doing some research I found out that XP doesn't natively run powershell on startup. I then tried to wrap the powershell in a vbscript but still no go. This is what I have so far.

    Set objShell = CreateObject("Wscript.shell")
    objShell.run ('"powershell.exe -executionpolicy bypass -noexit -windowstyle hidden -file \\domain.net\NETLOGON\DeployDeepSecurityAll.ps1")

    I thought maybe the spaces were an issue so I tried:

    Set objShell = CreateObject("Wscript.shell")
    objShell.run ('"powershell.exe " & "-executionpolicy " & "bypass " & "-noexit " & "-windowstyle " & "hidden " & "-file " & "\\domain.net\NETLOGON\DeployDeepSecurityAll.ps1")

    Still no go so then I tried to copy the file locally

    Set filesys=CreateObject("Scripting.FileSystemObject")
    Const EVENT_SUCCESS = 0
    Set objShell = CreateObject("Wscript.shell")
    filesys.CopyFile "\\domain.net\NETLOGON\DeployDeepSecurityAll.ps1", "c:\", True
    objShell.run("powershell.exe -windowstyle hidden -file C:\DeployDeepSecurityAll.ps1")

    Nothing I do seems to work. I have both the vbscript and powershell writing to the event log so I know what's going on. The vbscript will write to the event log and I see the powershell script get copied to the local C: but it just won't execute. I also want to point out that the powershell is signed and if I run the vbscript manually it works just fine. 

    Any idea's are greatly appreciated! 




    Wednesday, July 17, 2013 6:38 PM

Answers

  • Looks like I got it working although I have no idea how or why. I wanted to try and grab error info so I used this command"

    strErrorCode = objShell.run("powershell.exe -windowstyle hidden -noprofile -file \\domain.net\NETLOGON\Myscript.ps1",1,true)

    For some reason after making this small change it started to work. 

    Wednesday, July 17, 2013 11:30 PM

All replies

  • Works exactly fine for me on XP.

    Try this test first.

    Add a startup script to the startup folder.

    C:\WINDOWS\system32\GroupPolicy\Machine\Scripts\Startup

    Call the script 'start.cmd'

    Place this in the script:

    powershell.exe -command dir >c:\scripts\starter.txt

    Be sure the folder 'c:\scripts' is available and writable.

    GO into MMC and add Group Policy Editor for the local machine and set the computer startup script to the script file you just created.

    Restart the machine.  Check the folder for the log file just created.

    This will always work as long as PowerShell is not damaged.  If it works then there is something wrong with your script or you have not enabled scripting or you have a file that has been blocked.


    ¯\_(ツ)_/¯

    Wednesday, July 17, 2013 8:06 PM
  • Do I need to create that folder structure manually? I only have one folder, 'ADM' under C:\WINDOWS\system32\GroupPolicy\
    Wednesday, July 17, 2013 8:38 PM
  • Do I need to create that folder structure manually? I only have one folder, 'ADM' under C:\WINDOWS\system32\GroupPolicy\

    Use MMC to browse to the script location.

    ¯\_(ツ)_/¯

    Wednesday, July 17, 2013 8:41 PM
  • Ok thank you, so this worked. Now onto my script. All I want to do is call the powershell script. The very first thing the powershell script does is write to the event log. If there is blocking how do I find out and fix it?
    Wednesday, July 17, 2013 8:53 PM
  • How are you writing to the event log?

    ¯\_(ツ)_/¯

    Wednesday, July 17, 2013 9:07 PM
  • $evt=New-Object System.Diagnostics.EventLog("Application")
    $evt.Source="Deployment Script"
    $infoevent=[System.Diagnostics.EventLogEntryType]::Information
    $warningevent=[System.Diagnostics.EventLogEntryType]::Warning
    $errorevent=[System.Diagnostics.EventLogEntryType]::Error

    $evt.WriteEntry("Checking pre-reqs",$infoevent,1024)

    Again this script works when running it manually, just not using it as a startup script

    Wednesday, July 17, 2013 10:17 PM
  • I tried:

    objShell.run("powershell.exe -windowstyle hidden -file C:\DeployDeepSecurityAll.ps1 > c:\powershell.log")

    to see if there was any output. No file was generated, this tells me that it doesn't seem to be running the command at all.

    Wednesday, July 17, 2013 10:38 PM
  • Looks like I got it working although I have no idea how or why. I wanted to try and grab error info so I used this command"

    strErrorCode = objShell.run("powershell.exe -windowstyle hidden -noprofile -file \\domain.net\NETLOGON\Myscript.ps1",1,true)

    For some reason after making this small change it started to work. 

    Wednesday, July 17, 2013 11:30 PM
  • Makes sense to me (I think, at least). Are you aware of what "true" is doing in your run command?

    http://msdn.microsoft.com/en-us/library/d5fk67ky%28v=vs.84%29.aspx

    I personally set that flag to true in almost every case.


    Don't retire TechNet!

    Wednesday, July 17, 2013 11:54 PM
  • Then this should work:
    objShell.run "powershell.exe -windowstyle hidden -noprofile -file \\domain.net\NETLOGON\Myscript.ps1"

    The issue being a syntax error that none of us saw.

    Using this:

    strErrorCode = objShell.run("powershell.exe -windowstyle hidden -noprofile -file \\domain.net\NETLOGON\Myscript.ps1",1,true)

    eliminates the syntax error because a call to a function requires a return value or you need to call it as a sub as in the first case.  Catching the errors would have found this.

    I can now say your  full script has an "On Error  Resume Next" statement in the beginning which was hiding the error.

    Design of logon scripts takes real good knowledge of how the system executes scripts and it takes good knowledge in designing and debugging scripts.  I spend a good part of my consulting time convincing Admins to not use logon scripts when Group Policy can manage the items. Logon scripts are really legacy.  The ability to use them is slowly being withdrawn by Microsoft in favor of management systems and Group Policy.  The last SBS I deployed made absolutely no reference to logon scripts and automatically set up much of the system with GPOs.  All systems that I take control of get the logon scripts pretty much totally removed.

    Don't get me wrong.  Logon scripts work but they are problematic for newer Admins who have little formal computer training and have learned to be Admins either on-the-job or from a basic training class.  Programming and system debugging are not part of the traditional training. PowerShell will certainly begin to change that.

     


    ¯\_(ツ)_/¯

    Thursday, July 18, 2013 12:35 AM
  • Then this should work:
    objShell.run "powershell.exe -windowstyle hidden -noprofile -file \\domain.net\NETLOGON\Myscript.ps1"

    The issue being a syntax error that none of us saw.

    Using this:

    strErrorCode = objShell.run("powershell.exe -windowstyle hidden -noprofile -file \\domain.net\NETLOGON\Myscript.ps1",1,true)

    eliminates the syntax error because a call to a function requires a return value or you need to call it as a sub as in the first case.  Catching the errors would have found this.

    I can now say your  full script has an "On Error  Resume Next" statement in the beginning which was hiding the error.

    Design of logon scripts takes real good knowledge of how the system executes scripts and it takes good knowledge in designing and debugging scripts.  I spend a good part of my consulting time convincing Admins to not use logon scripts when Group Policy can manage the items. Logon scripts are really legacy.  The ability to use them is slowly being withdrawn by Microsoft in favor of management systems and Group Policy.  The last SBS I deployed made absolutely no reference to logon scripts and automatically set up much of the system with GPOs.  All systems that I take control of get the logon scripts pretty much totally removed.

    Don't get me wrong.  Logon scripts work but they are problematic for newer Admins who have little formal computer training and have learned to be Admins either on-the-job or from a basic training class.  Programming and system debugging are not part of the traditional training. PowerShell will certainly begin to change that.

     


    ¯\_(ツ)_/¯

    You're absolutely correct, it's been a long time since I had to write VB that I forgot the difference between ( and " (function vs sub). An unintended consequence is I like writing the error code to the event log in case I need it later. I appreciateT all the feedback, I was really banging my head against the wall on this one.

    I do have to comment that I used the 'Hey, Scripting Guy!' as a reference which put me on the wrong track (http://blogs.technet.com/b/heyscriptingguy/archive/2012/07/18/how-to-use-vbscript-to-run-a-powershell-script.aspx). I used their example as my starting point, am I missing something or if their example incorrect?

    Thank you guys again!

    Thursday, July 18, 2013 4:59 AM
  • Then this should work:
    objShell.run "powershell.exe -windowstyle hidden -noprofile -file \\domain.net\NETLOGON\Myscript.ps1"

    The issue being a syntax error that none of us saw.

    Using this:

    strErrorCode = objShell.run("powershell.exe -windowstyle hidden -noprofile -file \\domain.net\NETLOGON\Myscript.ps1",1,true)

    eliminates the syntax error because a call to a function requires a return value or you need to call it as a sub as in the first case.  Catching the errors would have found this.

    I can now say your  full script has an "On Error  Resume Next" statement in the beginning which was hiding the error.

    Design of logon scripts takes real good knowledge of how the system executes scripts and it takes good knowledge in designing and debugging scripts.  I spend a good part of my consulting time convincing Admins to not use logon scripts when Group Policy can manage the items. Logon scripts are really legacy.  The ability to use them is slowly being withdrawn by Microsoft in favor of management systems and Group Policy.  The last SBS I deployed made absolutely no reference to logon scripts and automatically set up much of the system with GPOs.  All systems that I take control of get the logon scripts pretty much totally removed.

    Don't get me wrong.  Logon scripts work but they are problematic for newer Admins who have little formal computer training and have learned to be Admins either on-the-job or from a basic training class.  Programming and system debugging are not part of the traditional training. PowerShell will certainly begin to change that.

     


    ¯\_(ツ)_/¯

    You're absolutely correct, it's been a long time since I had to write VB that I forgot the difference between ( and " (function vs sub). An unintended consequence is I like writing the error code to the event log in case I need it later. I appreciateT all the feedback, I was really banging my head against the wall on this one.

    I do have to comment that I used the 'Hey, Scripting Guy!' as a reference which put me on the wrong track (http://blogs.technet.com/b/heyscriptingguy/archive/2012/07/18/how-to-use-vbscript-to-run-a-powershell-script.aspx). I used their example as my starting point, am I missing something or if their example incorrect?

    JRV - I am curious on which group policy can intelligently manage software on the end users PC. There has been the ability to deploy MSI packages since 2000 but group policy is quite dumb. Sure there is SCCM or Altiris and I've asked our desktop team to deploy that for some time with no such luck. Sometimes us lowly admins need to get creative!

    I earned my MSCE in 2000 and at that time they didn't cover VBScript and obviously poweshell. The issues I encountered were a mistake in VB code and not a misunderstanding of the OS. 

    Cheers!


    Thursday, July 18, 2013 5:15 AM
  • JRV - I am curious on which group policy can intelligently manage software on the end users PC. There has been the ability to deploy MSI packages since 2000 but group policy is quite dumb. Sure there is SCCM or Altiris and I've asked our desktop team to deploy that for some time with no such luck. Sometimes us lowly admins need to get creative!

    You can get yourself up to speed with a small amount of investigation.

    GP is very good at deploying software.  Scripts are very bad at same.

    Don't blame the GP issues on poorly trained Admins.  It is a corporate problem.  Blame a poorly trained IT manager or CTO.


    ¯\_(ツ)_/¯

    Thursday, July 18, 2013 5:32 AM
  • I do have to comment that I used the 'Hey, Scripting Guy!' as a reference which put me on the wrong track (http://blogs.technet.com/b/heyscriptingguy/archive/2012/07/18/how-to-use-vbscript-to-run-a-powershell-script.aspx). I used their

    Blogs do not always get it right.  There is no substitute for experience.

    Note that I missed that one obvious thing from the beginning too.  It is subtle by very important.


    ¯\_(ツ)_/¯

    Thursday, July 18, 2013 5:35 AM