Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

windows

iis-6

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?

like image 367
username Avatar asked Oct 12 '11 11:10

username


1 Answers

Just use this code:

var account = new SecurityIdentifier(WellKnownSidType.NetworkServiceSid, null).Translate(typeof(NTAccount)).Value;
like image 88
Henning Krause Avatar answered Sep 24 '22 19:09

Henning Krause