Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


read the registry of a remote computer

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,24334
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> read the registry of a remote computer
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 read the registry of a remote computer - 7/29/2005 8:31:11 PM   
  the_apostle21


Posts: 54
Score: 0
Joined: 7/29/2005
Status: offline
hi guys...i have a question.

i want to be able to read the registry of a remote computer in a vb script.  i need to use the pc's ip address, as our wan doesnt allow pc names accross it.

does anybody know how to do this, as i have been searching the net for days...any help will be greatly appreciated.

cheers.
 
 
Post #: 1
 
 RE: read the registry of a remote computer - 7/30/2005 8:23:38 AM   
  Snipah


Posts: 1343
Score: 6
Joined: 11/1/2004
From: Netherlands
Status: offline
Hi The_Apostle21,

I use this function very much at work, to read the remote registry to fill the CMDB.

Try this, as the large one i use, is at work....

Dim var, strComputer
strComputer = 127.0.0.1
var = RegRead("\\" & strComputer & "\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion", "ProgramFilesDir")
MsgBox "Program files are in: " & var

_____________________________

For more information, please see the "Read me First" topic.

http://www.visualbasicscript.com

(in reply to the_apostle21)
 
 
Post #: 2
 
 RE: read the registry of a remote computer - 7/30/2005 12:56:31 PM   
  the_apostle21


Posts: 54
Score: 0
Joined: 7/29/2005
Status: offline
Hi Snipah,

thanks for the input.  But i copied your code and tried to run it, but i get an error on line 3...is there something else that needs to be a part of the 'RegRead'?

thanks again for you help

(in reply to Snipah)
 
 
Post #: 3
 
 RE: read the registry of a remote computer - 7/30/2005 7:14:35 PM   
  Snipah


Posts: 1343
Score: 6
Joined: 11/1/2004
From: Netherlands
Status: offline
hmmm, i grabbed it from a site which said that this may also do the trick....

Actually what must happen is that the script must access the PC just like a Win32 class...i already had doubts when i saw it, but hey, you never know, unfortunatly i didn't had time left to test it, or else would've seen it was not working...

To connect i remember that i used the StdRegProv....

Aha, i found a copy on my USB stick.... pls see below:


Const HKEY_CLASSES_ROOT   = &H80000000
Const HKEY_CURRENT_USER   = &H80000001
Const HKEY_LOCAL_MACHINE   = &H80000002
Const HKEY_USERS       = &H80000003
Const HKEY_CURRENT_CONFIG  = &H80000005

sMethod  = "GetStringValue"
hTree  = HKEY_LOCAL_MACHINE
sKey  = "SYSTEM\CurrentControlSet\Services\lanmanserver\parameters"
sValue  = "srvcomment"

Set oRegistry = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
Set oMethod = oRegistry.Methods_(sMethod)
Set oInParam = oMethod.inParameters.SpawnInstance_()

oInParam.hDefKey = hTree
oInParam.sSubKeyName = sKey
oInParam.sValueName = sValue

Set oOutParam = oRegistry.ExecMethod_(sMethod, oInParam)

CompDescription = oOutParam.Properties_("sValue")  '*** place the reg info in CompDescription

'*** the function below is to write to the remote reg... using the above var's
Function writeRemoteReg()
sMethod  = "SetStringValue"
hTree  = HKEY_LOCAL_MACHINE
sKey  = "SYSTEM\CurrentControlSet\Services\lanmanserver\parameters"
sValue  = "srvcomment"
oInParam.hDefKey = hTree
oInParam.sSubKeyName = sKey
sValue = Worksheet.Cells(4, 4).Value '*** i use excel to generate info, and write info on the same screen
End Function

< Message edited by Snipah -- 7/30/2005 7:17:37 PM >


_____________________________

For more information, please see the "Read me First" topic.

http://www.visualbasicscript.com

(in reply to the_apostle21)
 
 
Post #: 4
 
 RE: read the registry of a remote computer - 7/30/2005 9:26:22 PM   
  the_apostle21


Posts: 54
Score: 0
Joined: 7/29/2005
Status: offline
Hi Snipah,

