C# Starting Powershell ps1 File in batch with Process.Start()

0

I have a problem with starting a powershell inside a batch script with C#:

I wan't to replace the EnvironmentVariable "CLIENTNAME"for the Process so i did it like this:

ProcessStartInfo pi = new ProcessStartInfo();
pi.FileName = Environment.ExpandEnvironmentVariables("test.bat");
pi.UseShellExecute = false;
pi.EnvironmentVariables["clientname"] = clientname;
Process.Start(pi);

My "test.bat" looks like this:

powershell %logonserver%\netlogon\test.ps1
pause

The result is that I get this exception:

Windows PowerShell terminated with the following error:
Invalid Signature. (Exception from HRESULT: 0x80090006)

If I start the test.bat with doubleclick everything works fine... Why?

Thanks for your help.

c#
powershell
batch-file
asked on Stack Overflow Mar 11, 2016 by stefan.bittmann

1 Answer

0

now I have the answer to my question:

Environment.SetEnvironmentVariable("clientname", clientname);
ProcessStartInfo pi = new ProcessStartInfo();
pi.FileName = Environment.ExpandEnvironmentVariables("test.bat");
pi.UseShellExecute = true;
Process.Start(pi);
answered on Stack Overflow Mar 12, 2016 by stefan.bittmann

User contributions licensed under CC BY-SA 3.0