简体   繁体   English

使用Process.Start启动文件有效,但添加条件无效

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

So I am trying to launch a printer script using cscript from C#, and cscript launches a visual basic file. 因此,我尝试使用来自C#的cscript启动打印机脚本,然后cscript启动一个可视的基本文件。 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. 现在,当我仅启动cscript时,没有问题。

However when I add the condition of prnport.vbs to the cscript launch, I get this error in Visual Studio: 但是,当我将prnport.vbs的条件添加到cscript启动时,在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 . 但是我可以确认文件路径是正确的- /en-US存在prnport.vbs

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? 使用Process.Start时是否可以不传递参数(在这种情况下,文件路径将作为参数传递给cscript.exe)?

New to C# and confused about the proper way to do this. C#的新手,对执行此操作的正确方法感到困惑。

You have to specify the arguments separately from the file to run. 您必须与文件分开指定参数才能运行。 Try the Process.Start(string, string) overload : 尝试Process.Start(string, string)重载

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 这是一个参数,您将需要使用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. 如果您也需要Process.Start (String, String) ,其他方法是可能的,并且提供了更大的灵活性。

The Process.Start expects the file name as the first parameter. Process.Start期望将文件名作为第一个参数。 The arguments are given in separate argument. 参数在单独的参数中给出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM