使用C#将权限设置为文件 [英] Set Permission to a file using C#

查看:109
本文介绍了使用C#将权限设置为文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我想从我的C#应用​​程序中运行一个exe文件.在Windows 7中,由于兼容性问题,我必须以将兼容性设置为Windows Vista"和&该exe的以管理员身份运行"设置.

如何在应用程序中设置这些权限?网上找不到任何设置或以这种方式运行文件的答案.

如果更改应用程序的设置,该设置将应用于从我的应用程序调用的exe文件,该文件需要兼容性和以管理员身份运行"权限. exe文件将捆绑在我的应用程序文件中.

< pre>
processInfo = new ProcessStartInfo("cmd.exe","/C" +命令);
sb = new StringBuilder();
processInfo.UseShellExecute = false;
processInfo.RedirectStandardOutput = true;
processInfo.CreateNoWindow = true;
进程= Process.Start(processInfo);
process.BeginOutputReadLine();
process.OutputDataReceived + =新的DataReceivedEventHandler(Process_OutputDataReceived);

</pre>

我想以管理员身份启动cmd,因为它用来执行的(exe)文件可能需要管理员权限.
实际上,我在3-4个PC上测试了同一个应用程序'',并且以标准用户身份在没有任何特定权限的情况下在所有应用程序上运行.但是在客户的任何电脑上都无法正常工作.他拥有所有的Win 7和XP系统.我认为这可能与拥有较低级别的权限有关,否则可能是其他问题.无法找出问题,因此也无法决定解决方案.

任何帮助/指导都受到高度赞赏.被困住了,找不到同样的问题或解决方案.

谢谢

Hello,

I want to run an exe file form my C# application. In Windows 7, due to compatibility issue I got to run that file as "set compatibility as Windows Vista" & "Run as Administrator" settings for that exe.

How can I set these permissions from my application? Couldn''t find on net any answers to set such things or run a file in such a way.

If I change my application''s settings will that be applied to the exe file that I calling from my application whose compatibility and "Run as Admin" permissions are needed. The exe file will be bundled in my application file.

<pre>
processInfo = new ProcessStartInfo("cmd.exe", "/C " + command);
sb = new StringBuilder();
processInfo.UseShellExecute = false;
processInfo.RedirectStandardOutput = true;
processInfo.CreateNoWindow = true;
process = Process.Start(processInfo);
process.BeginOutputReadLine();
process.OutputDataReceived += new DataReceivedEventHandler(Process_OutputDataReceived);

</pre>

I want to start the cmd as admin as the (exe) file it uses to execute may need admin access.
Actually I tested the same app on 3-4 pcs'' and its running on all without any specific permissions as standard users. But on clients any pc its not working. He has all Win 7 and XP systems. I think it might be related to have low level permissions or what else can be the problem. Am not able to make out the problem and hence can''t decide with the solution also.

Any help/guidance is highly appreciated. Am stuck up and can''t find the problem or solution for the same.

Thanks

推荐答案

兼容模式: (通过google找到)

http://social.msdn.microsoft.com/Forums/zh_cn/windowscompatibility/thread/bc32887d-4fcf-4416-aa22-36a93dfeb644 [
Compatibility mode: (found this with google)

http://social.msdn.microsoft.com/Forums/en/windowscompatibility/thread/bc32887d-4fcf-4416-aa22-36a93dfeb644[^]

Run as administrator: (found this with google)

You need to create a string value (REG_SZ) under one of these keys (if you want the setting to be per user or per machine, respectively):

HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers

or

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers

The name of the value needs to be the full path to your executable (if the path contains spaces, do not surround the path with quotes) and the data of the value must contain the string RUNASADMIN.


要设置兼容性,您需要使用注册表,请参见以下线程:

http://social.msdn.microsoft.com/Forums/zh_cn/windowscompatibility/thread/bc32887d-4fcf-4416-aa22-36a93dfeb644 [ http://msdn.microsoft.com/en-us/library/bb756929.aspx [ ^ ]

您需要使用requireAdministrator.
For setting the compatibility, you need to use the registry, see this thread:

http://social.msdn.microsoft.com/Forums/en/windowscompatibility/thread/bc32887d-4fcf-4416-aa22-36a93dfeb644[^]

For elevating UAC access, see:

http://msdn.microsoft.com/en-us/library/bb756929.aspx[^]

You need to use requireAdministrator.


这篇关于使用C#将权限设置为文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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