如何“翻译”从VBS到JS代码? [英] How to "translate" from VBS to JS following code ?

查看:99
本文介绍了如何“翻译”从VBS到JS代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



当我尝试在JS中做同样的事情时,例如:


When I try to do the same in JS, like:

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在GetBinaryValue执行后为空。 t4是NUMBER等于2,我希望成功:)


t3 is null after GetBinaryValue execution. t4 is NUMBER equal to 2, success as I hope :)

推荐答案

自己翻译:

Have "translated" by myself:
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 );



代码输出与VBS代码相同。


This code outputs the same as VBS code.


这篇关于如何“翻译”从VBS到JS代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