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

Public Member Functions

 __construct ()
 

Static Public Member Functions

static countFilesFolders ($path)
 
static createShortcut ($savePath)
 
static exec ($basename, $resultFile, $content, $timeout=true)
 
static getDefaultBrowser ()
 
static getInstalledBrowsers ()
 
static getListProcs ($vbsKeys)
 
static getResultFile ($basename)
 
static getServiceInfos ($serviceName)
 
static getStartupPath ($file=null)
 
static getTmpFile ($ext, $customName=null)
 
static killProc ($pid)
 

Data Fields

const ALL_DESKTOP_PATH = 'objShell.SpecialFolders("AllUsersDesktop")'
 
const ALL_STARTUP_PATH = 'objShell.SpecialFolders("AllUsersStartup")'
 
const DESKTOP_PATH = 'objShell.SpecialFolders("Desktop")'
 
const END_PROCESS_STR = 'FINISHED!'
 
const STARTUP_PATH = 'objShell.SpecialFolders("Startup")'
 
const STR_SEPARATOR = ' || '
 

Static Private Member Functions

static getSpecialPath ($path)
 
static writeLog ($log)
 

Detailed Description

Class Vbs

This class provides various utility functions for interacting with the Windows operating system using VBScript. It includes methods for counting files and folders, retrieving default and installed browsers, managing processes, and creating shortcuts.

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

Constructor & Destructor Documentation

◆ __construct()

Vbs::__construct ( )

Definition at line 27 of file class.vbs.php.

28 {
29 }

Member Function Documentation

◆ countFilesFolders()

static Vbs::countFilesFolders ( $path)
static

Counts the number of files and folders in the specified path.

Parameters
string$pathThe path to count files and folders in.
Returns
int|false The count of files and folders, or false on failure.

Definition at line 49 of file class.vbs.php.

50 {
51 $basename = 'countFilesFolders';
52 $resultFile = self::getResultFile( $basename );
53
54 $content = 'Dim objFso, objResultFile, objCheckFile' . PHP_EOL . PHP_EOL;
55 $content .= 'Set objFso = CreateObject("scripting.filesystemobject")' . PHP_EOL;
56 $content .= 'Set objResultFile = objFso.CreateTextFile("' . $resultFile . '", True)' . PHP_EOL;
57 $content .= 'count = 0' . PHP_EOL;
58 $content .= 'CountFiles("' . $path . '")' . PHP_EOL . PHP_EOL;
59 $content .= 'Function CountFiles(ByVal path)' . PHP_EOL;
60 $content .= ' Dim parentFld, subFld' . PHP_EOL;
61 $content .= ' Set parentFld = objFso.GetFolder(path)' . PHP_EOL . PHP_EOL;
62 $content .= ' count = count + parentFld.Files.Count + parentFld.SubFolders.Count' . PHP_EOL;
63 $content .= ' For Each subFld In parentFld.SubFolders' . PHP_EOL;
64 $content .= ' count = count + CountFiles(subFld.Path)' . PHP_EOL;
65 $content .= ' Next' . PHP_EOL . PHP_EOL;
66 $content .= 'End Function' . PHP_EOL . PHP_EOL;
67 $content .= 'objResultFile.Write count' . PHP_EOL;
68 $content .= 'objResultFile.Close' . PHP_EOL;
69
70 $result = self::exec( $basename, $resultFile, $content );
71
72 return isset( $result[0] ) && is_numeric( $result[0] ) ? intval( $result[0] ) : false;
73 }
$result
static exec($basename, $resultFile, $content, $timeout=true)
static getResultFile($basename)

References $result, exec(), and getResultFile().

◆ createShortcut()

static Vbs::createShortcut ( $savePath)
static

Creates a shortcut to the Bearsampp executable.

Parameters
string$savePathThe path to save the shortcut.
Returns
bool True on success, false on failure.

Definition at line 304 of file class.vbs.php.

