Override NTFS permissions in code


Author
Message
Keith Chisarik
Keith Chisarik
StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)
Group: StrataFrame Users
Posts: 939, Visits: 40K
Question:

If I have an application I wrote that executes under Windows login "generaluser", I now want my application in specific scenarios to write a file to a network folder to which "generaluser" does not have write NTFS permissions. How can I accomplish this?

Keith Chisarik

Trent Taylor
Trent Taylor
StrataFrame Developer (8.7K reputation)StrataFrame Developer (8.7K reputation)StrataFrame Developer (8.7K reputation)StrataFrame Developer (8.7K reputation)StrataFrame Developer (8.7K reputation)StrataFrame Developer (8.7K reputation)StrataFrame Developer (8.7K reputation)StrataFrame Developer (8.7K reputation)StrataFrame Developer (8.7K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
You can go at this several ways and it can get somewhat complicated depending on the route that you take.  Let's first look at spawning an EXE to perform a certain action with different credentials. 

Dim startInfo As New System.Diagnostics.ProcessStartInfo("C:\MyApp.exe")
Dim password As New System.Security.SecureString()
Dim process As System.Diagnostics.Process

'-- Build the secure password string
For Each c As Char In "MyPassword"
    password.AppendChar(c)
Next

'-- Set the security login credentials
startInfo.UserName = "MyWindowsUser"
startInfo.Domain = "MYDOMAIN"
startInfo.Password = password

'-- Spawn the process
process = System.Diagnostics.Process.Start(startInfo)

'-- If you want to wait for the process to exit you can wait like this
process.WaitForExit()

Now if you want to create isolation levels within your assembly, it gets a lot more complicated.  You will have to apply security attributes and configure each client machine that will execute the code.  I am obviously not getting too deep here as this can become a really big tutorial in and of itself, but if you have this need, then a web search would probably be your best best as I ams ure that there are probably already some articles out on CodeProject or something along those lines showing how to do this.

Keith Chisarik
Keith Chisarik
StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)
Group: StrataFrame Users
Posts: 939, Visits: 40K
thanks, all I was hoping for was a namespace or starting place from someone who has done this, Google turned up a lot of options. I'll check out what you posted, appreciated as always.

Keith Chisarik
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search