0

How can I run a PowerShell script from within the %ProgramFiles% folder?

I have tried the variable %ProgramFiles% without any progress, also "Program Files" but can't get ut to work.

My current code

Set shell = WScript.CreateObject("WScript.shell")
shell.Run("powershell C:\Program Files\Temp\test.ps1"), 0 , True

It's working if I use a network share without any spaces

Set shell = WScript.CreateObject("WScript.shell")
shell.Run("powershell \\domain\SYSVOL\script\test.ps1"), 0 , True

I have also tried using """ but can't get PowerShell to work.

Anyone know how to solve this? I need to use VBScript in order to start the PowerShell script in the background at logon via a GPO. Otherwise it will show a PowerShell window.

1 Answer 1

1

Try this. Add parameter "-file" and double quotes around the path. You can get and store %ProgramFiles% in a variable using ExpandEnvironmentStrings:

Set shell = WScript.CreateObject("WScript.shell")

sProgramFiles = shell.ExpandEnvironmentStrings("%PROGRAMFILES%")

shell.Run "powershell -file """ & sProgramFiles & "\Temp\test.ps1""", 0 , True
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.