Click here to Skip to main content
12,816,270 members (34,586 online)
Rate this:
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)

                DirectoryInfo dInfo = new DirectoryInfo(FileName);

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

                dSecurity.AddAccessRule(new FileSystemAccessRule(Account,
                Rights, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,

            catch (Exception ex)

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
Updated 5-Oct-12 0:40am
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.
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.
geekbond 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
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170308.1 | Last Updated 5 Oct 2012
Copyright © CodeProject, 1999-2017
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