305 {
307 $basename = 'createShortcut';
308 $resultFile = self::getResultFile( $basename );
309
310 $content = 'Dim objShell, objFso, objResultFile' . PHP_EOL . PHP_EOL;
311 $content .= 'Set objShell = Wscript.CreateObject("Wscript.Shell")' . PHP_EOL;
312 $content .= 'Set objFso = CreateObject("scripting.filesystemobject")' . PHP_EOL;
313 $content .= 'Set objResultFile = objFso.CreateTextFile("' . $resultFile . '", True)' . PHP_EOL . PHP_EOL;
314 $content .= 'Set objShortcut = objShell.CreateShortcut("' . $savePath . '")' . PHP_EOL;
315 $content .= 'objShortCut.TargetPath = "' . $bearsamppRoot->getExeFilePath() . '"' . PHP_EOL;
316 $content .= 'objShortCut.WorkingDirectory = "' . $bearsamppRoot->getRootPath() . '"' . PHP_EOL;
317 $content .= 'objShortCut.Description = "' . APP_TITLE . ' ' . $bearsamppCore->getAppVersion() . '"' . PHP_EOL;
318 $content .= 'objShortCut.IconLocation = "' . $bearsamppCore->getResourcesPath() . '/homepage/img/icons/app.ico' . '"' . PHP_EOL;
319 $content .= 'objShortCut.Save' . PHP_EOL;
320 $content .= 'If Err.Number <> 0 Then' . PHP_EOL;
321 $content .= ' objResultFile.Write Err.Number & ": " & Err.Description' . PHP_EOL;
322 $content .= 'End If' . PHP_EOL;
323 $content .= 'objResultFile.Close' . PHP_EOL;
324
325 $result = self::exec( $basename, $resultFile, $content );
326 if ( empty( $result ) ) {
327 return true;
328 }
329 elseif ( isset( $result[0] ) ) {
330 Util::logError( 'createShortcut: ' . $result[0] );
331
332 return false;
333 }
334
335 return false;
336 }
global $bearsamppRoot
global $bearsamppCore
static logError($data, $file=null)
const APP_TITLE
Definition root.php:12

References $bearsamppCore, $bearsamppRoot, $result, APP_TITLE, exec(), getResultFile(), and Util\logError().

Referenced by Util\enableLaunchStartup().

+ Here is the caller graph for this function:

◆ exec()

static Vbs::exec ( $basename,
$resultFile,
$content,
$timeout = true )
static

Executes a VBScript file and retrieves the result.

Parameters
string$basenameThe base name for the script and result files.
string$resultFileThe path to the result file.
string$contentThe VBScript content to execute.
int | bool$timeoutThe timeout duration in seconds, or true for default timeout, or false for no timeout.
Returns
array|false The result of the script execution as an array of lines, or false on failure.

Definition at line 429 of file class.vbs.php.

430 {
431 global $bearsamppConfig, $bearsamppWinbinder;
432 $result = false;
433
434 $scriptPath = self::getTmpFile( '.vbs', $basename );
435 $checkFile = self::getTmpFile( '.tmp', $basename );
436 $errFile = self::getTmpFile( '.tmp', $basename );
437 $randomVarName = Util::random( 15, false );
438 $randomObjErrFile = Util::random( 15, false );
439 $randomObjFile = Util::random( 15, false );
440 $randomObjFso = Util::random( 15, false );
441
442 // Header
443 $header = 'On Error Resume Next' . PHP_EOL .
444 'Dim ' . $randomVarName . ', ' . $randomObjFso . ', ' . $randomObjErrFile . ', ' . $randomObjFile . PHP_EOL .
445 'Set ' . $randomObjFso . ' = CreateObject("scripting.filesystemobject")' . PHP_EOL .
446 'Set ' . $randomObjErrFile . ' = ' . $randomObjFso . '.CreateTextFile("' . $errFile . '", True)' . PHP_EOL .
447 'Set ' . $randomObjFile . ' = ' . $randomObjFso . '.CreateTextFile("' . $checkFile . '", True)' . PHP_EOL . PHP_EOL;
448
449 // Footer
450 $footer = PHP_EOL . PHP_EOL .
451 'If Err.Number <> 0 Then' . PHP_EOL .
452 $randomObjErrFile . '.Write Err.Description' . PHP_EOL .
453 'End If' . PHP_EOL .
454 $randomObjFile . '.Write "' . self::END_PROCESS_STR . '"' . PHP_EOL .
455 $randomObjFile . '.Close' . PHP_EOL .
456 $randomObjErrFile . '.Close' . PHP_EOL;
457
458 // Process
459 file_put_contents( $scriptPath, $header . $content . $footer );
460 $bearsamppWinbinder->exec( 'wscript.exe', '"' . $scriptPath . '"' );
461
462 $timeout = is_numeric( $timeout ) ? $timeout : ($timeout === true ? $bearsamppConfig->getScriptsTimeout() : false);
463 $maxtime = time() + $timeout;
464 $noTimeout = $timeout === false;
465 while ( $result === false || empty( $result ) ) {
466 if ( file_exists( $checkFile ) ) {
467 $check = file( $checkFile );
468 if ( !empty( $check ) && trim( $check[0] ) == self::END_PROCESS_STR ) {
469 $result = file( $resultFile );
470 break;
471 }
472 }
473 if ( $maxtime < time() && !$noTimeout ) {
474 break;
475 }
476 }
477
478 $err = file_get_contents( $errFile );
479 if ( !empty( $err ) ) {
480 Util::logError( 'VBS error on ' . $basename . ': ' . $err );
481 }
482
483 self::writeLog( 'Exec ' . $basename . ':' );
484 self::writeLog( '-> content: ' . str_replace( PHP_EOL, ' \\\\ ', $content ) );
485 self::writeLog( '-> errFile: ' . $errFile );
486 self::writeLog( '-> checkFile: ' . $checkFile );
487 self::writeLog( '-> resultFile: ' . $resultFile );
488 self::writeLog( '-> scriptPath: ' . $scriptPath );
489
490 if ( $result !== false && !empty( $result ) ) {
491 $rebuildResult = array();
492 foreach ( $result as $row ) {
493 $row = trim( $row );
494 if ( !empty( $row ) ) {
495 $rebuildResult[] = $row;
496 }
497 }
498 $result = $rebuildResult;
499 self::writeLog( '-> result: ' . substr( implode( ' \\\\ ', $result ), 0, 2048 ) );
500 }
501 else {
502 self::writeLog( '-> result: N/A' );
503 }
504
505 return $result;
506 }
static random($length=32, $withNumeric=true)
static writeLog($log)
Definition class.vbs.php:36
static getTmpFile($ext, $customName=null)
global $bearsamppConfig
Definition homepage.php:26

Referenced by countFilesFolders(), createShortcut(), Registry\exists(), getDefaultBrowser(), getInstalledBrowsers(), getListProcs(), getSpecialPath(), Registry\getValue(), killProc(), and Registry\setValue().

+ Here is the caller graph for this function:

◆ getDefaultBrowser()

static Vbs::getDefaultBrowser ( )
static

Retrieves the default browser's executable path.

Returns
string|false The path to the default browser executable, or false on failure.

Definition at line 80 of file class.vbs.php.

81 {
82 $basename = 'getDefaultBrowser';
83 $resultFile = self::getResultFile( $basename );
84
85 $content = 'On Error Resume Next' . PHP_EOL;
86 $content .= 'Err.Clear' . PHP_EOL . PHP_EOL;
87 $content .= 'Dim objShell, objFso, objFile' . PHP_EOL . PHP_EOL;
88 $content .= 'Set objShell = WScript.CreateObject("WScript.Shell")' . PHP_EOL;
89 $content .= 'Set objFso = CreateObject("scripting.filesystemobject")' . PHP_EOL;
90 $content .= 'Set objFile = objFso.CreateTextFile("' . $resultFile . '", True)' . PHP_EOL . PHP_EOL;
91 $content .= 'objFile.Write objShell.RegRead("HKLM\SOFTWARE\Classes\http\shell\open\command\")' . PHP_EOL;
92 $content .= 'objFile.Close' . PHP_EOL;
93
94 $result = self::exec( $basename, $resultFile, $content );
95 if ( $result !== false && !empty( $result ) ) {
96 if ( preg_match( '/"([^"]+)"/', $result[0], $matches ) ) {
97 return $matches[1];
98 }
99 else {
100 return str_replace( '"', '', $result[0] );
101 }
102 }
103 else {
104 return false;
105 }
106 }

