JScript 中的 StdRegProv .CheckAccess 方法 - 错误:需要对象

发布于 2024-11-27 11:35:52 字数 1123 浏览 1 评论 0原文

此脚本收到 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();

This script is getting Microsoft JScript runtime error: Object expected on If (out_params.bGranted) line. It seems like this is related to a syntax error, but I can't find it. This code, in its current form, was basically copied from Invoking functions with `out` arguments, passing arguments by reference in 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();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怪我入戏太深 2024-12-04 11:35:52

在 JScript 中,关键字(和标识符)区分大小写,因此不能使用 If 代替 ifElse 代替 else,等等。

在您的示例中,脚本引擎将 If (out_params.bGranted) 解释为函数调用,这会导致运行时错误,因为您显然没有定义 If 函数。

In JScript, keywords (and identifiers) are case-sensitive, so you cannot use If instead of if, Elseinstead of else, and so on.

In your example the script engine interprets If (out_params.bGranted) as a function call, which results in a runtime error since you obviously did not defined an If function.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文