Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Get the user names and domains of all locally stored user profi

samohtrelhesamohtrelhe Posts: 2Member
Hi
I'd like to retrieve the user names and domains of all user profiles stored on a computer, through WMI, using VB.NET?
The Code below does exactly what I need, but in VBScript.
How can I convert it to VB.NET?
(I do not want to use "Win32_UserAccount" :-)

Const HKLM = &H80000002
Const profiles = "SOFTWAREMicrosoftWindows NTCurrentVersionProfileList"

sh = CreateObject("WScript.Shell")
fso = CreateObject("Scripting.FileSystemObject")
wmi = GetObject("winmgmts://./root/cimv2")
reg = GetObject("winmgmts://./root/default:StdRegProv")

reg.EnumKey(HKLM, profiles, subkeys)
For Each sid In subkeys
reg.GetStringValue(HKLM, profiles & "" & sid, "ProfileImagePath", path)
path = sh.ExpandEnvironmentStrings(path)
If fso.FolderExists(path) Then
acct = wmi.Get("Win32_SID.SID='" & sid & "'")
CheckedListBox1.Items.Add(acct.ReferencedDomainName & "" & acct.AccountName)
End If
Next

(CheckedListBox1 is added by me in stead of WScript.echo.)


Comments

Sign In or Register to comment.