Launching a file using Process.Start works, but adding conditions does not

StackOverflow https://stackoverflow.com/questions/13272693

  •  27-11-2021
  •  | 
  •  

Вопрос

So I am trying to launch a printer script using cscript from C#, and cscript launches a visual basic file. So sort of a daisy chain (and I want to keep this daisy chain intact for certain reasons).

Here's the code:

Process.Start("c:/windows/system32/cscript.exe c:/windows/System32/Printing_Admin_Scripts/en-US/prnport.vbs");

Now, when I launch ONLY cscript, no problems.

However when I add the condition of prnport.vbs to the cscript launch, I get this error in Visual Studio:

"The system cannot find the file specified"

But I can confirm the file path is correct - prnport.vbs DOES exist in /en-US.

So what am I doing wrong here? Can you not pass arguments (and in this case, the file path is being passed as an argument to cscript.exe) when using Process.Start?

New to C# and confused about the proper way to do this.

Это было полезно?

Решение

You have to specify the arguments separately from the file to run. Try the Process.Start(string, string) overload:

Process.Start("c:/windows/system32/cscript.exe", 
    "c:/windows/System32/Printing_Admin_Scripts/en-US/prnport.vbs");

Другие советы

That's an Argument, you'll need to use another overload of Process.Start

Have a look at the method's documentation.

Process.Start (String, String) will do, others are possible and offer more flexibility, if you should need that, too.

The Process.Start expects the file name as the first parameter. The arguments are given in separate argument.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top