0

i have a powershell script file, and a bat file, the bat file runs the script, so when i double click
the bat file the script get executed.
in my code i do the following:

 ProcessStartInfo info = new ProcessStartInfo(@batchfilename + ".bat");  
            Process processToStart = new Process();  
            processToStart.StartInfo = info;  
            processToStart.Start();  

the batch gets executed and the powershell scripts starts, but it crashes telling me somthing about policy issue.
allthoug my policy is unrestrected, any ideas?

2 Answers 2

3

You need to set Execution Policy to unrestricted MSDN.

Execution Policies (From the above MSDN link)

  • Restricted - No scripts can be run. Windows PowerShell can be used only in interactive mode.
  • AllSigned - Only scripts signed by a trusted publisher can be run.
  • RemoteSigned - Downloaded scripts must be signed by a trusted publisher before they can be run.
  • Unrestricted - No restrictions; all Windows PowerShell scripts can be run.

For 64 bit system, it needs to be set separately for x86, and x64.

PowerShell 32 and 64 bit have different execution policy settings

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

4 Comments

For both x86 and x64? If so, try to run VS as administrator
your saying that if my computer is a 64bit, than i need to set both of the operation system types?
Yes. if you have 64bit Windows, you need to set executionpolicy in c:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe (64bit PS, default one) AND c:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe (32bit, may be called by some programs).
You could try modifying the batch file so that you're passing -ExecutionPolicy Unrestricted into Powershell. Then you don't need to modify the system settings.
0
powershell.exe c:\FULL_PATH\send.ps1

1 Comment

And... to what question is this answer?

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.