为什么这个过程没有启动?
我正在尝试启动位于以下位置的进程 Store.Client.UI.exe:“C:\Program Files\Intel\IntelAppStore\bin\Store.Client.UI.exe”或“C:\Program Files ( x86)\Intel\IntelAppStore\bin\Store.Client.UI.exe”对于像我这样的 64 位,所以我使用代码:
If My.Settings.instpathtype = 86 Then
Process.Start("C:\Program Files\Intel\IntelAppStore\bin\Store.Client.UI.exe")
Else
Process.Start("C:\Program Files (x86)\Intel\IntelAppStore\bin\Store.Client.UI.exe")
End If
其中 my.settings.instpathtype 是计算机是 64 位还是 32 位。但是当我运行它时,由于某种原因它没有运行 Store.Client.UI.exe。当我进入资源管理器并输入“C:\Program Files (x86)\Intel\IntelAppStore\bin\Store.Client.UI.exe”时,它会运行 Store.Client.UI.exe。怎么了?
I'm trying to start the process Store.Client.UI.exe which is located at: "C:\Program Files\Intel\IntelAppStore\bin\Store.Client.UI.exe", or "C:\Program Files (x86)\Intel\IntelAppStore\bin\Store.Client.UI.exe" for 64bit like me, so I use the code:
If My.Settings.instpathtype = 86 Then
Process.Start("C:\Program Files\Intel\IntelAppStore\bin\Store.Client.UI.exe")
Else
Process.Start("C:\Program Files (x86)\Intel\IntelAppStore\bin\Store.Client.UI.exe")
End If
Where my.settings.instpathtype is whether the computer is 64 or 32 bit. But when I run it, it doesn't run Store.Client.UI.exe for some reason. When I go into Explorer and type "C:\Program Files (x86)\Intel\IntelAppStore\bin\Store.Client.UI.exe" it runs Store.Client.UI.exe. What's wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
从您发布的代码中,我不知道您在哪里/如何获取
instpathtype
的值,或者它被声明为什么类型。但无论如何,你真的不应该这样做。 文件系统的硬编码路径是 如果您希望代码“正常工作”,这是非常糟糕的做法。您上面发布的内容不仅会因操作系统的位数而中断,而且如果用户重命名或移动其程序文件也会中断文件夹。如果我的启动驱动器是 E:,您的代码在我的计算机上也会失败。
相反,您应该使用特殊的系统文件夹。这样,您甚至不需要检查您运行的是 32 位还是 64 位操作系统。 .NET Framework 提供了一种非常简单的方法来通过
获取这些值Environment.GetFolderPath
方法,并指定 您要检索的文件夹的类型。在这种情况下,无论主机操作系统的位数如何,您都需要 32 位 Program Files 文件夹,因此您可以使用
ProgramFilesX86
值来检索相应的文件夹,如下所示:From the code that you posted, I don't know where/how you're getting the value for
instpathtype
, or what type it is declared as.But regardless, you really shouldn't be doing it this way. Hard-coding paths to the file system is a very bad practice if you want your code to "Just Work." What you posted above will not only break depending on the bitness of the OS, but also if the user has renamed or moved their Program Files folder. If my boot drive is E:, your code will fail on my computer as well.
Instead, you should be using the special system folders. That way, you don't even need to check whether you're running on a 32-bit or 64-bit operating system. The .NET Framework provides a really easy way of getting at these values with the
Environment.GetFolderPath
method, and specifying the type of folder you want to retrieve.In this case, you want the 32-bit Program Files folder, regardless of the host OS's bitness, so you can use the
ProgramFilesX86
value to retrieve the appropriate folder, like so:当您遇到这样的问题时,调试就开始了。尝试通过简单的
MessageBox
或类似的内容来显示My.Settings.instpathtype
输出的内容。如果您的测试机器是 32 位,并且输出与86
不同,请更改它。编辑:所以我猜你有一台 64 位机器?换个方式试试。交换
If
和Else
下的语句,然后将My.Settings.instpathtype
的输出放在条件处。编辑:如果条件没有错误,则可能是因为
\
被读取为转义字符。您可以通过在其前面添加另一个\
来修复它。When you are encountering problems like this, debugging comes in. Try to display what
My.Settings.instpathtype
outputs, by a simpleMessageBox
or similar. If your testing machine is 32 bit, and if the output is different from86
, change it.EDIT: So I guess you have a 64 bit machine? Try it the other way around. Swap the statements under
If
andElse
, then putMy.Settings.instpathtype
's output at the condition.EDIT: If there are no errors on the condition, then it might be because
\
is being read as an escape character. You can fix it by adding another\
before it.该进程可能正在启动,然后立即退出并出现错误。使用 Process.Start 的返回进程并检查其一些属性,例如 proc.exitcode、proc.starttime 和 proc.exittime。
It's possible the process is starting and then exiting immediately with an error. Use the return process from Process.Start and check some of its properties, such as proc.exitcode, proc.starttime, and proc.exittime.