此脚本出现 Microsoft JScript 运行时错误:If (out_params.bGranted) 行上预期的对象。这似乎与语法错误有关,但我找不到它。这段代码,以其当前的形式,基本上是从带有 `out` 参数的调用函数中复制而来的,在 JScript 中通过引用传递参数。
function main()
{
var provider_name = "StdRegProv";
var func_name = "CheckAccess";
var services = GetObject("winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\default"); // connect to WMI
var registry = services.Get(provider_name); // get provider
var in_params = registry.Methods_(func_name).InParameters.SpawnInstance_();
in_params.hDefKey = 0x80000001;
in_params.sSubKeyName = "Software\\Microsoft\\Shared Tools\\Proofing Tools\\1.0\\Override";
in_params.uRequired = 65536;
var out_params = services.ExecMethod(provider_name, func_name, in_params);
If (out_params.bGranted)
{
WScript.Echo("Has DELETE Access Rights on HKCU " + strKeyPath);
registry.DeleteKey (HKCU, strKeyPath);
}
Else
{
WScript.Echo("No DELETE Access Rights on HKCU " + strKeyPath);
}
}
main();