Header-Ad

PHP,Joomla,WordPress & Linux based server management, error resolutions and fixing problems.

Thursday, October 4, 2012

PHP Get Process Creation Time.

So, this is a very quick and dirty method that i am going to tell you today, actually whenever on windows platform if you need to get the time of when is a certain process is created, actually nobody needs it that much only but if you are creating system layered applications with PHP and are going deep inside digging through the WinCOM Objects.
Anyway, i won't recommend this method but may be any of you finds it useful in any scenarios,so here we go:

First of all you need to know, what actually are you trying to achieve,the process in Windows can be accessed using two ways, either by using the PID (Process Identifier) or the name (Image Name). So i will tell you the both ways you can actually get to that by how, here is the code :

$pid "9252";$wmi new COM('winmgmts://')$process $wmi->ExecQuery("SELECT * FROM Win32_Process WHERE ProcessId ='".$pid."'")$pDate floor($process->CreationDate);    $formatDate date_parse($pDate);$time $formatDate['hour'].':'.$formatDate['minute'].':'.$formatDate['second'];print $time;

So, what is actually happening above, its quite simple, i am using COM objects with PHP, even though you should use them with great precautions because they can be huge security risk if exploited so you should have to be really careful playing around with these.

Just change the $pid "9252"to any PID you like,and if you want to know the process creation time using its name,than it is quite simple as well, just change the ProcessId with ProcessName in  $wmi->ExecQuery("SELECT * FROM Win32_Process WHERE ProcessId ='".$pid."'");  and you are good to go.

There could be many more methods out but i used this one for my own usage and it quite helped me. But as before i would recommend you to thoroughly tighten the security if you are using COM objects on Enterprise level.

Happy Coding!
, ,

No comments:

Post a Comment

** Comments are reviewed, but not delayed posted **