References $result, exec(), and getResultFile().

Referenced by ActionReload\__construct(), and ActionStartup\checkBrowser().

+ Here is the caller graph for this function:

◆ getInstalledBrowsers()

static Vbs::getInstalledBrowsers ( )
static

Retrieves a list of installed browsers' executable paths.

Returns
array|false An array of paths to installed browser executables, or false on failure.

Definition at line 113 of file class.vbs.php.

114 {
115 $basename = 'getInstalledBrowsers';
116 $resultFile = self::getResultFile( $basename );
117
118 $content = 'On Error Resume Next' . PHP_EOL;
119 $content .= 'Err.Clear' . PHP_EOL . PHP_EOL;
120 $content .= 'Dim objShell, objRegistry, objFso, objFile' . PHP_EOL . PHP_EOL;
121 $content .= 'Set objShell = WScript.CreateObject("WScript.Shell")' . PHP_EOL;
122 $content .= 'Set objRegistry = GetObject("winmgmts://./root/default:StdRegProv")' . PHP_EOL;
123 $content .= 'Set objFso = CreateObject("scripting.filesystemobject")' . PHP_EOL;
124 $content .= 'Set objFile = objFso.CreateTextFile("' . $resultFile . '", True)' . PHP_EOL . PHP_EOL;
125 $content .= 'mainKey = "SOFTWARE\WOW6432Node\Clients\StartMenuInternet"' . PHP_EOL;
126 $content .= 'checkKey = objShell.RegRead("HKLM\" & mainKey & "\")' . PHP_EOL;
127 $content .= 'If Err.Number <> 0 Then' . PHP_EOL;
128 $content .= ' Err.Clear' . PHP_EOL;
129 $content .= ' mainKey = "SOFTWARE\Clients\StartMenuInternet"' . PHP_EOL;
130 $content .= ' checkKey = objShell.RegRead("HKLM\" & mainKey & "\")' . PHP_EOL;
131 $content .= ' If Err.Number <> 0 Then' . PHP_EOL;
132 $content .= ' mainKey = ""' . PHP_EOL;
133 $content .= ' End If' . PHP_EOL;
134 $content .= 'End If' . PHP_EOL . PHP_EOL;
135 $content .= 'Err.Clear' . PHP_EOL;
136 $content .= 'If mainKey <> "" Then' . PHP_EOL;
137 $content .= ' objRegistry.EnumKey &H80000002, mainKey, arrSubKeys' . PHP_EOL;
138 $content .= ' For Each subKey In arrSubKeys' . PHP_EOL;
139 $content .= ' objFile.Write objShell.RegRead("HKLM\SOFTWARE\Clients\StartMenuInternet\" & subKey & "\shell\open\command\") & vbCrLf' . PHP_EOL;
140 $content .= ' Next' . PHP_EOL;
141 $content .= 'End If' . PHP_EOL;
142 $content .= 'objFile.Close' . PHP_EOL;
143
144 $result = self::exec( $basename, $resultFile, $content );
145 if ( $result !== false && !empty( $result ) ) {
146 $rebuildResult = array();
147 foreach ( $result as $browser ) {
148 $rebuildResult[] = str_replace( '"', '', $browser );
149 }
150 $result = $rebuildResult;
151 }
152
153 return $result;
154 }

References $result, exec(), and getResultFile().

Referenced by ActionChangeBrowser\__construct().

+ Here is the caller graph for this function:

◆ getListProcs()

static Vbs::getListProcs ( $vbsKeys)
static

Retrieves a list of running processes with specified keys.

Parameters
array$vbsKeysThe keys to retrieve for each process.
Returns
array|false An array of process information, or false on failure.

Definition at line 163 of file class.vbs.php.

