Click here to Skip to main content
11,496,146 members (603 online)
The site is currently in read-only mode for maintenance. Posting of new items will be available again shortly.
See more: VB VB.NET
Hi

I'd very much like to do exactly what the following script does, just from inside VB!

Const HKLM = &h80000002
Const profiles = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"
 
Set sh  = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
Set wmi = GetObject("winmgmts://./root/cimv2")
Set 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
    Set acct = wmi.Get("Win32_SID.SID='" & sid & "'")
    WScript.Echo acct.ReferencedDomainName & "\" & acct.AccountName
  End If
Next

JUST go through the SID keys in ProfileList and pull out the
ReferencedDomainName & "\" & Accountname

I'm sure some of you guys will find it trivial but I cannot make it work :-/

With Kind regards and high hopes

Samoht
Posted 13-Mar-13 3:30am
Comments
CHill60 at 13-Mar-13 8:32am
   
When you say you cannot make it work, what is the problem you encounter? Use the Improve Question link above to post the VB code you are having the problem with.
samoht relhe at 13-Mar-13 8:50am
   
Uhm. More or less it all.. how to get hold of the subkeys and read them and how to declare the needed objects..

I am not normally using VB.net but have to ad the fuctionality of the above to an existing form.

1 solution

Have a look at this codeproject article Working with Windows Registry using VB.NET[^] Unfortunately it's quite old but may be enough to get you going.
There is a slightly more recent (!) tutorial here http://www.dreamincode.net/forums/topic/31219-working-with-the-windows-registry-in-vbnet/[^]
The official Microsoft stuff is here http://msdn.microsoft.com/en-us/library/aa289494(v=vs.71).aspx[^]
Have a go with these examples and come back if you then have a specific issue
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 10,401
1 OriginalGriff 8,910
2 Sascha Lefèvre 3,899
3 Maciej Los 3,422
4 Richard Deeming 2,600


Advertise | Privacy | Mobile
Web04 | 2.8.150520.1 | Last Updated 13 Mar 2013
Copyright © CodeProject, 1999-2015
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