Isr*_*uez 4 vb.net globalization permissions
所以,我正在做一个用VB.NET编写的安装项目,我需要向NetworkService帐户授予某个文件夹的权限.
以下代码非常完美(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)
Run Code Online (Sandbox Code Playgroud)
当我在Windows 7,Vista或XP上尝试这个相同的代码(全部在PT-BR中)时,问题就出现了,我发现没有"网络服务",正确的名称是"ServiçodeRede".
我需要获得此名称才能授予合适的用户权限.
经过对所有3个操作系统的大量调查,我发现用户的ID是:"S-1-5-20",他在注册表中的路径是:Computer\HKEY_USERS\S-1-5-20和它的默认文件夹:C:\ Windows\ServiceProfiles\NetworkService
但我仍然没有找到实际的"可本地化"名称,我需要它是动态的,因为这个系统将安装在许多不同的国家(不同的机器和文化).
提前致谢.
使用System.Security.Principal.WellKnownSidType枚举:
SecurityIdentifier networkService = new SecurityIdentifier(
WellKnownSidType.NetworkServiceSid, null);
FileSystemAccessRule rule = new FileSystemAccessRule(
networkService, FileSystemRights.FullControl, AccessControlType.Allow);
Run Code Online (Sandbox Code Playgroud)