Click here to Skip to main content
12,620,840 members (35,835 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: VB VB.NET
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"
    Else
        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
    End If
 
    Return op
End Function
Posted 2-Dec-12 20:49pm
ledtech313.8K

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Wrap your s = DirectCast(f.Translate...) line in a Try/Catch block. When Translate throws, your Catch block will execute where you can return any string you want to the caller.

Really, it sounds as though you need to go through a beginners book on VB.NET. Exception handling is a basic skill.
  Permalink  
v2
Comments
ledtech3 3-Dec-12 12:10pm
   
I tired that but I guess I was to broad on what I had inside of the try catch
I have a half a dozen VB.net 2005 books and none help with that problem.
I know it was a easy fix but I just couldn't think of it at 2 am and get it to work.
Thanks for your help. Works great.
Dave Kreskowiak 3-Dec-12 14:30pm
   
Google for "VB.NET Exception Handling". Some broader search terms would have resulted in better hits.
ledtech3 3-Dec-12 20:47pm
   
Thanks,
Maybe I should have gotten some sleep and tried it again in the morning. : s
But maybe this will help someone else.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.161128.1 | Last Updated 3 Dec 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100