C#进程.开始文件名和传递参数 [英] C# process.Start filename and passing arguments
问题描述
我需要打开文件test.mdb. 路径必须是从相对于C#程序exe所在的任何目录构建的fullpath.
I need to open the file test.mdb. The path must be fullpath built from whatever directory it is located in relative to the C# program exe
我需要传递Arguments行,该行将像这样/cmd"MyArgument"一样批量传递 为了使/cmd开关起作用,该路径必须包含已安装的MSACCESS.EXE的完整路径.
I need to pass the Arguments line which in batch would be passed like this /cmd "MyArgument" For the /cmd switch to work the path must include the full path to the installed MSACCESS.EXE
我只是不知道如何将完整路径传递给MSACCESS> EXE,然后将完整路径传递给test.mdb,然后是参数.
I just can't work out how to pass the full path to MSACCESS>EXE followed by the fullpath to test.mdb followed by the Arguments.
要尝试提供帮助,我将发布以下有效的批处理字符串,但我需要C#
To try to help I'm posting the following batch string which works but I need C#
"C:\ Program Files \ Microsoft Office \ Office10 \ MSACCESS.EXE""C:\ Documents and Settings \ User \ Test示例Folder \ test.mdb"/cmd"MyArgument"
"C:\Program Files\Microsoft Office\Office10\MSACCESS.EXE" "C:\Documents and Settings\User\Test Examples Folder\test.mdb" /cmd "MyArgument"
要阐明两个重要点:
test.mdb全路径必须由启动的C#exe自动确定,它将是C#exes路径,但带有test.mdb.
The test.mdb fullpath must be automatically determined by the launching C# exe it will be the C# exes path but with test.mdb.
如果C#exe程序可以自动检查哪个版本(例如Office 10,Office 12等)并使用它,那么MSACCESS.EXE路径必须是MSACCESS.EXE安装版本的完整路径.
And the MSACCESS>EXE path must be the full path to the installed version of MSACCESS.EXE if the C# exe program can automatically check which version i.e. Office 10, Office 12 etc and use that this would be excellent.
到目前为止,这是我的代码:
This is my code so far:
var filePath = @"test.mdb";
Process process = new Process();
process.StartInfo.FileName = filePath;
process.StartInfo.Arguments = "/cmd " + "\"MyArgument\"";
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
process.Start();
推荐答案
我认为您不必担心检测Office版本,只是这样对您有用:
I don't think you need to worry about detecting the office version, just this should work for you:
string filepath = '"' + Directory.GetCurrentDirectory() + "\\test.mdb" + '"';
string acc_cmd_arg = "HELLO";
using (System.Diagnostics.Process process = new System.Diagnostics.Process() ) {
process.StartInfo.FileName = "msaccess.exe";
process.StartInfo.Arguments = filepath + " /cmd " + acc_cmd_arg;
process.Start();
}
这篇关于C#进程.开始文件名和传递参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!