So, I'm doing a setup project, all written in VB.NET, and I need to give to the NetworkService account, permission on a certain folder.
The following code works perfect (Windows 7 - en-US):
Dim dInfo As New DirectoryInfo("C:\FolderOrFileToGivePermission")
Dim dSecurity As DirectorySecurity = dInfo.GetAccessControl()
dSecurity.AddAccessRule(New FileSystemAccessRule("NETWORK SERVICE", FileSystemRights.FullControl, AccessControlType.Allow))
dInfo.SetAccessControl(dSecurity)
The problem began when I try this very same code on my Windows 7, Vista or XP (all in PT-BR) , I found that there is no "NETWORK SERVICE", the correct name is "Serviço de Rede".
I need to get this name to give permission to the right user.
After a lot of investigation on all 3 OSes, I found that the ID for the user is: "S-1-5-20", his path on the registry is: Computer\HKEY_USERS\S-1-5-20 and the default folder for it: C:\Windows\ServiceProfiles\NetworkService
But I still didn't find the actual "localizable" name and I need it to be dynamic, because this system will be installed in a lot of different countries (different machines and cultures).
Thanks in advance.