Bearsampp 2025.8.29
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 109 of file class.win32ps.php.

110 {
111 return self::findByPid($pid) !== false;
112 }
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 142 of file class.win32ps.php.

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

References $proc, Util\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 120 of file class.win32ps.php.

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

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(), WinBinder\destroyWindow(), ActionLoading\processLoading(), ActionQuit\processWindow(), ActionStartup\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 return Vbs::getListProcs(self::getKeys());
82 }
static getListProcs($vbsKeys)

References Vbs\getListProcs().

Referenced by 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 89 of file class.win32ps.php.

90 {
91 $statProc = self::callWin32Ps('win32_ps_stat_proc');
92
93 if ($statProc !== false) {
94 return array(
95 self::PROCESS_ID => $statProc['pid'],
96 self::EXECUTABLE_PATH => $statProc['exe']
97 );
98 }
99
100 return null;
101 }
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 165 of file class.win32ps.php.

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

References Vbs\killProc().

Referenced by 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 179 of file class.win32ps.php.

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

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

Referenced by ActionManualRestart\__construct(), Batch\exitApp(), ActionStartup\installServices(), ActionStartup\killOldInstances(), 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

const EXECUTABLE_PATH = 'ExecutablePath'

◆ NAME

const NAME = 'Name'

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

◆ PROCESS_ID

const PROCESS_ID = 'ProcessID'

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