thanks again for your help.  but i cannot seem to get CompDescription to pick up any info.  i changed the 'strComputer' variable to my computer name and  sValue  = "srvcomment" to be  sValue  = "size", simply to match a value that was in the registry.  this still returned no value....or is this wrong??

help!!!

(in reply to Snipah)
 
 
Post #: 5
 
 RE: read the registry of a remote computer - 7/31/2005 12:26:04 AM   
  Snipah


Posts: 1343
Score: 6
Joined: 11/1/2004
From: Netherlands
Status: offline
1) what key are you reading?
2) what is the expected output?
3) what OS are you on?

please provide the above, so i can imitate your environment...

_____________________________

For more information, please see the "Read me First" topic.

http://www.visualbasicscript.com

(in reply to the_apostle21)
 
 
Post #: 6
 
 RE: read the registry of a remote computer - 7/31/2005 6:47:07 PM   
  the_apostle21


Posts: 54
Score: 0
Joined: 7/29/2005
Status: offline
I as simply just copying your code straight into a vbs.  All i changed is the 'sValue' as stated above...i think this is the key the script is trying to read, but i am not sure.

I am on windows xp and that location does exist, probably by default.

thanks

(in reply to Snipah)
 
 
Post #: 7
 
 RE: read the registry of a remote computer - 7/31/2005 9:39:07 PM   
  Snipah


Posts: 1343
Score: 6
Joined: 11/1/2004
From: Netherlands
Status: offline
 
Aha, i took a look at the key...(my bad)

the error is in "sMethod  = "GetStringValue"" since the key is not a string....

'************************************************************************
'These are examples For 'sMethod'
'
'GetBinaryValue - reads regisry value of BINARY type
'GetDWORDValue - reads registry value of DWORD type
'GetExpandedStringValue - reads registry value of EXPANDED STRING type
'GetMultiStringValue - reads registry value of MULTI STRING type
'GetStringValue - reads registry value of STRING type
'CreateKey - creates registry key
'SetBinaryValue - writes registry value of BINARY type
'SetDWORDValue - writes registry value of DWORD type
'SetExpandedStringValue - writes registry value of EXPANDED STRING type
'SetMultiStringValue - writes registry value of MULTI STRING type
'SetStringValue - writes registry value of STRING type
'DeleteKey - deletes registry key
'DeleteValue - deleting registry value
'EnumKey - enumerates registry key
'EnumValues - enumerates registry value
'CheckAccess - checks permissions on registry key
'************************************************************************


_____________________________

For more information, please see the "Read me First" topic.

http://www.visualbasicscript.com

(in reply to the_apostle21)
 
 
Post #: 8
 
 RE: read the registry of a remote computer - 8/5/2005 3:54:33 PM   
  the_apostle21


Posts: 54
Score: 0
Joined: 7/29/2005
Status: offline
thanks very much Snipah...i will give that a go!!

(in reply to Snipah)
 
 
Post #: 9
 
 RE: read the registry of a remote computer - 8/10/2005 4:32:28 PM   
  the_apostle21


Posts: 54
Score: 0
Joined: 7/29/2005
Status: offline
Hi Snipah,

thanks for your help...i have managed to get my script to run without errors!!!  the problem is i dont think the sql queries are running.  I have created the connection to the database, but im not sure if my syntax is incorrect or the query structure is wrong.

here is the script...if you can tell me what i am doing wrong, that would be greatly appreciated...



    ' Set some variables & constants
KEY_VERSION = "Version"
KEY_PATCH = "Patch"
KEY_HOTFIX = "Hotfix"
Const HKEY_LOCAL_MACHINE = &H80000002


    ' Create the queries
Q_FIRSTSTORE = _
"    select top 1 branch_code as FIRST_BRANCH, no_pos_terminals as CURRENT_TILL, ip_address as CURRENT_IP   " & _
"        from  branch  " & _
"        where  " & _
"        ip_address <> '0.0.0.0'  "

Q_COUNT = _
"    select count(branch_code) as TOTAL  " & _
"        from  branch  " & _
"        where  " & _
"        ip_address <> '0.0.0.0'  "

Q_CURRENTSTORE = _
"      select top 1 branch_code as CURRENT_BRANCH, no_pos_terminals as CURRENT_TILL, ip_address as CURRENT_IP  " & _
"          from  branch  " & _
"      where  " & _
"        ip_address <> '0.0.0.0' and branch >= OTHER_BRANCH  "

Q_REGSET = _
"    update AR_VERSION set  " & _
"        ip_address = ' & CURRENT_IP & '  " & _
"        ar_version = ' & VALUE_VERSION & '  " & _
"        ar_patch = ' & VALUE_PATCH & '  " & _
"        ar_hotfix = ' & VALUE_HOTFIX & '  " & _
"        where  " & _
"        locid = ' & CURRENT_BRANCH & '  " & _
"        and  " & _
"        till_no = ' & CURRENT_TILL & '  "


    ' Connect to the dataware database
Set DW_CONNECT = CreateObject( "ADODB.Connection" )
DATAWARE = "Driver={MySQL ODBC 3.51 Driver};Server=hydra;Port=3306;Database=DATAWARE;Uid=root;Pwd=root;"
DW_CONNECT.Open DATAWARE


' **************************************************************************
' ANGUS & COOTE


    ' Connect to the A&C database
Set AC_CONNECT = CreateObject( "ADODB.Connection" )
ACDATA = "Driver={SQL Server};Server=ROMEO;Database=LIVEACHODATA;Uid=aspuser;Pwd=aspuser;"
AC_CONNECT.Open ACDATA


    ' Find the first store
AC_CONNECT.Execute (Q_FIRSTSTORE)


    ' Count all the stores
AC_CONNECT.Execute (Q_COUNT)
wscript.echo "total = " & total
wscript.quit

    ' Here we go
FIRST_BRANCH = OTHER_BRANCH
do until COUNT = TOTAL
    if FIRST_BRANCH <> OTHER_BRANCH then
    AC_CONNECT.Execute Q_CURRENTSTORE
    end if
    do until CURRENT_TILL = 0
        Set oReg=GetObject("winmgmts:\\" & CURRENT_IP & "\root\default:StdRegProv")
        REG_PATH = "SOFTWARE\Data Group Systems Ltd\AdvanceRetail"
        oReg.GetExpandedStringValue HKEY_LOCAL_MACHINE,REG_PATH,KEY_VERSION,VALUE_VERSION
        oReg.GetExpandedStringValue HKEY_LOCAL_MACHINE,REG_PATH,KEY_PATCH,VALUE_PATCH
        oReg.GetExpandedStringValue HKEY_LOCAL_MACHINE,REG_PATH,KEY_HOTFIX,VALUE_HOTFIX

        DW_CONNECT.Execute Q_REGSET

        VALUE_VERSION = "blank"
        VALUE_PATCH = "blank"
        VALUE_HOTFIX = "blank"

        CURRENT_IP + 1
        CURRENT_TILL - 1
    loop
    CURRENT_BRANCH = OTHER_BRANCH + 1
COUNT + 1
loop
   
AC_CONNECT.Close

(in reply to the_apostle21)
 
 
Post #: 10
 
 RE: read the registry of a remote computer - 8/12/2005 11:39:10 AM   
  the_apostle21


Posts: 54
Score: 0
Joined: 7/29/2005
Status: offline
Can anyone help me with this at all??

(in reply to the_apostle21)
 
 
Post #: 11
 
 RE: read the registry of a remote computer - 8/20/2005 11:47:35 AM   
  ehvbs

 

Posts: 2169
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi the_apostle21,

trying to understand your 'multiple connection' problem, I stumbled upon this post.
I'm seldom successfull, if I post answers without testing the code first, but if you
"dont think the sql queries are running" then try this:

    ' Count all the stores
Dim oRS, total
Set oRS = AC_CONNECT.Execute (Q_COUNT)
total = oRS.Fields( 0 ).value
wscript.echo "total = " & total
wscript.quit

You have to assign the return value of Excute (the result set) to a (recordset)
variable, if the SQL statement is query (SELECT ..) and not an operation (data
definition/manipulation, e.g. UPDATE ..., CREATE TABLE, ..).

(in reply to the_apostle21)
 
 
Post #: 12
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> read the registry of a remote computer Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts