Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
552 views
in Technique[技术] by (71.8m points)

permissions - setting UAC settings of a file in C#

i want to give a file(already present on the client computer .exe) permissions to always execute with administrative permissions.

please note that the file i wants to give permissions is already on target machine. and i want to change permissions of that file through another program written in c# and it has administrative permissions to do everything.

kindly let me know how to do it i am using this code

        System.Security.AccessControl.FileSecurity fs = File.GetAccessControl(@"c:inam.exe");
        FileSystemAccessRule fsar = new FileSystemAccessRule("Everyone", FileSystemRights.FullControl, AccessControlType.Allow);
        fs.AddAccessRule(fsar);
        File.SetAccessControl(@"c:inam.exe", fs);

this code will change the permissions correctly but still when i execute inam.exe after executing this code the UAC not appeared and also the inam.exe cant perform administrative operations.

actually i have already deployed an application on more than 10,000 clients so wants to release a patch to resolve the administrative rights issue.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Execute with administrative privileges is not a file permission.

This is usually configured by adding a manifest file (either to the Win32 resources in the EXE, or as an external manifest). This manifest file can state whether the application needs to run elevated or not.

I'm not entirely sure where Windows stashes the "Run this program as an administrator" compatibility setting.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...