Jump to content

Trouble converting a vbscript


Recommended Posts

  • Moderators

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)

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • Moderators

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.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

  • Moderators

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

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

  • Moderators

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

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

  • Moderators

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

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...