6 Replies - 1359 Views - Last Post: 27 August 2012 - 10:29 AM Rate Topic: -----

#1 Smaxey843  Icon User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 74
  • Joined: 22-November 11

Error : Type mismatch when referencing remote registry.

Posted 17 August 2012 - 11:43 AM

Thank you for your interest.
I am not a programming professional but I am enjoying it, below is an attempt to read a remote registry, remote machine is specified by an inputbox which can be computername or Ip address, and verify a key. later on in the functionality of the project, the key will be used to create a path to begin copying profile data in a computer refresh. I am receiving the error on line 32. it states that there is a type mismatch. I have verified that it is an expanded string on my machine, as well as the target test machine. I have tried also GetStringValue instead, which yields the same error.

Again, any help is appreciated, and thank you.



Option Explicit

dim objWMIService, objRemoteWMIService, objWshNet, objFSO, objAccount, objShell, objReg
dim strComputer, strRemoteComputer, strLIUser, strLIUserSID, strTargetuser, strLIDomain, strpartfilepath, strRegPartProfilePath, strRegProfilePath, strRegKeyPath, strValue, strRegKeyValueName
dim intTest

'Step 1: 
set objWshNet = WScript.CreateObject("WScript.Network")
strLIUser = objWshNet.UserName
strLIDomain = objWshNet.UserDomain
strpartfilepath = "C:\documents and settings\"

strComputer = "." 'inputbox("What is the target computer's ip Address?")
'Wscript.echo strComputer
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objAccount = objWMIService.Get _
    ("Win32_UserAccount.Name='" & strLIUser & "',Domain='" & strLIDomain & "'")
strLIUserSID = objAccount.SID

StrRemoteComputer = inputbox("What is your old computer's IP Address?", "Old PC IP Address")
Set objRemoteWMIService = GetObject("winmgmts:\\" & strRemoteComputer & "\root\default:StdRegProv")

'Test Echo
Wscript.Echo "on computer : " & strComputer &vbnewline & "User : " & strLIUser & vbnewline & " SID : "& strLIUserSID 

set objFSO = CreateObject("Scripting.FileSystemObject")

Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strRemoteComputer & "\root\default:StdRegProv")
strRegKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\" & strLIUserSID
strRegkeyValueName = "ProfileImagePath"
objReg.GetExpandedStringValue "HKEY_LOCAL_MACHINE",strRegKeyPath,strRegKeyValueName,strValue
wscript.echo "in the case of "&strLIUser& " on " & strRemoteComputer & vbnewline &_
	"The key path is : " & strRegKeyPath & vbnewline &_
	"the key value name is :" & strRegKeyValueName & vbnewline &_
	"the key value is :" & strValue

'WScript.Echo "Registry key path: " & strRegKeyPath & vbnewline & "Key Value: " &strRegProfilePath' check this against your profile lsit sid location and verify data
wscript.echo "End of File"



Is This A Good Question/Topic? 0
  • +

Replies To: Error : Type mismatch when referencing remote registry.

#2 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 299
  • View blog
  • Posts: 1,768
  • Joined: 26-March 09

Re: Error : Type mismatch when referencing remote registry.

Posted 18 August 2012 - 01:36 AM

Just to clarify, your error is with line 32 shown below as per the code tag lines?

32 wscript.echo "in the case of "&strLIUser& " on " & strRemoteComputer & vbnewline &_
    "The key path is : " & strRegKeyPath & vbnewline &_
    "the key value name is :" & strRegKeyValueName & vbnewline &_
    "the key value is :" & strValue



If so, a couple of suggestions.

1. Declare your datatypes, at the moment, everything appears declared as a variant.
2. Try putting spaces between the ampersands and variables

Have you checked what variables are populated with using the immediate or locals window?

This post has been edited by maj3091: 18 August 2012 - 01:36 AM

Was This Post Helpful? 0
  • +
  • -

#3 Smaxey843  Icon User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 74
  • Joined: 22-November 11

Re: Error : Type mismatch when referencing remote registry.

Posted 20 August 2012 - 08:22 AM

View Postmaj3091, on 18 August 2012 - 04:36 AM, said:

Just to clarify, your error is with line 32 shown below as per the code tag lines?

32 wscript.echo "in the case of "&strLIUser& " on " & strRemoteComputer & vbnewline &_
    "The key path is : " & strRegKeyPath & vbnewline &_
    "the key value name is :" & strRegKeyValueName & vbnewline &_
    "the key value is :" & strValue



If so, a couple of suggestions.

1. Declare your datatypes, at the moment, everything appears declared as a variant.
2. Try putting spaces between the ampersands and variables

Have you checked what variables are populated with using the immediate or locals window?


Maj, thanks for your reply.
I was incorrect, it is line 31 in which there is a type match failure.

Option Explicit

