Bearsampp 2026.5.5
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 ( )

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

27 {
28 }

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

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

References $result.

Referenced by getStatProc().

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

123 {
124 return self::findByPid($pid) !== false;
125 }
static findByPid($pid)

References findByPid().

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

156 {
157 $path = UtilPath::formatUnixPath($path);
158 if (!empty($path) && is_file($path)) {
159 $procs = self::getListProcs();
160 if ($procs !== false) {
161 foreach ($procs as $proc) {
162 $unixExePath = UtilPath::formatUnixPath($proc[self::EXECUTABLE_PATH]);
163 if ($unixExePath == $path) {
164 return $proc;
165 }
166 }
167 }
168 }
169
170 return false;
171 }
$proc
Definition ajax.php:61
static formatUnixPath($path)
static getListProcs()

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

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

134 {
135 if (!empty($pid)) {
136 $procs = self::getListProcs();
137 if ($procs !== false) {
138 foreach ($procs as $proc) {
139 if ($proc[self::PROCESS_ID] == $pid) {
140 return $proc;
141 }
142 }
143 }
144 }
145
146 return false;
147 }

References $proc, and getListProcs().

Referenced by exists().

◆ getCurrentPid()

getCurrentPid ( )
static

Retrieves the current process ID.

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

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

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

References getStatProc().

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

◆ getKeys()

getKeys ( )
static

Retrieves the keys used for process information.

Returns
array An array of keys used for process information.

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

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

◆ getListProcs()

getListProcs ( )
static

Retrieves a list of running processes.

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

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

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

References $proc, and Win32Native\getProcessList().

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

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

103 {
104 $statProc = self::callWin32Ps('win32_ps_stat_proc');
105
106 if ($statProc !== false) {
107 return array(
108 self::PROCESS_ID => $statProc['pid'],
109 self::EXECUTABLE_PATH => $statProc['exe']
110 );
111 }
112
113 return null;
114 }
static callWin32Ps($function)

References callWin32Ps().

Referenced by getCurrentPid().

◆ kill()

kill ( $pid)
static

Terminates a process by its PID.

Parameters
int$pidThe process ID to terminate.

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

179 {
180 $pid = intval($pid);
181 if (!empty($pid)) {
183 }
184 }
static killProcess($pid)

References Win32Native\killProcess().

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

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

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

References $bearsamppRoot, $proc, UtilString\contains(), UtilPath\formatUnixPath(), getListProcs(), kill(), and UtilString\startWith().

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

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: