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 5-Oct-12 0:37am
Edited 5-Oct-12 0:40am
(no name)53.4K
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 DamithSL 300
1 Zoltán Zörgő 170
2 OriginalGriff 150
3 Sergey Alexandrovich Kryukov 120
4 Maciej Los 115
0 OriginalGriff 7,740
1 DamithSL 5,769
2 Sergey Alexandrovich Kryukov 5,424
3 Maciej Los 5,076
4 Kornfeld Eliyahu Peter 4,539


Advertise | Privacy | Mobile
Web03 | 2.8.141223.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