locked
How to give Administrator Rights to code? RRS feed

  • Question

  • Hi,

    Friends I am working on a project called computer scanner, But when i run my code in order to scan my hard drives its gives me an exception "Access Denied to Documents and Setting Folders" , I am using some code which would allow me to run my code as a Administrator, but still showing me the same exception.

    The codes are:

    WindowsIdentity CurrentIdentity = WindowsIdentity.GetCurrent();
                    WindowsPrincipal CurrentPrincipal = new      WindowsPrincipal(CurrentIdentity);

                    if (CurrentPrincipal.IsInRole(WindowsBuiltInRole.Administrator))
    {
    //Scanning Code will Execute
    }

    after using this code it still giving me an exception...

    Please Help.
    Wednesday, November 28, 2012 2:11 PM

Answers

  • Hi Nikhi,

    Welcome to the MSDN Forum.

    Please try this config: http://msdn.microsoft.com/en-us/library/windows/desktop/bb756929.aspx 

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, November 29, 2012 10:09 AM
    Moderator
  • Hi Nikhil,

    Please check this thread:http://answers.microsoft.com/en-us/windows/forum/windows_vista-security/access-denied-to-the-my-documents-and-settings/915eecc8-6a07-4d6a-8ca5-468ee51e9484

    The “My Documents and Settings” is not a folder used by Windows Vista.  It is what is called a junction point.  If you note, the folder itself is shaded out with a shortcut overlay.  If you have "Hide protected operating system files" unchecked, then you will see these junction points. It is intended that users have no access to these junction points.

     

    In Windows Vista, the “My Documents and Settings“, has been replaced by "Users".  Each user account will then have Documents, Pictures, videos etc.  Note the "My" designation is no longer used.  These junction points exist to provide backwards compatibility for older programs that are unaware of the new folder structure in Windows Vista.  A program that is hardcoded to install files in the old Documents and Settings will be silently redirected to the new location.

    So you need to change the folder name in your code.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, November 30, 2012 7:35 AM
    Moderator

All replies

  • Hi Nikhi,

    Welcome to the MSDN Forum.

    Please try this config: http://msdn.microsoft.com/en-us/library/windows/desktop/bb756929.aspx 

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, November 29, 2012 10:09 AM
    Moderator
  • How you are running you application? From Visual Studio or by clicking on .exe from debug/release folder?

    Have you tried running Visual Studio or your compiled .exe as Administrator (Right Click and Say run as admin?)

    If it does not resolve let me know your OS version too.


    Lingaraj Mishra

    Thursday, November 29, 2012 10:16 AM
  • Hi Sir,

    First of All, I would like to say thanks for Replying, 

    The Procedure to run my Program as a Administrator, which you asked me to Follow i have already did that  but still its giving me the same exception. 

    After learning about this "Access Denied" Exception from Internet, i have got to learn that, after adding "Manifest File" and including it in to my project my program can avail admin rights in order to run the program, and i have done the same, but unfortunately nothing as such happend.

    My computer Operating System is "window 7 Professtional, 64bit operating System".

    Sir Please Help,

    thanks in Advance :)

    Friday, November 30, 2012 5:13 AM
  • Hi Sir,

    Thanks For Replying Sir,

    I wanted to say that i have folllowed that procedure adding "Manifest File" to my project but still same issue i am facing. :(

    Friday, November 30, 2012 5:18 AM
  • Hi Nikhil,

    Please check this thread:http://answers.microsoft.com/en-us/windows/forum/windows_vista-security/access-denied-to-the-my-documents-and-settings/915eecc8-6a07-4d6a-8ca5-468ee51e9484

    The “My Documents and Settings” is not a folder used by Windows Vista.  It is what is called a junction point.  If you note, the folder itself is shaded out with a shortcut overlay.  If you have "Hide protected operating system files" unchecked, then you will see these junction points. It is intended that users have no access to these junction points.

     

    In Windows Vista, the “My Documents and Settings“, has been replaced by "Users".  Each user account will then have Documents, Pictures, videos etc.  Note the "My" designation is no longer used.  These junction points exist to provide backwards compatibility for older programs that are unaware of the new folder structure in Windows Vista.  A program that is hardcoded to install files in the old Documents and Settings will be silently redirected to the new location.

    So you need to change the folder name in your code.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, November 30, 2012 7:35 AM
    Moderator
  • Hi Sir,

    First of All, I would like to say thanks for Replying, 

    The Procedure to run my Program as a Administrator, which you asked me to Follow i have already did that  but still its giving me the same exception. 

    After learning about this "Access Denied" Exception from Internet, i have got to learn that, after adding "Manifest File" and including it in to my project my program can avail admin rights in order to run the program, and i have done the same, but unfortunately nothing as such happend.

    My computer Operating System is "window 7 Professtional, 64bit operating System".

    Sir Please Help,

    thanks in Advance :)

    Saturday, December 1, 2012 2:29 PM
  • The Documents and Settings folder doesn't exist on systems which are newer than XP. The folder can still come up in certain instances for some backwards compatibility, but you're not going to navigate it. For your scanner, check the attributes of the directory and make sure that it isn't a ReparsePoint before trying to navigate into it.
    Monday, December 3, 2012 1:02 AM
  • Hi Sir,

    Sir its not only about "Document and Settings" folders there are some other folders to which are not allowing me to have Access other folders like "System Volume Information", And i am building the PRroject called "Antivirus" and i wants to give All the Posible Rights to my Program and it should have all the access in order to scan the Folders.

    Sir Please Help me its very urgent I Have to submit this project Tommarrow itself anyhow Or else i am going to loose some Project Marks please Help.

    Thanks

    :)  

    Monday, December 3, 2012 6:43 AM
  • Hi Nikhil,

    This folder is system security folder. I am afraid there is no simple way to access it. 

    You need some APIs related to privileges.

    Our  managed forum is focused on break fix issues that are neither urgent, nor complex. If the issue is urgent to your business, it is recommended that you contact Microsoft Customer Spport Services(CSS) via telephone so that a dedicated Support Professional can assist you in a more efficient manner. Please be advised that contacting phone support will be a charged call. 

    to obtain the phone numbers for specific technology request please take a look at the web site listed below.

    http://support.microsoft.com/default.aspx?scid=fh;EN-US;PHONENUMBERS  

    If you are outside the US please see http://support.microsoft.com for regional support phone numbers.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, December 3, 2012 9:23 AM
    Moderator