1
votes

I try execute powershell script with HelloWorld, but I see error.My script:

        try
        {
            System.Diagnostics.Process.Start("C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\Powershell.exe -File HelloWOrld.ps1");
        }
        catch (Exception exception)
        {

        }

In exception I see:

"System.ComponentModel.Win32Exception (0x80004005): The system cannot find the file specified at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo) at System.Diagnostics.Process.Start() at System.Diagnostics.Process.Start(ProcessStartInfo startInfo) at System.Diagnostics.Process.Start(String fileName) at InstallAzurePowershell.Program.WritePowershell() in c:\Users\titans\Documents\Visual Studio 2013\Projects\InstallAzurePowershell\InstallAzurePowershell\Program.cs:line 111"

So how it's fixed?

1

1 Answers

1
votes

You are using wrong overload. The version used Process.Start(String) will take one string as an argument. It considers the whole string as application name. So instead of running powershell.exe and passing -File Hello.ps1 you are trying to run an exe called "powershell.exe -File hello.ps1". This obviously makes little sense to the OS.

Use the proper overloaded version: Process.Start(String, String).