Wpc.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. <?php
  2. namespace easyTask;
  3. use \Com as Com;
  4. use \Exception as Exception;
  5. /**
  6. * Class Wpc
  7. * @package easyTask
  8. */
  9. class Wpc
  10. {
  11. /**
  12. * Wpc实例
  13. * @var null
  14. */
  15. private $instance = null;
  16. /**
  17. * Wpc constructor.
  18. * @return $this
  19. */
  20. public function __construct()
  21. {
  22. $this->instance = new Com('Wpc.Core');
  23. return $this;
  24. }
  25. /**
  26. * 获取Com_Variant
  27. * @return Com
  28. */
  29. public function getInstance()
  30. {
  31. return $this->instance;
  32. }
  33. /**
  34. * 设置进程文件
  35. * @param string $filename
  36. * @return $this
  37. * @throws Exception
  38. */
  39. public function setFile($filename)
  40. {
  41. $filename = realpath($filename);
  42. if (!file_exists($filename))
  43. {
  44. throw new Exception("the file:{$filename} is not exist");
  45. }
  46. $this->instance->SetFile($filename);
  47. return $this;
  48. }
  49. /**
  50. * 设置进程域
  51. * @param string $domain
  52. * @return $this
  53. */
  54. public function setDomain($domain)
  55. {
  56. $domain = (string)$domain;
  57. $this->instance->SetDomain($domain);
  58. return $this;
  59. }
  60. /**
  61. * 设置进程参数
  62. * @param string $argument
  63. * @return $this
  64. */
  65. public function setArgument($argument)
  66. {
  67. $argument = (string)$argument;
  68. $this->instance->SetArgument($argument);
  69. return $this;
  70. }
  71. /**
  72. * 设置进程是否带窗口
  73. * @param bool $set
  74. * @return $this
  75. */
  76. public function setNoWindow($set)
  77. {
  78. $set = (bool)$set;
  79. $this->instance->SetNoWindow($set);
  80. return $this;
  81. }
  82. /**
  83. * 设置启动进程的用户
  84. * @param string $username
  85. * @return $this
  86. */
  87. public function setUsername($username)
  88. {
  89. $username = (string)$username;
  90. $this->instance->SetUsername($username);
  91. return $this;
  92. }
  93. /**
  94. * 设置启动进程的密码
  95. * @param string $password
  96. * @return $this
  97. */
  98. public function setPassword($password)
  99. {
  100. $password = (string)$password;
  101. $this->instance->SetPassword($password);
  102. return $this;
  103. }
  104. /**
  105. * 设置进程风格
  106. * @param int $style (0.正常 1.隐藏 2.最小化 3.最大化)
  107. * @return $this
  108. */
  109. public function setStyle($style)
  110. {
  111. $style = (int)$style;
  112. $this->instance->SetStyle($style);
  113. return $this;
  114. }
  115. /**
  116. * 设置进程工作目录
  117. * @param string $path
  118. * @return $this
  119. * @throws Exception
  120. */
  121. public function setWorkDir($path)
  122. {
  123. $path = realpath($path);
  124. if (!is_dir($path))
  125. {
  126. throw new Exception("the path:{$path} is not exist");
  127. }
  128. $this->instance->SetWorkDir($path);
  129. return $this;
  130. }
  131. /**
  132. * 设置等待关联进程退出
  133. * @param int $timeOut 超时时间
  134. * @return $this
  135. * @throws Exception
  136. */
  137. public function setWaitForExit($timeOut = 1024)
  138. {
  139. $timeOut = (int)$timeOut;
  140. $this->instance->SetWaitForExit($timeOut);
  141. return $this;
  142. }
  143. /**
  144. * 获取进程ID
  145. * @return int
  146. */
  147. public function getPid()
  148. {
  149. return $this->instance->GetPid();
  150. }
  151. /**
  152. * 获取进程sessionId
  153. * @return int
  154. */
  155. public function getSessionId()
  156. {
  157. return $this->instance->GetSessionId();
  158. }
  159. /**
  160. * 获取程是否已经退出
  161. * @return bool
  162. */
  163. public function hasExited()
  164. {
  165. return $this->instance->HasExited();
  166. }
  167. /**
  168. * 获取进程名称
  169. * @return string
  170. */
  171. public function getProcessName()
  172. {
  173. return $this->instance->GetProcessName();
  174. }
  175. /**
  176. * 获取进程打开的资源句柄数
  177. * @return int
  178. */
  179. public function getHandleCount()
  180. {
  181. return $this->instance->GetHandleCount();
  182. }
  183. /**
  184. * 获取进程主窗口标题
  185. * @return string
  186. */
  187. public function getMainWindowTitle()
  188. {
  189. return $this->instance->GetMainWindowTitle();
  190. }
  191. /**
  192. * 获取进程启动时间
  193. * @return string
  194. */
  195. public function getStartTime()
  196. {
  197. return $this->instance->GetStartTime();
  198. }
  199. /**
  200. * 获取进程停止时间
  201. * @return string
  202. */
  203. public function getStopTime()
  204. {
  205. return $this->instance->GetStopTime();
  206. }
  207. /**
  208. * 启动进程
  209. * @return int 进程id
  210. */
  211. public function start()
  212. {
  213. return $this->instance->Start();
  214. }
  215. /**
  216. * 停止进程
  217. * @param int $force (1.正常停止 2.强制停止)
  218. */
  219. public function stop($force = 1)
  220. {
  221. $this->instance->Stop($force);
  222. }
  223. }