Bearsampp 2026.9.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 18 of file class.win32ps.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( )

Constructs a Win32Ps instance.

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

30 {
31 }

Member Function Documentation

◆ callWin32Ps()

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 40 of file class.win32ps.php.

41 {
42 $result = false;
43
44 if (function_exists($function)) {
45 $result = @call_user_func($function);
46 }
47
48 return $result;
49 }
$result

References $result.

Referenced by getStatProc().

Here is the caller graph for this function:

◆ exists()

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 129 of file class.win32ps.php.

130 {
131 return self::findByPid($pid) !== false;
132 }
static findByPid($pid)

References findByPid().

Here is the call graph for this function:

◆ findByPath()

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 164 of file class.win32ps.php.

165 {
166 $path = Path::formatUnixPath($path);
167 if (!empty($path) && is_file($path)) {
168 $procs = self::getListProcs();
169 if ($procs !== false) {
170 foreach ($procs as $proc) {
171 $unixExePath = Path::formatUnixPath($proc[self::EXECUTABLE_PATH]);
172 if ($unixExePath == $path) {
173 return $proc;
174 }
175 }
176 }
177 }
178
179 return false;
180 }
$proc
Definition ajax.php:130
static formatUnixPath($path)
static getListProcs()

References $proc, Path\formatUnixPath(), and getListProcs().

Here is the call graph for this function:

◆ findByPid()

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 141 of file class.win32ps.php.

142 {
143 if (!empty($pid)) {
144 $procs = self::getListProcs();
145 if ($procs !== false) {
146 foreach ($procs as $proc) {
147 if ($proc[self::PROCESS_ID] == $pid) {
148 return $proc;
149 }
150 }
151 }
152 }
153
154 return false;
155 }

References $proc, and getListProcs().

Referenced by exists().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getCurrentPid()

getCurrentPid ( )
static

Retrieves the current process ID.

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

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

73 {
74 $procInfo = self::getStatProc();
75
76 return isset($procInfo[self::PROCESS_ID]) ? intval($procInfo[self::PROCESS_ID]) : 0;
77 }
static getStatProc()

References getStatProc().

Referenced by ActionLoading\__construct(), ActionQuit\checkForOrphanedProcesses(), WinBinder\destroyWindow(), ActionLoading\processLoading(), ActionQuit\processWindow(), and ActionQuit\terminatePhpProcesses().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getKeys()

getKeys ( )
static

Retrieves the keys used for process information.

Returns
array An array of keys used for process information.

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

57 {
58 return array(
59 self::NAME,
60 self::PROCESS_ID,
61 self::EXECUTABLE_PATH,
62 self::CAPTION,
63 self::COMMAND_LINE
64 );
65 }

◆ getListProcs()

getListProcs ( )
static

Retrieves a list of running processes.

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

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

85 {
86 $procs = Win32Native::getProcessList(self::getKeys());
87
88 // Filter out processes without ExecutablePath (same behavior as old VBS version)
89 if ($procs !== false && is_array($procs)) {
90 $filtered = array();
91 foreach ($procs as $proc) {
92 if (!empty($proc[self::EXECUTABLE_PATH])) {
93 $filtered[] = $proc;
94 }
95 }
96
97 return $filtered;
98 }
99
100 return $procs;
101 }
static getProcessList($properties=[])

References $proc, and Win32Native\getProcessList().

Referenced by ActionQuit\checkForOrphanedProcesses(), findByPath(), findByPid(), Root\getProcs(), killBins(), and ActionQuit\terminatePhpProcesses().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getStatProc()

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 108 of file class.win32ps.php.

109 {
110 $statProc = self::callWin32Ps('win32_ps_stat_proc');
111
112 if ($statProc !== false) {
113 return array(
114 self::PROCESS_ID => $statProc['pid'],
115 self::EXECUTABLE_PATH => $statProc['exe']
116 );
117 }
118
119 return null;
120 }
static callWin32Ps($function)

References callWin32Ps().

Referenced by getCurrentPid().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ kill()

kill ( $pid)
static

Terminates a process by its PID.

Parameters
int$pidThe process ID to terminate.

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

188 {
189 $pid = intval($pid);
190 if (!empty($pid)) {
192 }
193 }
static killProcess($pid)

References Win32Native\killProcess().

Referenced by ActionLoading\__construct(), ActionQuit\checkForOrphanedProcesses(), killBins(), ActionLoading\processLoading(), Util\stopLoading(), and ActionQuit\terminatePhpProcesses().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ killBins()

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 202 of file class.win32ps.php.

203 {
204 global $bearsamppRoot;
205 $killed = array();
206
207 $procs = $bearsamppRoot->getProcs();
208 if ($refreshProcs || $procs === null) {
209 $procs = self::getListProcs();
210 }
211
212 if ($procs !== false && $procs !== null) {
213 foreach ($procs as $proc) {
214 $unixExePath = Path::formatUnixPath($proc[self::EXECUTABLE_PATH]);
215 $unixCommandPath = Path::formatUnixPath($proc[self::COMMAND_LINE]);
216
217 // Not kill current PID (PHP)
218 if ($proc[self::PROCESS_ID] == self::getCurrentPid()) {
219 continue;
220 }
221
222 // Not kill bearsampp
223 if ($unixExePath == Path::getExeFilePath()) {
224 continue;
225 }
226
227 // Not kill inside www
228 if (UtilString::startWith($unixExePath, Path::getWwwPath() . '/') || UtilString::contains($unixCommandPath, Path::getWwwPath() . '/')) {
229 continue;
230 }
231
232 // Not kill external process
233 if (!UtilString::startWith($unixExePath, Path::getRootPath() . '/') && !UtilString::contains($unixCommandPath, Path::getRootPath() . '/')) {
234 continue;
235 }
236
237 self::kill($proc[self::PROCESS_ID]);
238 $killed[] = $proc;
239 }
240 }
241
242 return $killed;
243 }
global $bearsamppRoot
static getExeFilePath($aetrayPath=false)
static getRootPath($aetrayPath=false)
static getWwwPath($aetrayPath=false)
static contains($string, $search)
static startWith($string, $search)
static kill($pid)

References $bearsamppRoot, $proc, UtilString\contains(), Path\formatUnixPath(), Path\getExeFilePath(), getListProcs(), Path\getRootPath(), Path\getWwwPath(), kill(), and UtilString\startWith().

Referenced by ActionManualRestart\__construct(), Win32Service\delete(), Batch\exitApp(), ServiceHelper\forceKillService(), ActionStartup\killOldInstances(), ActionStartup\prepareService(), ActionQuit\processWindow(), and ActionExt\procReload().

Here is the call graph for this function:
Here is the caller graph for this function:

Field Documentation

◆ CAPTION

const CAPTION = 'Caption'

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

◆ COMMAND_LINE

const COMMAND_LINE = 'CommandLine'

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

◆ EXECUTABLE_PATH

◆ NAME

const NAME = 'Name'

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

◆ PROCESS_ID


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