简体   繁体   English

一些Process.Start命令不起作用

[英]Some Process.Start commands not working

I am working on visual studio 2012 with C# , but some of the commands are not working with visual studio. 我正在使用C#开发Visual Studio 2012,但是某些命令不适用于Visual Studio。

I am trying to access 我正在尝试访问

 Process.Start(Path.Combine(Environment.SystemDirectory, "msconfig.exe"));

some other similar commands are not working. 其他一些类似的命令不起作用。 where as these functions are working fine in visual studio 2010 on same machine. 这些功能在Visual Studio 2010中的同一台机器上正常运行。 Please provide me some solution. 请给我一些解决方案。

it is showing "Win32Exception ... the system cannot find the file specified" 它显示“ Win32Exception ...系统找不到指定的文件”

Summarizing what I put in the comments - you're seeing the issue because you're running in a 32-bit process that is then subject to File System Redirection - your attempts to access the System directory get redirected to (by default) C:\\Windows\\SysWOW64. 总结一下我在评论中所发表的内容-由于在32位进程中运行该文件 ,然后要进行文件系统重定向 ,因此您会看到此问题-您访问系统目录的尝试将重定向到(默认情况下)C: \\的Windows \\ Syswow64资料。

This directory doesn't contain an msconfig.exe . 该目录不包含msconfig.exe

Visual Studio 2012, introduced a AnyCPU Prefer 32-bit option, and that is selected by default. Visual Studio 2012引入了AnyCPU Prefer 32-bit选项,默认情况下AnyCPU选中状态。

Best advice would be to switch your build platform to 64-bit , or uncheck Prefer 32-bit . 最好的建议是将构建平台切换为64-bit ,或者取消选中“ Prefer 32-bit

This is not beacuse of any security. 这不是因为任何安全性。 As exception says file not found at disk. 作为例外,说在磁盘上找不到文件。 This is the problem with Visual Studio Project file configuration. 这是Visual Studio Project文件配置的问题。

string path = Path.Combine(Environment.SystemDirectory, "msconfig.exe");
if(File.Exists(path))
  Process.Start(path);

I simply tried this using default configuration and found that the if check itself failed. 我只是使用默认配置尝试了此操作,发现if检查本身失败了。 In order to achieve this you will have to change the platform for project. 为了实现这一目标,您将不得不更改项目平台。 By default the Visual Studio environment is taking x86 always even though you are running 64-bit OS and selecting Any CPU. 默认情况下,即使您正在运行64位OS并选择“任何CPU”,Visual Studio环境也始终采用x86。 Below are the settings for your program to work. 以下是程序正常运行的设置。 Right click on project in Solution Explorer and Select Settings -> Build -> Plateform target -> Select x64. 在解决方案资源管理器中Right click on project ,然后选择设置->构建->平板目标->选择x64。

Have a look on below image for visual representation of settings: 在下面的图片中查看设置的直观表示:

在此处输入图片说明

Mark as answered if fixed your problem 如果已解决问题,则标记为已回答

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

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