none
Why am I getting this exception: A required privilege is not held by the client?

    Question

  • Hi,

    I have a PC, and I'm the administrator. I wanted to create a test folder on my desktop with explicit access and audit rules. Here's my code:

     

      Dim dir As String = "C:\Users\Administrator\Desktop\Test Folder"
    
                Dim ds As New DirectorySecurity
                ds.AddAuditRule(New FileSystemAuditRule("Administrator", FileSystemRights.Read, _
                                                        AuditFlags.Success))
                ds.AddAccessRule(New FileSystemAccessRule("Administrator", FileSystemRights. _
                                                          ListDirectory, AccessControlType.Deny))
    
    
                Directory.CreateDirectory(dir, ds)
    

     


    When I try to run the application, I get an error saying "A required privilege is not held by the client". It's my home PC, I'm the administrator, and I'm running the application with admin privileges.

    Can anyone tell me why am I getting this error?

    Please help

    Regards,

    Abdul


    • Edited by Abdul A. Ali Thursday, December 01, 2011 10:25 AM
    Thursday, December 01, 2011 10:03 AM

Answers

  • Hi Abdul,

    Firstly, I suggest you can try to AddRules to other folders(not in device C:\) and run the program as Administrator(Right-Click the progra-> Run As Administrator).

    If you don't get error now, it may be caused by UAC. You can try to disable UAC:

    Disable UAC

    There are several ways to do that, I suggest two ways for you:

    1.      Modify the registry to disable UAC.

    You can set the disableUAC  Value in the registry (HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System)  to be 0 to disable and to 1 to enable.

    2.      Disable UAC in manifest.

    You can follow the solution from this thread.

     

    Much further information:

    UAC: All Information Developers need about the User Account Control (UAC)

    /MANIFESTUAC

    How to embed a manifest in an assembly


    Paul Zhou [MSFT]
    MSDN Community Support | Feedback to us
    • Marked as answer by Paul Zhou Friday, December 09, 2011 8:43 AM
    Friday, December 02, 2011 9:14 AM

All replies

  • Maybe the application wasn't started with administrative rights? Try to start it with administrative rights.

    Starting with Vista, UAC was introduced and administrators work without administrative rights by default.

    With kind regards,

    Konrad

    Thursday, December 01, 2011 10:19 AM
  • Thanks for the reply, Konrad.

    I've made sure that I'm running the application with administrative privileges.

    I tried to debug the application so that I can see what is causing the error. When I remove this

     ds.AddAuditRule(New FileSystemAuditRule("Administrator", FileSystemRights.Read, _
                                                        AuditFlags.Success))

    it works perfectly. So I think something is wrong with creating the Audit Rule.

     

    Please reply back.

     

    Regards,

    Abdul




    • Edited by Abdul A. Ali Thursday, December 01, 2011 10:30 AM
    Thursday, December 01, 2011 10:24 AM
  • Hi Abdul,

    Firstly, I suggest you can try to AddRules to other folders(not in device C:\) and run the program as Administrator(Right-Click the progra-> Run As Administrator).

    If you don't get error now, it may be caused by UAC. You can try to disable UAC:

    Disable UAC

    There are several ways to do that, I suggest two ways for you:

    1.      Modify the registry to disable UAC.

    You can set the disableUAC  Value in the registry (HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System)  to be 0 to disable and to 1 to enable.

    2.      Disable UAC in manifest.

    You can follow the solution from this thread.

     

    Much further information:

    UAC: All Information Developers need about the User Account Control (UAC)

    /MANIFESTUAC

    How to embed a manifest in an assembly


    Paul Zhou [MSFT]
    MSDN Community Support | Feedback to us
    • Marked as answer by Paul Zhou Friday, December 09, 2011 8:43 AM
    Friday, December 02, 2011 9:14 AM
  • Hi,

     

    Has your issue been resolved? Would you mind letting us know the result of the suggestions?

     

    Now I will mark an answer, you can mark others that you think to be so useful to your issue.

    If you still have any questions about this issue, please feel free to let me know. 

     

    Have a nice day!


    Paul Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Friday, December 09, 2011 8:43 AM
  • Hey, thanks all.

     

    My problem still stands. I tried everything, yet nothing.

    The problem is only when I'm creating a new folder with explicit permissions, like the example above. But if I'm adding an Access rule or and Audit rule, to an existing folder, it works fine.

     

    Please help

    Sunday, December 11, 2011 11:05 AM