Marcelo,
I have to say, this generally is a bad idea. You should never, ever
take away the right from a user to do what they wish to their machine. What
happens if your app does something wrong, and writes a file to the directory
that needs to be removed for some reason or another? The user wouldn't be
able to fix it at all, since they wouldn't have the rights to remove the
folder and/or the files. You are making the assumption that your code will
be perfect, and also neglecting other factors that could affect your program
(what if the power goes out while writing one of these files, and it becomes
corrupt, for example).
Also, in order to do this all, if the user is on a network and not an
administrator, then more likely than not, they are not going to have the
rights to do this sort of thing.
That being said, to create a new user account, you will have to call the
NetUserAdd function in the Netapi32 dll through the P/Invoke layer. To
assign permissions to a folder for the new user, check out knowledge base
article 318744, titled "HOWTO: Use Visual Basic to Programmatically Change
Ownership of a File or Folder", located at (watch for line wrap):
http://support.microsoft.com/default.aspx?scid=kb;en-us;318744
As for starting your app using this new user, check out the
documentation for the Impersonate method on the WindowsIdentity class.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)
Marcelo López said:
I need to create a folder in the file system owned by an special user
created by my application. The idea is that only my app will have
permissions to delete and create files on that folder.
My app is a redistribuitable one, so i need to create the user and give
permissions to my app to that folder programatically.
My questions are:
1) Using c# how can i create a new user account
2) How can i asign permissions to a folder to the new user
3) how can i start my app using this new user ?
Regards,
Marcelo.