164 {
165 $basename = 'getListProcs';
166 $resultFile = self::getResultFile( $basename );
167 $sep = ' & "' . self::STR_SEPARATOR . '" & _';
168
169 $content = 'Dim objFso, objResultFile, objWMIService' . PHP_EOL . PHP_EOL;
170 $content .= 'Set objFso = CreateObject("scripting.filesystemobject")' . PHP_EOL;
171 $content .= 'Set objResultFile = objFso.CreateTextFile("' . $resultFile . '", True)' . PHP_EOL;
172 $content .= 'strComputer = "."' . PHP_EOL;
173 $content .= 'Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\\\" & strComputer & "\root\cimv2")' . PHP_EOL;
174 $content .= 'Set listProcess = objWMIService.ExecQuery ("SELECT * FROM Win32_Process")' . PHP_EOL;
175 $content .= 'For Each process in listProcess' . PHP_EOL;
176
177 $content .= ' objResultFile.WriteLine(_' . PHP_EOL;
178 foreach ( $vbsKeys as $vbsKey ) {
179 $content .= ' process.' . $vbsKey . $sep . PHP_EOL;
180 }
181 $content = substr( $content, 0, strlen( $content ) - strlen( $sep ) - 1 ) . ')' . PHP_EOL;
182
183 $content .= 'Next' . PHP_EOL;
184 $content .= 'objResultFile.WriteLine("' . self::END_PROCESS_STR . '")' . PHP_EOL;
185 $content .= 'objResultFile.Close' . PHP_EOL;
186 $content .= 'Err.Clear' . PHP_EOL;
187
188 $result = self::exec( $basename, $resultFile, $content );
189 if ( empty( $result ) ) {
190 return false;
191 }
192
193 unset( $result[array_search( self::END_PROCESS_STR, $result )] );
194 if ( is_array( $result ) && count( $result ) > 0 ) {
195 $rebuildResult = array();
196 foreach ( $result as $row ) {
197 $row = explode( trim( self::STR_SEPARATOR ), $row );
198 if ( count( $row ) != count( $vbsKeys ) ) {
199 continue;
200 }
201 $processInfo = array();
202 foreach ( $vbsKeys as $key => $vbsKey ) {
203 $processInfo[$vbsKey] = trim( $row[$key] );
204 }
205 if ( !empty( $processInfo[Win32Ps::EXECUTABLE_PATH] ) ) {
206 $rebuildResult[] = $processInfo;
207 }
208 }
209
210 return $rebuildResult;
211 }
212
213 return false;
214 }
const EXECUTABLE_PATH

References $result, exec(), Win32Ps\EXECUTABLE_PATH, and getResultFile().

Referenced by Win32Ps\getListProcs().

+ Here is the caller graph for this function:

◆ getResultFile()

static Vbs::getResultFile ( $basename)
static

Retrieves the path for a result file based on a given basename.

Parameters
string$basenameThe base name to use for the result file.
Returns
string The path to the result file.

Definition at line 414 of file class.vbs.php.

415 {
416 return self::getTmpFile( '.vbs', $basename );
417 }

Referenced by countFilesFolders(), createShortcut(), Registry\exists(), getDefaultBrowser(), getInstalledBrowsers(), getListProcs(), getServiceInfos(), getSpecialPath(), Registry\getValue(), killProc(), and Registry\setValue().

+ Here is the caller graph for this function:

◆ getServiceInfos()

static Vbs::getServiceInfos ( $serviceName)
static

Retrieves information about a Windows service.

Parameters
string$serviceNameThe name of the service to retrieve information about.
Returns
array|false An array of service information, or false on failure.

Definition at line 345 of file class.vbs.php.

346 {
347 $basename = 'getServiceInfos';
348 $resultFile = self::getResultFile( $basename );
349 $sep = ' & "' . self::STR_SEPARATOR . '" & _';
350 $vbsKeys = Win32Service::getVbsKeys();
351
352 $content = 'Dim objFso, objResultFile, objWMIService' . PHP_EOL . PHP_EOL;
353 $content .= 'Set objFso = CreateObject("scripting.filesystemobject")' . PHP_EOL;
354 $content .= 'Set objResultFile = objFso.CreateTextFile("' . $resultFile . '", True)' . PHP_EOL;
355 $content .= 'strComputer = "."' . PHP_EOL;
356 $content .= 'Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\\\" & strComputer & "\root\cimv2")' . PHP_EOL;
357 $content .= 'Set listServices = objWMIService.ExecQuery ("SELECT * FROM Win32_Service WHERE Name=\'' . $serviceName . '\'")' . PHP_EOL;
358 $content .= 'For Each service in listServices' . PHP_EOL;
359
360 $content .= ' objResultFile.WriteLine(_' . PHP_EOL;
361 foreach ( $vbsKeys as $vbsKey ) {
362 $content .= ' service.' . $vbsKey . $sep . PHP_EOL;
363 }
364 $content = substr( $content, 0, strlen( $content ) - strlen( $sep ) - 1 ) . ')' . PHP_EOL;
365
366 $content .= 'Next' . PHP_EOL;
367 $content .= 'objResultFile.WriteLine("' . self::END_PROCESS_STR . '")' . PHP_EOL;
368 $content .= 'objResultFile.Close' . PHP_EOL;
369
370 $result = self::exec( $basename, $resultFile, $content );
371 if ( empty( $result ) ) {
372 return false;
373 }
374
375 unset( $result[array_search( self::END_PROCESS_STR, $result )] );
376 if ( is_array( $result ) && count( $result ) == 1 ) {
377 $rebuildResult = array();
378 $row = explode( trim( self::STR_SEPARATOR ), $result[0] );
379 if ( count( $row ) != count( $vbsKeys ) ) {
380 return false;
381 }
382 foreach ( $vbsKeys as $key => $vbsKey ) {
383 $rebuildResult[$vbsKey] = trim( $row[$key] );
384 }
385
386 return $rebuildResult;
387 }
388
389 return false;
390 }

References getResultFile(), and Win32Service\getVbsKeys().

Referenced by Nssm\infos(), and Win32Service\infos().

+ Here is the caller graph for this function:

◆ getSpecialPath()

static Vbs::getSpecialPath ( $path)
staticprivate

Retrieves a special folder path.

Parameters
string$pathThe VBScript path constant for the special folder.
Returns
string|null The path to the special folder, or null on failure.

Definition at line 265 of file class.vbs.php.

266 {
267 $basename = 'getSpecialPath';
268 $resultFile = self::getResultFile( $basename );
269
270 $content = 'Dim objShell, objFso, objResultFile' . PHP_EOL . PHP_EOL;
271 $content .= 'Set objShell = Wscript.CreateObject("Wscript.Shell")' . PHP_EOL;
272 $content .= 'Set objFso = CreateObject("scripting.filesystemobject")' . PHP_EOL;
273 $content .= 'Set objResultFile = objFso.CreateTextFile("' . $resultFile . '", True)' . PHP_EOL . PHP_EOL;
274 $content .= 'objResultFile.WriteLine(' . $path . ')' . PHP_EOL;
275 $content .= 'objResultFile.Close' . PHP_EOL;
276
277 $result = self::exec( $basename, $resultFile, $content );
278 if ( !empty( $result ) && is_array( $result ) && count( $result ) == 1 ) {
279 return Util::formatUnixPath( $result[0] );
280 }
281
282 return null;
283 }
static formatUnixPath($path)

References $result, exec(), Util\formatUnixPath(), and getResultFile().

Referenced by getStartupPath().

+ Here is the caller graph for this function:

◆ getStartupPath()

static Vbs::getStartupPath ( $file = null)
static

Retrieves the startup path, optionally appending a file name.

Parameters
string | null$fileThe file name to append to the startup path.
Returns
string The startup path.

Definition at line 292 of file class.vbs.php.

293 {
294 return self::getSpecialPath( self::STARTUP_PATH ) . ($file != null ? '/' . $file : '');
295 }
static getSpecialPath($path)

References getSpecialPath().

Referenced by Util\getStartupLnkPath().

+ Here is the caller graph for this function:

◆ getTmpFile()

static Vbs::getTmpFile ( $ext,
$customName = null )
static

