启动进程时以编程方式设置起始位置
我有一个应用程序,可以在桌面上创建快捷方式,并允许您将文件拖放到快捷方式中以执行操作(将 Word 文档转换为 PDF)。现在我想做的是使用 shellexecute (.NET Process.Start()) 以编程方式执行此操作。
问题是它似乎不起作用,我偷偷怀疑这与创建的快捷方式将“开始于”参数设置为特定文件夹这一事实有关。
所以它看起来像这样:
Shortcut target: "C:\Program Files (x86)\MyPDFConvertor\MyPDFConvertor.exe"
Shortcut startin: "C:\Program Files (x86)\MyPDFConvertor\SomeSubfolder\SomeSubSubFolder"
我的代码如下。
System.Diagnostics.Process.Start("C:\\Program Files (x86)\\MyPDFConvertor\\MyPDFConvertor.exe", "C:\\MyFiles\\This is a test word document.docx");
从根本上来说,我的问题归结为:“Startin”对于快捷方式实际上意味着什么/做什么?在使用 shellexecute 或 Process.Start 启动应用程序时我可以复制此功能吗?
I have an application that creates a shortcut on my desktop and allows you to drag and drop files into the shortcut to perform an action (convert a word document to PDF). Now what I am trying to do is perform this action programmatically using shellexecute (.NET Process.Start()).
The problem is that it doesnt seem to be working and I have a sneaking suspicion this has something to do with the fact that the shortcut created has the "Start in" parameter set to a specific folder.
So it looks like this:
Shortcut target: "C:\Program Files (x86)\MyPDFConvertor\MyPDFConvertor.exe"
Shortcut startin: "C:\Program Files (x86)\MyPDFConvertor\SomeSubfolder\SomeSubSubFolder"
My code was the following.
System.Diagnostics.Process.Start("C:\\Program Files (x86)\\MyPDFConvertor\\MyPDFConvertor.exe", "C:\\MyFiles\\This is a test word document.docx");
Fundamentally my question boils down to: What does "Startin" actually mean/do for shortcuts and can I replicate this functionality when starting an application using either shellexecute or Process.Start?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您使用
Process.Start
时,您可以使用ProcessStartInfo
调用它,而ProcessStartInfo
又恰好能够设置WorkingDirectory
属性 - 这样您就可以可以复制这种行为。When you use
Process.Start
you can call it with aProcessStartInfo
which in turn happens to be able to setup aWorkingDirectory
property - this way you can replicate that behaviour.正如 Yahia 所说,设置WorkingDirectory 属性。您还需要引用论点。这是一个粗略的例子:
As Yahia said, set the WorkingDirectory property. You also need to quote the arguments. Here is a rough example: