4

I've got a PS script that adds firewall rules.

I'm using Process.Start("powershell.exe", "-File "+"\"C:\Program Files (x86)\blah\blah\add-FirewallRule.ps1\"");

This command works fine on my local machine, but in testing I've been running the program on a Windows Server 2008 R2, and the PS script won't run. It runs and works fine if I run it manually from the command line, but my code won't work. All the file paths are correct (i've already checked that and had a co worker check it). When I run the code the PS console doesn't even pop up.

Any suggestions?

3 Answers 3

11

Since you are in C#, I'd recommend using the PowerShell Invoke API rather than Process.Start. The API is easy to use and hopefully will give you a better indication of what is going wrong.

Sign up to request clarification or add additional context in comments.

Comments

4

Turns out that I wasn't accounting for the automatic redirect caused by running a 32-bit app on a 64-bit system. So all I had to do was go in and set the appropriate execution policy for the 32 bit version of powershell.

Comments

0

Have you tried running as Admin? I believe Process.Start requires elevated privileges that are not available in, say, sandbox mode.

1 Comment

And you are not getting any exceptions from the Process.Start method, but the script is still not executing? Could it be that the directory the script opens in is different when running from your code than in the command line?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.