C#新建过程中产生的不能访问某些文件 [英] C# New process created cannot access certain files

查看:129
本文介绍了C#新建过程中产生的不能访问某些文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了C#的过程(比如CMD.EXE)。但是,所创建的exe不能够访问所有的文件由用户运行的方法。

I created a process in C# (say cmd.exe). But, the created exe is not able to access all of the files as a process run by the user.

我已经清楚地嵌入屏幕画面说明了这个问题。其中我的应用程序创建的进程(CMD)是在左侧,一个在右侧打开直接与运行命令。我已经做了DIR CMD在这两个命令提示符中运行。在计数的差异大大惊人的我。

The screenshot which I have embedded clearly illustrates this issue. The process (cmd) which my application created is in the left side and the one in right side is opened with a run command directly. I have made a dir cmd to execute on both of these command prompts. The difference in the count is greatly astonishing me.

对不起它喊,我没有足够的声誉。截图的所以才的链接。

Sorry it shouts that I don't have enough reputation. So just the link of the screenshot.

该截图显示

我认为有关应用程序的高度,因为我认为这个过程是不允许访问的所有文件该系统为标准用户。所以我提升的过程。

I considered about the elevation of the application, because I thought that the process was not allowed to access all the files of the system to a standard user. So I elevated the process.

在我的计划,我试图创建一个cmd提示符并执行java命令由它来运行jar文件。

In my program, I tried to create a cmd prompt and execute the java command from it to run a jar file.

也不要问有关PATH变量(等等,等等,等等)。由于java.exe的掌握在system32 /文件夹这已经是在PATH变量。

Also don't ask about the PATH variables (blah, blah, blah). Because the java.exe rests in the system32/ folder which is already in the PATH variable.

下面是创建新进程的函数的源代码。

The following is the source code of a function that creates the new process.

Process process = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo(@"C:\Windows\System32\cmd.exe");
startInfo.UseShellExecute = true;
startInfo.Verb = "runas";
startInfo.Arguments = "/C java.exe";
process.StartInfo = startInfo;
process.Start();



不久,


  • x是用的Process.Start

  • 创建新进程
  • x不能找到其中通常应用程序查找一个文件。

  • X得到管理员权限也
  • x是颇为神秘??

  • x is a new process created with Process.start
  • x can't find a file which an usual app finds.
  • x got admin rights also
  • x is quite mysterious??

修改


  • 假设x是一个cmd.exe的,它打开C:/中/ Windows的Syswow64资料代替预计C:/在Windows / System32下运行命令 CD C:/在Windows / System32下/

  • 我如何访问的实际System32下文件夹?

推荐答案

看一下文件大小,他们也不同,实际上文件夹是不一样的。右边是C:\windows\system32而左边C:\Windows\SysWOW64

Look at the file sizes, they are also different, and actually the folders are not the same. On the right is C:\windows\system32 while on the left C:\Windows\SysWOW64

似乎是位数的问题。通过Windows任务管理器中查看你的流程的位数。左侧的人都应该有* 32旁边。它运行作为32位进程,默认情况下是在SysWow64文件夹

Seems to be a matter of bitness. Check by the windows task manager the bitness of your processes. The one on the left should have *32 next to it. It runs as an 32 bit process and by default is in SysWow64 folder

请注意:OP再改目标平台到x64其解决了问题。

Note: OP then changed the target platform to x64 which solved the issue

这篇关于C#新建过程中产生的不能访问某些文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