[英]Launch a file with command line arguments without knowing location of exe?
Here's the situation: I am trying to launch an application, but the location of the .exe isn't known to me. 情况如下:我正在尝试启动一个应用程序,但我不知道.exe的位置。 Now, if the file extension is registered (in Windows), I can do something like: 现在,如果文件扩展名被注册(在Windows中),我可以执行以下操作:
Process.Start("Sample.xls");
However, I need to pass some command line arguments as well. 但是,我还需要传递一些命令行参数。 I couldn't get this to work 我无法使它正常工作
Process p = new Process();
p.StartInfo.FileName = "Sample.xls";
p.StartInfo.Arguments = "/r"; // open in read-only mode
p.Start();
Any suggestions on a mechanism to solve this? 关于解决此问题的机制有什么建议吗?
Edit @ aku 编辑 @ aku
My StackOverflow search skills are weak; 我的StackOverflow搜索技能很弱; I did not find that post. 我没有找到那个帖子。 Though I generally dislike peering into the registry, that's a great solution. 尽管我通常不喜欢查看注册表,但这是一个很好的解决方案。 Thanks! 谢谢!
If you query the registry, you can retrieve the data about the registered file type and then call the app directly passing the command line arguments. 如果查询注册表,则可以检索有关已注册文件类型的数据,然后直接通过命令行参数调用应用程序。 See Programmatically Checking and Setting File Types for an example of retrieving shell information for a file type. 有关检索文件类型的外壳程序信息的示例,请参见以编程方式检查和设置文件类型 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.