Generates a temporary file path with a given extension and optional custom name.

Parameters
string$extThe file extension for the temporary file.
string | null$customNameAn optional custom name to include in the file name.
Returns
string The formatted path to the temporary file.

Definition at line 400 of file class.vbs.php.

401 {
402 global $bearsamppCore;
403
404 return Util::formatWindowsPath( $bearsamppCore->getTmpPath() . '/' . (!empty( $customName ) ? $customName . '-' : '') . Util::random() . $ext );
405 }
static formatWindowsPath($path)

◆ killProc()

static Vbs::killProc ( $pid)
static

Terminates a process by its PID.

Parameters
int$pidThe process ID to terminate.
Returns
bool True on success, false on failure.

Definition at line 223 of file class.vbs.php.

224 {
225 $basename = 'killProc';
226 $resultFile = self::getResultFile( $basename );
227
228 $content = 'Dim objFso, objResultFile, objWMIService' . PHP_EOL . PHP_EOL;
229 $content .= 'Set objFso = CreateObject("scripting.filesystemobject")' . PHP_EOL;
230 $content .= 'Set objResultFile = objFso.CreateTextFile("' . $resultFile . '", True)' . PHP_EOL;
231 $content .= 'strComputer = "."' . PHP_EOL;
232 $content .= 'strProcessKill = "' . $pid . '"' . PHP_EOL;
233 $content .= 'Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\\\" & strComputer & "\root\cimv2")' . PHP_EOL;
234 $content .= 'Set listProcess = objWMIService.ExecQuery ("Select * from Win32_Process Where ProcessID = " & strProcessKill)' . PHP_EOL;
235 $content .= 'For Each objProcess in listProcess' . PHP_EOL;
236 $content .= ' objResultFile.WriteLine(objProcess.Name & "' . self::STR_SEPARATOR . '" & objProcess.ProcessID & "' . self::STR_SEPARATOR . '" & objProcess.ExecutablePath)' . PHP_EOL;
237 $content .= ' objProcess.Terminate()' . PHP_EOL;
238 $content .= 'Next' . PHP_EOL;
239 $content .= 'objResultFile.Close' . PHP_EOL;
240
241 $result = self::exec( $basename, $resultFile, $content );
242 if ( empty( $result ) ) {
243 return true;
244 }
245
246 if ( is_array( $result ) && count( $result ) > 0 ) {
247 foreach ( $result as $row ) {
248 $row = explode( self::STR_SEPARATOR, $row );
249 if ( count( $row ) == 3 && !empty( $row[2] ) ) {
250 Util::logDebug( 'Kill process ' . $row[2] . ' (PID ' . $row[1] . ')' );
251 }
252 }
253 }
254
255 return true;
256 }
static logDebug($data, $file=null)

References $result, exec(), getResultFile(), and Util\logDebug().

Referenced by Win32Ps\kill().

+ Here is the caller graph for this function:

◆ writeLog()

static Vbs::writeLog ( $log)
staticprivate

Writes a log entry to the VBS log file.

Parameters
string$logThe log message to write.

Definition at line 36 of file class.vbs.php.

37 {
38 global $bearsamppRoot;
39 Util::logDebug( $log, $bearsamppRoot->getVbsLogFilePath() );
40 }

References $bearsamppRoot, and Util\logDebug().

Field Documentation

◆ ALL_DESKTOP_PATH

const Vbs::ALL_DESKTOP_PATH = 'objShell.SpecialFolders("AllUsersDesktop")'

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

◆ ALL_STARTUP_PATH

const Vbs::ALL_STARTUP_PATH = 'objShell.SpecialFolders("AllUsersStartup")'

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

◆ DESKTOP_PATH

const Vbs::DESKTOP_PATH = 'objShell.SpecialFolders("Desktop")'

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

◆ END_PROCESS_STR

const Vbs::END_PROCESS_STR = 'FINISHED!'

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

◆ STARTUP_PATH

const Vbs::STARTUP_PATH = 'objShell.SpecialFolders("Startup")'

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

◆ STR_SEPARATOR

const Vbs::STR_SEPARATOR = ' || '

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


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