dim objWMIService, objRemoteWMIService, objWshNet, objFSO, objAccount, objShell, objReg
dim strComputer, strRemoteComputer, strLIUser, strLIUserSID, strTargetuser, strLIDomain, strpartfilepath, strRegPartProfilePath, strRegProfilePath, strRegKeyPath, strValue, strRegKeyValueName
dim intTest

'Step 1: 
set objWshNet = WScript.CreateObject("WScript.Network")
strLIUser = objWshNet.UserName
strLIDomain = objWshNet.UserDomain
strpartfilepath = "C:\documents and settings\"

strComputer = "." 'inputbox("What is the target computer's ip Address?")
'Wscript.echo strComputer
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objAccount = objWMIService.Get _
    ("Win32_UserAccount.Name='" & strLIUser & "',Domain='" & strLIDomain & "'")
strLIUserSID = objAccount.SID

StrRemoteComputer = inputbox("What is your old computer's IP Address?", "Old PC IP Address")
Set objRemoteWMIService = GetObject("winmgmts:\\" & strRemoteComputer & "\root\default:StdRegProv")

'Test Echo
Wscript.Echo "on computer : " & strComputer &vbnewline & "User : " & strLIUser & vbnewline & " SID : "& strLIUserSID 

set objFSO = CreateObject("Scripting.FileSystemObject")

Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strRemoteComputer & "\root\default:StdRegProv")
strRegKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\" & strLIUserSID
strRegkeyValueName = "ProfileImagePath"
objReg.GetExpandedStringValue "HKEY_LOCAL_MACHINE",strRegKeyPath,strRegKeyValueName,strValue
wscript.echo "in the case of "&strLIUser& " on " & strRemoteComputer & vbnewline &_
	"The key path is : " & strRegKeyPath & vbnewline &_
	"the key value name is :" & strRegKeyValueName & vbnewline &_
	"the key value is :" & strValue

'WScript.Echo "Registry key path: " & strRegKeyPath & vbnewline & "Key Value: " &strRegProfilePath' check this against your profile lsit sid location and verify data
wscript.echo "End of File"



I will clean up the spacing and ampersands to make it a little more readable. I do not know how to check what a variable is populated with at a given time. I am currently coding using Notepad++ is there a more suitable tool for debugging VBScript?
Thanks again,
Steven

This post has been edited by Smaxey843: 20 August 2012 - 08:24 AM

Was This Post Helpful? 0
  • +
  • -

#4 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 299
  • View blog
  • Posts: 1,768
  • Joined: 26-March 09

Re: Error : Type mismatch when referencing remote registry.

Posted 20 August 2012 - 08:29 AM

Apologies, I just assumed you where using the VB IDE.

Only way I can think off, would be to write them to screen using a messagebox (assuming that's available in VBScript)
Was This Post Helpful? 0
  • +
  • -

#5 Smaxey843  Icon User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 74
  • Joined: 22-November 11

Re: Error : Type mismatch when referencing remote registry.

Posted 20 August 2012 - 01:16 PM

Maj,
again thanks,

Option Explicit

dim objWMIService, objRemoteWMIService, objWshNet, objFSO, objAccount, objShell, objReg
dim strComputer, strRemoteComputer, strLIUser, strLIUserSID, strTargetuser, strLIDomain, strpartfilepath, strRegPartProfilePath, strRegProfilePath, strRegKeyPath, strValue, strRegKeyValueName
dim intTest

'Step 1: 
set objWshNet = WScript.CreateObject("WScript.Network")
strLIUser = objWshNet.UserName
strLIDomain = objWshNet.UserDomain
strpartfilepath = "C:\documents and settings\"

strComputer = "." 'inputbox("What is the target computer's ip Address?")
'Wscript.echo strComputer
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objAccount = objWMIService.Get _
    ("Win32_UserAccount.Name='" & strLIUser & "',Domain='" & strLIDomain & "'")
strLIUserSID = objAccount.SID

StrRemoteComputer = inputbox("What is your old computer's IP Address?", "Old PC IP Address")
Set objRemoteWMIService = GetObject("winmgmts:\\" & strRemoteComputer & "\root\default:StdRegProv")

'Test Echo
Wscript.Echo "on computer : " & strComputer &vbnewline & "User : " & strLIUser & vbnewline & " SID : "& strLIUserSID 

set objFSO = CreateObject("Scripting.FileSystemObject")

Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strRemoteComputer & "\root\default:StdRegProv")
strRegKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\" & strLIUserSID
strRegkeyValueName = "ProfileImagePath"
wscript.echo "reg read verification " & vbnewline & "HKEY_LOCAL_MACHINE" & vbnewline & _
	"The key path is : " & strRegKeyPath & vbnewline &_
	"the key value name is :" & strRegKeyValueName & vbnewline &_
	"the key value is :" & strValue
	
