2024.8.23
Loading...
Searching...
No Matches
Win32Ps Class Reference

Public Member Functions

 __construct ()
 

Static Public Member Functions

static exists ($pid)
 
static findByPath ($path)
 
static findByPid ($pid)
 
static getCurrentPid ()
 
static getKeys ()
 
static getListProcs ()
 
static getStatProc ()
 
static kill ($pid)
 
static killBins ($refreshProcs=false)
 

Data Fields

const CAPTION = 'Caption'
 
const COMMAND_LINE = 'CommandLine'
 
const EXECUTABLE_PATH = 'ExecutablePath'
 
const NAME = 'Name'
 
const PROCESS_ID = 'ProcessID'
 

Static Private Member Functions

static callWin32Ps ($function)
 

Detailed Description

Class Win32Ps

This class provides various utility functions for interacting with Windows processes. It includes methods for retrieving process information, checking process existence, finding processes by PID or path, and terminating processes.

Definition at line 17 of file class.win32ps.php.

Constructor & Destructor Documentation

◆ __construct()

Win32Ps::__construct ( )

Definition at line 25 of file class.win32ps.php.

26 {
27 }

Member Function Documentation

◆ callWin32Ps()

static Win32Ps::callWin32Ps ( $function)
staticprivate

Calls a specified function if it exists.

Parameters
string$functionThe name of the function to call.
Returns
mixed The result of the function call, or false if the function does not exist.

Definition at line 35 of file class.win32ps.php.

36 {
37 $result = false;
38
39 if (function_exists($function)) {
40 $result = @call_user_func($function);
41 }
42
43 return $result;
44 }
$result

References $result.

Referenced by getStatProc().

+ Here is the caller graph for this function:

◆ exists()

static Win32Ps::exists ( $pid)
static

Checks if a process with the specified PID exists.

Parameters
int$pidThe process ID to check.
Returns
bool True if the process exists, false otherwise.

Definition at line 108 of file class.win32ps.php.

109 {
110 return self::findByPid($pid) !== false;
111 }
static findByPid($pid)

References findByPid().

◆ findByPath()

static Win32Ps::findByPath ( $path)
static

Finds a process by its executable path.

Parameters
string$pathThe path to the executable.
Returns
array|false An array of process information, or false if not found.

Definition at line 141 of file class.win32ps.php.

142 {
143 $path = Util::formatUnixPath($path);
144 if (!empty($path) && is_file($path)) {
146 if ($procs !== false) {
147 foreach ($procs as $proc) {
148 $unixExePath = Util::formatUnixPath($proc[self::EXECUTABLE_PATH]);
149 if ($unixExePath == $path) {
150 return $proc;
151 }
152 }
153 }
154 }
155
156 return false;
157 }
$proc
Definition ajax.php:43
$procs
Definition ajax.php:19
static formatUnixPath($path)
static getListProcs()

References $proc, $procs, Util\formatUnixPath(), and getListProcs().

◆ findByPid()

static Win32Ps::findByPid ( $pid)
static

Finds a process by its PID.

Parameters
int$pidThe process ID to find.
Returns
array|false An array of process information, or false if not found.

Definition at line 119 of file class.win32ps.php.

120 {
121 if (!empty($pid)) {
123 if ($procs !== false) {
124 foreach ($procs as $proc) {
125 if ($proc[self::PROCESS_ID] == $pid) {
126 return $proc;
127 }
128 }
129 }
130 }
131
132 return false;
133 }

References $proc, $procs, and getListProcs().

Referenced by exists().

+ Here is the caller graph for this function:

◆ getCurrentPid()

static Win32Ps::getCurrentPid ( )
static

Retrieves the current process ID.

Returns
int The current process ID, or 0 if not found.

Definition at line 67 of file class.win32ps.php.

68 {
69 $procInfo = self::getStatProc();
70 return isset($procInfo[self::PROCESS_ID]) ? intval($procInfo[self::PROCESS_ID]) : 0;
71 }
static getStatProc()

References getStatProc().

Referenced by ActionLoading\__construct(), and ActionLoading\processLoading().

+ Here is the caller graph for this function:

◆ getKeys()

static Win32Ps::getKeys ( )
static

Retrieves the keys used for process information.

Returns
array An array of keys used for process information.

Definition at line 51 of file class.win32ps.php.

52 {
53 return array(
54 self::NAME,
55 self::PROCESS_ID,
56 self::EXECUTABLE_PATH,
57 self::CAPTION,
58 self::COMMAND_LINE
59 );
60 }

