1

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 Answer 1

1

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).

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

Comments

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.