objReg.GetExpandedStringValue "HKEY_LOCAL_MACHINE",strRegKeyPath,strRegKeyValueName,strValue
wscript.echo "in the case of "&strLIUser& " on " & strRemoteComputer & vbnewline &_
	"The key path is : " & strRegKeyPath & vbnewline &_
	"the key value name is :" & strRegKeyValueName & vbnewline &_
	"the key value is :" & strValue

'WScript.Echo "Registry key path: " & strRegKeyPath & vbnewline & "Key Value: " &strRegProfilePath' check this against your profile lsit sid location and verify data
wscript.echo "End of File"


The error has moved to line 36, which is

objReg.GetExpandedStringValue "HKEY_LOCAL_MACHINE",strRegKeyPath,strRegKeyValueName,strValue




the strValue is blank, the other data checks out as what I have intended.

I am a little baffled. I may be missing something that someone with formal training might know whats what. Thanks for looking through it again.
Steven
Was This Post Helpful? 0
  • +
  • -

#6 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 299
  • View blog
  • Posts: 1,768
  • Joined: 26-March 09

Re: Error : Type mismatch when referencing remote registry.

Posted 20 August 2012 - 03:09 PM

Have a look at this link, see if it sheds any light.

I'm not that clued up with what you're trying to do, but this link looked like something similar.
Was This Post Helpful? 0
  • +
  • -

#7 Smaxey843  Icon User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 74
  • Joined: 22-November 11

Re: Error : Type mismatch when referencing remote registry.

Posted 27 August 2012 - 10:29 AM

Maj!
Thats awesome! In previous hack and slashes through unknown territory I had read that very post about profiles! Thank you for your patience and after rereading the thread I realized i never clearly declared what I was trying to accomplish.

I need to find out what the user path is for a user on a specified computer

the issue with this is that during a migration. half of the network ID's were one convention and the other half another. The folks in charge of the migration took the easy route and did not recreate profiles that comply with their naming convention. So we have usernames of jsmith and the path could be %systemdrive%\documents and settings\smithj OR e01234

So, the need to use the SID to determine a user's profile path on a remote computer was born. I got it to work, its an ugly little duck but it works to demonstrate the concept. whether or not to use this process will be decided beyond my pay grade. I need to get a rubber duck.

code below incase this helps someone in the future :

Option Explicit

dim objWMIService, objRemoteWMIService, objWshNet, objFSO, objAccount, objShell, objReg, objSubkey
dim strComputer, strRemoteComputer, strLIUser, strLIUserSID, strTargetuser, strLIDomain, strpartfilepath, strRegPartProfilePath, strRegProfilePath, strRegKeyPath, strValue, strRegKeyValueName,  strRegSubKeyPath
dim intTest
dim arrSubkeys

Const HKEY_LOCAL_MACHINE = &H80000002

'notify user that the script is executing
Wscript.echo "Do not use this utility without the close attention of " & vbnewline &_
"the assistance of HUSA/SUSA Technical support staff"

'Step 1: Obtain currently logged on user's information.
set objWshNet = WScript.CreateObject("WScript.Network")
strLIUser = objWshNet.UserName
strLIDomain = objWshNet.UserDomain
strpartfilepath = "C:\documents and settings\"

'Step 2: Using information gathered in step one, determine the SID of the user 
strComputer = "." 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objAccount = objWMIService.Get _
    ("Win32_UserAccount.Name='" & strLIUser & "',Domain='" & strLIDomain & "'")
strLIUserSID = objAccount.SID

'Test Echo to display logged on domain user's SID
Wscript.Echo "on computer : " & strComputer &vbnewline & "User : " & strLIUser & vbnewline & " SID : "& strLIUserSID 

'Step 3: Query the user for the address of the old computer's IP Address.
StrRemoteComputer = inputbox("What is your old computer's IP Address?", "Old PC IP Address")

'Step 4: Connect to remote registry
Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
	strRemoteComputer & "\root\default:StdRegProv")

'Initialize and define registry variables.
strRegKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\" 
strRegkeyValueName = "ProfileImagePath"
strRegsubkeypath = strRegKeyPath & "\" & strLIUserSID

'Step 5: Querty remote registry for specified keys, collect keys into array, search array for the specific keypath including currently logged on user's SID to find the user's path on that machine. 
objreg.EnumKey HKEY_LOCAL_MACHINE,strRegKeyPath,ArrSubkeys
objReg.GetExpandedStringValue HKEY_LOCAL_MACHINE,strRegsubKeyPath,strRegKeyValueName,strValue
'Test Echo
'wscript.echo " *** " &strRegSubKeypath &vbnewline & " *** " & strregkeyvaluename & vbnewline & " *** " & strValue
	
'Echo to report findings of this script.
wscript.echo "in the case of "&strLIUser& " on " & strRemoteComputer & vbnewline &_
	"The key path is : " & strRegKeyPath & vbnewline &_
	"the key value name is : " & strRegKeyValueName & vbnewline &_
	"the key value is : " & strValue

wscript.echo "End of File"


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1