Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
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.
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 4-Oct-12 23:37pm
Edited 4-Oct-12 23:40pm
53.1K
v2
Comments
Mehdi Gholam at 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 at 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
geekbond at 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)

  Print Answers RSS
0 Dnyaneshwar@Pune 604
1 OriginalGriff 394
2 thatraja 370
3 Sergey Alexandrovich Kryukov 334
4 CPallini 219
0 OriginalGriff 697
1 Dnyaneshwar@Pune 604
2 Kornfeld Eliyahu Peter 495
3 thatraja 370
4 Sergey Alexandrovich Kryukov 344


Advertise | Privacy | Mobile
Web02 | 2.8.140827.1 | Last Updated 5 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100