简体   繁体   中英

How to get localized version of built-in windows 'Network Service' account?

In order to setup my web application I need to give a full control to a certain folder for a 'NETWORK SERVICE' account. It works fine, but on a non English systems I'm getting System.Security.Principal.IdentityNotMappedException . This is because the name of this built-in account is localized for that system (I'm using harcoded value 'NETWORK SERVICE' ). Is there a way to find out programmatically what the localized version of 'NETWORK SERVICE' is?

只需使用此代码:

var account = new SecurityIdentifier(WellKnownSidType.NetworkServiceSid, null).Translate(typeof(NTAccount)).Value;

I guess you can p/invoke LookupAccountSid() , since it returns the localized account name . The SID of Network Service is S-1-5-20 .

You can find the method signature and an invocation example here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM