none
Read registry values RRS feed

  • General discussion

  • Below is code that I have been trying to read the values within a folder that has curly brackets as part of the name.  I have tried to ASCII code to replace brackets but still no joy.  I am trying to determine if a server has left the domain.


    Const HKEY_CURRENT_USER = &H80000001
    Const HKEY_LOCAL_MACHINE = &H80000002

    strComputer = "."
     
    Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
        strComputer & "\root\default:StdRegProv")

    Dim fldr
    fldr = chr(123) & "B8A76F2B-3782-41C3-9863-F5E037A00F90" & chr(125)

     
    strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\Profiles" & fldr
    strValueName = "Category"
    wscript.echo strKeyPath

    oReg.GetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue

    Wscript.Echo "Category: " & dwValue

    • Changed type Bill_Stewart Friday, January 26, 2018 3:00 PM
    • Moved by Bill_Stewart Friday, January 26, 2018 3:00 PM Unanswerable drive-by question
    Thursday, November 30, 2017 5:16 PM

All replies

  • How does this help you determine if a computer is not joined to a domain?

    -- Bill Stewart [Bill_Stewart]

    Thursday, November 30, 2017 5:40 PM
  • This is how to do this correctly:

    strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\Profiles\{B8A76F2B-3782-41C3-9863-F5E037A00F90}"
    strValueName = "Category"
    
    Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
    returnValue = oReg.GetDWORDValue(&H80000002,strKeyPath,strValueName,dwValue)
    If returnValue = 0 Then
    	Wscript.Echo "Category: " & dwValue
    	If dwValue = 2 Then WScript.Echo "Connected to domain"
    Else
    	WScript.Echo "Failed with ReturnValue:"  & returnValue
    End If
    

    PowerShell is much easier.

    Get-ChildItem 'hklm:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\Profiles' | 
        Get-ItemProperty | 
        Select-Object ProfileName, Category
    As Bill has pointed out.  This sill not tell you if the "join" is fully functional.


    \_(ツ)_/

    Thursday, November 30, 2017 7:05 PM
  • thank you so much.  I have been hitting close but no wee-oh!

    I discovered something else to my well,,opps

    if this is not ran under administrator command prompt will not work correctly

    Thanks again

    Friday, December 1, 2017 8:44 PM