Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
VBScript
Const HKEY_LOCAL_MACHINE = &H80000002

strComputer = "."
Set StdOut = WScript.StdOut

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

strKeyPath = "SYSTEM\MountedDevices"

strValueName = "\??\Volume{714ce42f-d2a2-11e4-824f-806e6f6e6963}"
oReg.GetBinaryValue HKEY_LOCAL_MACHINE, strKeyPath, strValueName, strValue
msg = "" 
blank = " " 
For i = lBound( strValue ) to uBound( strValue )
    msg = msg & blank & strValue( i )
Next
StdOut.WriteLine strValueName & blank & msg


It outputs:
\??\Volume{714ce42f-d2a2-11e4-824f-806e6f6e6963}  196 193 54 16 0 0 16 0 0 0 0 0

When I try to do the same in JS, like:
JavaScript
HKLM = 0x80000002;
var strComputer = "."
var oReg=GetObject( "winmgmts:{impersonationLevel=impersonate}!\\\\" +  
    strComputer + "\\root\\default:StdRegProv")
... some lines omitted
var t1, t2, t3 = null, t4, t5;
t1 = "SYSTEM\\MountedDevices"; // path to ( name, values ) pairs
t2 = "\\??\\Volume{714ce42f-d2a2-11e4-824f-806e6f6e6963}"; // name of the value
t4 = oReg.GetBinaryValue( HKLM, t1, t2, t3 );

t3 is null after GetBinaryValue execution. t4 is NUMBER equal to 2, success as I hope :)
Posted
Updated 3-May-15 11:00am
v8

1 solution

Have "translated" by myself:
JavaScript
var strComputer = "."
var oReg = GetObject( "winmgmts:{impersonationLevel=impersonate}!\\\\" +
    strComputer + "\\root\\default:StdRegProv" );
method   = oReg.Methods_.Item( "GetBinaryValue" );
inparams = method.InParameters.SpawnInstance_();
inparams.hDefKey     = 0x80000002;
inparams.sSubKeyName = "SYSTEM\\MountedDevices";
inparams.sValueName  = "\\??\\Volume{714ce42f-d2a2-11e4-824f-806e6f6e6963}";

outparams = oReg.ExecMethod_( method.Name, inparams );// run GetBinaryValue

if ( outparams.ReturnValue == 0 )
{
  t3 = VBArray( outparams.uValue ).toArray();
  t4 = inparams.sValueName;
  for ( var i = 0; i < t3.length; i++ ) t4 += " " + t3[ i ];
  WScript.Echo( t4 );
}

WScript.Quit( 0 );

This code outputs the same as VBS code.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900