Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8980939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:12:37+00:00 2026-06-15T20:12:37+00:00

I have an application where I would like users to be able to perform

  • 0

I have an application where I would like users to be able to perform an SQL/Server backup to their home directory. Because SQL is running under the Network Service account it gives a file system permission error when attempting the backup. I’ve tried the following code and a few variants to try giving full control to the network account:

Public Sub GiveFolderNetworkAccess(FilePath As String)
    Dim SID As SecurityIdentifier = New SecurityIdentifier(WellKnownSidType.NetworkServiceSid, Nothing)
    Dim FolderInfo As IO.DirectoryInfo = New IO.DirectoryInfo(FilePath)
    Dim FolderAcl As New DirectorySecurity
    FolderAcl.AddAccessRule(New FileSystemAccessRule(SID, FileSystemRights.FullControl, InheritanceFlags.ContainerInherit Or InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow))
    FolderInfo.SetAccessControl(FolderAcl) 
End Sub

Hower I get a System.UnauthorizedAccessException exception when calling FolderInfo.SetAccessControl. I’ve also tried the code on non-Windows paths where the user has full control and get the same result. Any ideas appreciated, I’m currently testing this under Windows 7 and .NET Framework 4.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T20:12:38+00:00Added an answer on June 15, 2026 at 8:12 pm

    Many thanks to OwerFlov for his suggestion that setting the permissions on a folder would require elevation even if the user had permission on the folder, that indeed turned out to be the case. For the specific application I decided to create a backup directory using InstallShield with appropriate permissions and then copy the SQL/Server backup file to the final destination. I used compression so the extra file access was required anyway.

    I’ve since had a chance to research further and found that changing access on a specific file does not require elevation. For any similar future requirements I’ve written the following code that creates an empty file with full control permission granted to the Network Service account:

    Public Sub CreateFileWithNetworkAccess(fileName As String)
        File.Create(fileName).Dispose()
        Dim SID As SecurityIdentifier = New SecurityIdentifier(WellKnownSidType.NetworkServiceSid, Nothing)
        Dim fSecurity As FileSecurity = File.GetAccessControl(fileName)
        Dim accessRule As FileSystemAccessRule = New FileSystemAccessRule(SID, FileSystemRights.FullControl, AccessControlType.Allow)
        fSecurity.AddAccessRule(accessRule)
        File.SetAccessControl(fileName, fSecurity)
    End Sub
    

    Doing some testing SQL/Server will successfully overwrites an empty file with the backup set.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ASP.NET 3.5 web application and I would like to allow users
I have an application A that I would like to be able to invoke
I have a web application (ASP.NET C#) where I would like the users to
I would like to enable users of my we application to be able to
I would like to allow users of my application to be able to place
I have a JSF application that uses mostly Richfaces. I would like to introduce
We have a customer that would like to modify application user messages that we
I would like to make my own user-mode NAT application. I have the folowing
I have an application I would like to force SSL on the login page
I have an application where I would like to make my reducers (I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.