Sign in to follow this  
Followers 0
JLogan3o13

Trouble converting a vbscript

10 posts in this topic

This should be a simple thing; I think I have been staring at it too long. I'm looking to query a registry key through WMI on a number remote machines because some genius disabled Remote Registry. I have the following in vbscript format that works just fine:

const HKEY_LOCAL_MACHINE = &H80000002
dim filesys, filetxt
Set filesys = CreateObject("Scripting.FileSystemObject")
strPC = "MNCS00258"

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strPC & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{5B21A1C6-5F55-480F-816E-C307C1E97293}"
strValueName = "DisplayVersion"
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue

msgbox(strValue)

This should be a simple conversion, but I am getting hung up on the strValue. I have tried a number of different ways but am unsure how to capture the value. Any assistance would be appreciated.

$HKLM = "&H80000002"
$filesys = ObjCreate("Scripting.FileSystemObject")
$PC = "MNCS00258"
$oReg = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $PC & "\root\default:StdRegProv")
$Path = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{5B21A1C6-5F55-480F-816E-C307C1E97293}"
$ValName = "DisplayVersion"

   $oReg.GetStringValue($HKLM, $Path, $ValName, strValue) ;<--Unsure what this should be
   MsgBox(0, "", strValue)

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Anyone of these I imagine:

Const REG_SZ = 1
Const REG_EXPAND_SZ = 2
Const REG_BINARY = 3
Const REG_DWORD = 4
Const REG_MULTI_SZ = 7

I don't know if you need the numeric or string value though.

edit: I based it on this article but on second look was a bit hasty and I'm wrong. It looks like the variable is passed as a reference like ByRef:

Global $strValue
$oReg.GetStringValue($HKLM, $Path, $ValName, $strValue)
MsgBox(0, " strValue ", $strValue)
Edited by dany

[center]Spiderskank Spiderskank[/center]GetOpt Parse command line options UDF | AU3Text Program internationalization UDF | Identicon visual hash UDF

Share this post


Link to post
Share on other sites

I'm looking to get the string value, as it is a REG_SZ. Curious that I do not need to specify the type in a vbscript.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

Could you try this (untested) code?

$HKLM = 0x80000002
$filesys = ObjCreate("Scripting.FileSystemObject")
$PC = "MNCS00258"
$oReg = ObjGet("winmgmts:{impersonationLevel=impersonate}!" & $PC & "rootdefault:StdRegProv")
$Path = "SOFTWAREMicrosoftWindowsCurrentVersionUninstall{5B21A1C6-5F55-480F-816E-C307C1E97293}"
$ValName = "DisplayVersion"

$sResult = $oReg.GetStringValue($HKLM, $Path, $ValName)
MsgBox(0, "", $sResult)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I should have refreshed :)

Edited by dany

[center]Spiderskank Spiderskank[/center]GetOpt Parse command line options UDF | AU3Text Program internationalization UDF | Identicon visual hash UDF

Share this post


Link to post
Share on other sites

It returns 0, so I would guess it is getting to the point of the ValName ok


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

This works for me. If you run a 64 bit Windows you need to run the script as 64 bit.

#AutoIt3Wrapper_UseX64=y
$HKLM = 0x80000002
$filesys = ObjCreate("Scripting.FileSystemObject")
$PC = "." ; C0548"
$oReg = ObjGet("winmgmts:{impersonationLevel=impersonate}!" & $PC & "rootdefault:StdRegProv")
$Path = "SOFTWAREMicrosoftWindowsCurrentVersionUninstall{5B21A1C6-5F55-480F-816E-C307C1E97293}"
$ValName = "DisplayVersion"

Global $iResult, $sResult = ""
$iResult = $oReg.GetStringValue($HKLM, $Path, $ValName, $sResult)
MsgBox(0, "", ">" & $iResult & "-" & $sResult & "<")

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Hi, Water, thanks for the assistance. It's odd. The output for this particular value should be 4.6.105.68. My return from your script above is >2-<. I am running from a 64bit machine, but touching a 32bit machine remotely. I tried running the script both ways and receive the same return.

I guess I'm mostly curious how vbscript automatically "knows" how to deal with the strValue; it isn't something declared in the script. Not sure how strValue maps to the object we're looking for.

Again, thanks for the help and suggestions; I'm going to keep playing with it.

Edit: Ok, I'm a blooming idiot. Sorry, I failed to notice you took the PC name out of there. It is working as you said. Many thanks.

Edited by JLogan3o13

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

So to summarize... your mistake was (except not declaring strValue)

$HKLM = "&H80000002"

I've seen you doing that before. AutoIt's hex represented number is

0x...

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

Thanks for pointing it out to me, I will definitely keep it in mind in the future.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0