当尝试在 Windows 7 上运行以下 PHP 脚本时出现错误

发布于 2024-10-08 21:31:33 字数 1213 浏览 4 评论 0原文

if (strlen($log) > 0)
{
    // Use "WScript.Shell" to run the command with no command prompt window pop up.
    $wShell = new COM("WScript.Shell"); 
    $cmd = "cmd /c cscript.exe \"%DIR%\\bin\\eventquery.vbs\" /l \"" . $log . "\" > \"%DIR%\\Temp\\event.log\" 2>&1";
    ////echo $cmd;
    $return = $wShell->Run($cmd, 0, true);
    if ($return == 0 || $return ==254)
    {
        $handle = @fopen(getenv('DIR') . "\\Temp\\event.log", "r");
        if ($handle)
        {
            $linenum = 1;
            while (!feof($handle))
            {
                $buffer = fgets($handle);
                // Skip the first three lines
                if ($linenum > 3)
                {
                    echo $buffer;
                }

                $linenum++;
            }

            fclose($handle);
        }
    }
    else
    {
        echo "Error running \"" . $cmd . "\" command."; 
    }
}

在 windows 7 上出现错误:

错误:无法包含通用模块“CmdLib.Wsc”

当我尝试从命令行@ windows 7 运行它时,它工作正常:

cscript.exe \"%DIR%\\bin\\eventquery.vbs\" /l \"" . $log . "\" > \"%DIR%\\Temp\\event.log\" 2>&1
if (strlen($log) > 0)
{
    // Use "WScript.Shell" to run the command with no command prompt window pop up.
    $wShell = new COM("WScript.Shell"); 
    $cmd = "cmd /c cscript.exe \"%DIR%\\bin\\eventquery.vbs\" /l \"" . $log . "\" > \"%DIR%\\Temp\\event.log\" 2>&1";
    ////echo $cmd;
    $return = $wShell->Run($cmd, 0, true);
    if ($return == 0 || $return ==254)
    {
        $handle = @fopen(getenv('DIR') . "\\Temp\\event.log", "r");
        if ($handle)
        {
            $linenum = 1;
            while (!feof($handle))
            {
                $buffer = fgets($handle);
                // Skip the first three lines
                if ($linenum > 3)
                {
                    echo $buffer;
                }

                $linenum++;
            }

            fclose($handle);
        }
    }
    else
    {
        echo "Error running \"" . $cmd . "\" command."; 
    }
}

It gives an error on windows 7:

ERROR: Unable to include the common module"CmdLib.Wsc"

When I try run it from command line@ windows 7, it works fine:

cscript.exe \"%DIR%\\bin\\eventquery.vbs\" /l \"" . $log . "\" > \"%DIR%\\Temp\\event.log\" 2>&1

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

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

发布评论

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

评论(2

困倦 2024-10-15 21:31:33

尝试使用 escapeshellarg

$cmd = "cmd /c cscript.exe \"%DIR%\\bin\\eventquery.vbs\" /l \"" . escapeshellarg($log) . "\" > \"%DIR%\\Temp\\event.log\" 2>&1";

我的猜测是你有$log 中的 shell 元字符。`

Try using escapeshellarg:

$cmd = "cmd /c cscript.exe \"%DIR%\\bin\\eventquery.vbs\" /l \"" . escapeshellarg($log) . "\" > \"%DIR%\\Temp\\event.log\" 2>&1";

My guess is that you have shell metacharacters in $log.`

$a = 'all';
file_put_contents('ip.txt',shell_exec($dump = sprintf('ipconfig /%s',$a)));
$a = 'all';
file_put_contents('ip.txt',shell_exec($dump = sprintf('ipconfig /%s',$a)));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文