开发者

When tried to run following PHP script gives error on Windows 7

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


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)));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