While investigating the new lockdown of the Microsoft Security Essentials Service controller I discovered while using the console application ‘SC” that the command “sc sdshow MsMpSvc” returns a SID for the service of S-1-5-80-685333868-2237257676-1431965530-1907094206-2438021966. Using a conversion tool I built using code found online it converted to the username of "NT SERVICE\MsMpSvc".
I started wondering if I could build an app that enumerates the services to get the names of the services and then gets the SID for each service. As I found out 1 out of 171 services installed on my system does not map from a Domain\Username to SID and that is the “AdobeARMservice”. That service returns a “System.Security.Principal.IdentityNotMappedException” but that is currently the only one that does.
What I was thinking was If I could do a check like “If svcname(“NT SERVICE\AdobeARMservice”).exist then” do whatever, but there is no function I can find that is that simple and I’m not sure how to write it or if this Idea would even work.
The problem is in a lack of error handling in the Microsoft “Translate” function, it throws the error then you’re done. I can't come up with a way to handle the error then continue.
The function listed below works as is as a workaround but I would like to do a better implantation but don’t have a clue how.
Any Ideas are appreciated. And thank you for your time.
Private Function convertServiceNameToSID(ByVal name As String)
Dim op As String
Dim svcname As String = name
If svcname = "NT SERVICE\AdobeARMservice" Then
Return "not supported"
Dim f As New Principal.NTAccount(svcname)
Dim s As Principal.SecurityIdentifier
s = DirectCast(f.Translate(GetType(Principal.SecurityIdentifier)), Principal.SecurityIdentifier)
Dim sidString As String = s.ToString()
op = sidString