0

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.

Steven Matthews
  • 9,705
  • 45
  • 126
  • 232

3 Answers3

4

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");
lc.
  • 113,939
  • 20
  • 158
  • 187
  • Exactly this. Since you have both files in the first parameter, it treats that whole string in quotations as one file argument - you have to remember that file names can have spaces. – Drake Clarris Nov 07 '12 at 15:29
  • If this is run on Windows Vista or later, will file system redirection be a concern? I only ask because the script is in \windows\system32. – Chris Dunaway Nov 07 '12 at 16:08
  • @ChrisDunaway The real problem would be running a 32-bit process from a 64-bit OS, in which case you'll want to look at http://stackoverflow.com/questions/8585873/strange-behavior-with-process-start-and-dfsdiag-exe – lc. Nov 07 '12 at 16:11
1

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.

Mene
  • 3,739
  • 21
  • 40
1

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

Knaģis
  • 20,827
  • 7
  • 66
  • 80