作者aeolus0829 (archer)
看板PHP
标题Re: [请益] php能执行bat档吗
时间Thu Sep 9 10:06:02 2010
※ 引述《davidou (老欧 ! 月夜雪岚)》之铭言:
: 我想写一个自动关机的网页
: 所以应该会写一个bat档
: 我想问 php有办法去执行那个.bat的档案吗
: 假设可以另外还有个问题就是
: 我要是在别台电脑 开了这个网页
: 那被关机的电脑 应该是sever那台电脑是吧..
: 这方面似乎没甚麽涉略 不太知道该怎下手....
没有实作过,查了一下手册
http://php.net/manual/en/function.system.php
// Outputs all the result of shellcommand "ls", and returns
// the last output line into $last_line. Stores the return value
// of the shell command in $retval.
$last_line = system('ls', $retval);
上述的范例会将 shell 底下 ls 的命令输出结果回传到 $last_line
所以合理推测,可以用这样的方式去呼叫 .bat 档
system('<path_to_bat>')
如果可以成功呼叫 bat 档,那接下来就是蛋糕一块了
bat 内容:
psshutdown \\<server_ip> -t 600 -f -s [-u xxx -p xxx]
参数说明:
-t 600 设定时间,600秒
-f 强制
-s 关机
注:你必须有管理者权限,必要时必须撘配以下两个参数:
-u 帐号
-p 密码
psshutdown 是工具程式,这边可以下载
http://technet.microsoft.com/en-us/sysinternals/bb897541.aspx
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 61.218.139.174
1F:→ junktw:psshutdown 和 shutdown 有什麽差别 09/10 22:18