◆ getListProcs()

static Win32Ps::getListProcs ( )
static

Retrieves a list of running processes.

Returns
array|false An array of process information, or false on failure.

Definition at line 78 of file class.win32ps.php.

79 {
80 return Vbs::getListProcs(self::getKeys());
81 }
static getListProcs($vbsKeys)

References Vbs\getListProcs().

Referenced by findByPath(), findByPid(), killBins(), and Root\register().

+ Here is the caller graph for this function:

◆ getStatProc()

static Win32Ps::getStatProc ( )
static

Retrieves the status of the current process.

Returns
array|null An array containing the process ID and executable path, or null on failure.

Definition at line 88 of file class.win32ps.php.

89 {
90 $statProc = self::callWin32Ps('win32_ps_stat_proc');
91
92 if ($statProc !== false) {
93 return array(
94 self::PROCESS_ID => $statProc['pid'],
95 self::EXECUTABLE_PATH => $statProc['exe']
96 );
97 }
98
99 return null;
100 }
static callWin32Ps($function)

References callWin32Ps().

Referenced by getCurrentPid().

+ Here is the caller graph for this function:

◆ kill()

static Win32Ps::kill ( $pid)
static

Terminates a process by its PID.

Parameters
int$pidThe process ID to terminate.

Definition at line 164 of file class.win32ps.php.

165 {
166 $pid = intval($pid);
167 if (!empty($pid)) {
168 Vbs::killProc($pid);
169 }
170 }
static killProc($pid)

References Vbs\killProc().

Referenced by killBins(), ActionLoading\processLoading(), and Util\stopLoading().

+ Here is the caller graph for this function:

◆ killBins()

static Win32Ps::killBins ( $refreshProcs = false)
static

Terminates all Bearsampp-related processes except the current one.

Parameters
bool$refreshProcsWhether to refresh the list of processes before terminating.
Returns
array An array of terminated processes.

Definition at line 178 of file class.win32ps.php.

179 {
180 global $bearsamppRoot;
181 $killed = array();
182
183 $procs = $bearsamppRoot->getProcs();
184 if ($refreshProcs) {
186 }
187
188 if ($procs !== false) {
189 foreach ($procs as $proc) {
190 $unixExePath = Util::formatUnixPath($proc[self::EXECUTABLE_PATH]);
191 $unixCommandPath = Util::formatUnixPath($proc[self::COMMAND_LINE]);
192
193 // Not kill current PID (PHP)
194 if ($proc[self::PROCESS_ID] == self::getCurrentPid()) {
195 continue;
196 }
197
198 // Not kill bearsampp
199 if ($unixExePath == $bearsamppRoot->getExeFilePath()) {
200 continue;
201 }
202
203 // Not kill inside www
204 if (Util::startWith($unixExePath, $bearsamppRoot->getWwwPath() . '/') || Util::contains($unixCommandPath, $bearsamppRoot->getWwwPath() . '/')) {
205 continue;
206 }
207
208 // Not kill external process
209 if (!Util::startWith($unixExePath, $bearsamppRoot->getRootPath() . '/') && !Util::contains($unixCommandPath, $bearsamppRoot->getRootPath() . '/')) {
210 continue;
211 }
212
213 self::kill($proc[self::PROCESS_ID]);
214 $killed[] = $proc;
215 }
216 }
217
218 return $killed;
219 }
global $bearsamppRoot
static startWith($string, $search)
static contains($string, $search)
static kill($pid)

References $bearsamppRoot, $proc, $procs, Util\contains(), Util\formatUnixPath(), getListProcs(), kill(), and Util\startWith().

Referenced by ActionManualRestart\__construct(), Batch\exitApp(), ActionStartup\killOldInstances(), ActionQuit\processWindow(), and ActionExt\procReload().

+ Here is the caller graph for this function:

Field Documentation

◆ CAPTION

const Win32Ps::CAPTION = 'Caption'

Definition at line 22 of file class.win32ps.php.

◆ COMMAND_LINE

const Win32Ps::COMMAND_LINE = 'CommandLine'

Definition at line 23 of file class.win32ps.php.

◆ EXECUTABLE_PATH

const Win32Ps::EXECUTABLE_PATH = 'ExecutablePath'

◆ NAME

const Win32Ps::NAME = 'Name'

Definition at line 19 of file class.win32ps.php.

◆ PROCESS_ID

const Win32Ps::PROCESS_ID = 'ProcessID'

The documentation for this class was generated from the following file: