Reputation: 191
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?
Upvotes: 4
Views: 3288
Reputation: 191
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.
Upvotes: 4
Reputation: 201652
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.
Upvotes: 11
Reputation: 2760
Have you tried running as Admin? I believe Process.Start requires elevated privileges that are not available in, say, sandbox mode.
Upvotes: 0