的Process.Start权限问题权限、问题、Process、Start

由网友(一秒钟 想我△)分享简介:我想用的Process.Start运行从C#外部的问题,但我遇到了权限问题。当我常打开命令提示符(不作为管理员),然后执行我的命令,他们工作得很好,但是当我通过的Process.Start打开命令提示符,我得到一个写错误的目录。 (我不能写在文件test.log中)如果我运行它通过的Process.Start管理员它...

我想用的Process.Start运行从C#外部的问题,但我遇到了权限问题。当我常打开命令提示符(不作为管理员),然后执行我的命令,他们工作得很好,但是当我通过的Process.Start打开命令提示符,我得到一个写错误的目录。 (我不能写在文件test.log中) 如果我运行它通过的Process.Start管理员它工作正常,但我得到的权限弹出。没有人有任何的想法,可以帮助我想出解决办法?谢谢!

下面是code我使用:

 过程PROC =新工艺();
proc.StartInfo.FileName = @cmd.exe的;
proc.StartInfo.Arguments = @/ K乳胶C:用户巴蒂尔文档 test.tex;
proc.Start();
proc.WaitForExit();
 

解决方案

我不知道是否它试图写一个诊断日志当前工作目录中,您可能没有权限。 (我不知道随便是否会继承工作目录,或者是包含cmd.exe的目录)。我建议你指定使用新工艺的工作目录 ProcessStartInfo.WorkingDirectory

(顺便说一句,我个人觉得更清洁的创建一个新的的ProcessStartInfo 的填充该 - C#对象初始化使这个特别好),然后调用的Process.Start(的ProcessStartInfo)来启动它。否则,它看起来像有已经是一个过程时,有不止是一份呢。只是MHO虽然,无关你正在调查,可能是这个问题。)

Qt creater出现 启动程序失败,路径或者权限错误 或 The process could not be started 解决方法

I'm trying to run an external problem from C# by using Process.Start, but am running into permissions issues. When I open a command prompt normally (not as an admin) and run my commands they work fine, but when I open a command prompt via Process.Start, I get a write error on the directory. ("I can't write on file test.log") If I run it as an admin via Process.Start it works fine, but I get the permissions popup. Does anyone have any ideas that might help me figure this out? Thanks!

Here is the code I'm using:

Process proc = new Process();
proc.StartInfo.FileName = @"cmd.exe";
proc.StartInfo.Arguments = @"/k latex C:UsersShaneDocumentstest.tex";
proc.Start();
proc.WaitForExit();

解决方案

I wonder whether it's trying to write a diagnostic log to the current working directory, which you may not have permissions for. (I don't know offhand whether it will inherit the working directory, or be the directory that contains cmd.exe.) I suggest you specify the working directory for the new process using ProcessStartInfo.WorkingDirectory.

(As an aside, I personally find it cleaner to create a new ProcessStartInfo an populate that - C# object initializers make this particularly nice) and then call Process.Start(ProcessStartInfo) to start it. Otherwise it looks like there's already a process when there isn't really one yet. Just MHO though, and unrelated to the problem you're investigating, probably.)

阅读全文

相关推荐

最新文章