如何使用 VB.NET 检索存储在计算机上的所有用户配置文件的用户名和域?下面的代码正是我需要的,但在 VBScript 中。我怎样才能在 VB.NET 中做同样的事情?
Const HKLM = &H80000002
Const profiles = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"
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