Click here to Skip to main content
15,892,643 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am using below code to access denied to user for calculator . I take Filename Path as"@"C:\Windows\System32\calc.exe.". But it denied the the Calculator of path @"C:\Windows\SysWOW64\calc.exe". How to resolve it.
C#
public string FileName = @"C:\Windows\System32\calc.exe";
  AddDirectorySecurity(FileName, "everyone", FileSystemRights.Read, AccessControlType.Deny);


 public void AddDirectorySecurity(string FileName, string Account, FileSystemRights Rights, AccessControlType ControlType)
        {
            try
            {
               

                DirectoryInfo dInfo = new DirectoryInfo(FileName);
              

                DirectorySecurity dSecurity = dInfo.GetAccessControl();
                dSecurity.SetAccessRuleProtection(true, false);

                dSecurity.AddAccessRule(new FileSystemAccessRule(Account,
                Rights, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
                PropagationFlags.None,
                ControlType));


                dInfo.SetAccessControl(dSecurity);
                MessageBox.Show("successfully");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message); 
            }
        }

I want to block calculator of this path =@"C:\Windows\System32\calc.exe".
but above code block calculator for this path=@"C:\Windows\SysWOW64\calc.exe"

but i want to block for path=@"C:\Windows\System32\calc.exe".
Posted
Updated 4-Oct-12 23:40pm
v2
Comments
Mehdi Gholam 5-Oct-12 5:47am    
Not a good way to do this since you can copy calc.exe to c:\ for example and execute from there.
Sergey Alexandrovich Kryukov 5-Oct-12 19:01pm    
Who needs an ugly calc.exe, ever? First, it's bad thing to execute an external process not designed for any kind of integration -- processes are well isolated. Secondly, it's relatively easy to develop a decent calculator component. A calculator with buttons per symbol is just a stupidity, imitation of stone-age device never used by reasonable computer users. I don't think it's a real working application, just a toy. If OP provides it to really calculate something, it's just a unacceptable style and usability.
--SA
Akinmade Bond 5-Oct-12 18:19pm    
The process that executes your code should be elevated. And yes, like Gholam said, the user can just copy the calc app to another path and execute from there.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900