如何使用批处理文件运行php脚本?

时间:2019-04-20 12:20:45

标签: php powershell batch-file

我在logoff.php文件中为注销用户写了一些powershell命令,当我在浏览器中执行代码时,它成功执行,但是当我在批处理文件中传递此文件时,用户没有注销。 请引导我。

logoff.php:

 $sql = mysqli_query($con,"SELECT * FROM rdc_info");

 $mstrng = 

shell_exec("C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe  -ExecutionPolicy Bypass -NoProfile -InputFormat none -command query user < NUL");

//echo $mstrng;

 while($row=mysqli_fetch_assoc($sql)){

     $string = (explode(" ",$mstrng));

     $key = array_search($row['user_name'], $string);

     if($row['user_name']==$string[$key]){

        $userName = $row['user_name'];
        $active_user = shell_exec("C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe  -ExecutionPolicy Bypass -NoProfile -InputFormat none -command query session $userName < NUL");

        $user = substr($active_user,80);

        $array = explode(' ',trim($user));

        $new = array();
        foreach ($array as $item) {

          if (is_numeric($item)) { array_push($new, $item); } 

        }

        $session_id = implode('',$new);

        $len= strlen($session_id);
        for($i =0; $i<$len ; $i++){

            $sssiduser=  $session_id[$i];

           $check = shell_exec("C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe  -ExecutionPolicy Bypass -NoProfile -InputFormat none -command logoff $sssiduser < NUL");
        }

     }   

 }

批处理文件代码:

@echo off
cd\
set path=C:\xampp\php;
cd "C:\xampp\htdocs"
cd "C:\xampp\htdocs\ldap
php logoff.php
exit

0 个答案:

没有答案