ruiner
10-30-2004, 01:22 PM
I'm writting a very simple script that will show the uptime of the server. Unfortunately this script will only work if using NT security and logging in as administrator. It won't even work with normal users. I'm trying to find out where you set the security for this... Any help appreciated!
BTW I'm going to be using a lot more wmi functions, I know there are other ways to find uptime but this is just an example script so I can get this working..
$this->wmi = new COM("WinMgmts:\\\\.");
$objInstance = $this->wmi->InstancesOf("Win32_OperatingSystem");
$obj = $objInstance->Next();
$year = intval(substr($obj->LastBootUpTime, 0, 4));
$month = intval(substr($obj->LastBootUpTime, 4, 2));
$day = intval(substr($obj->LastBootUpTime, 6, 2));
$hour = intval(substr($obj->LastBootUpTime, 8, 2));
$minute = intval(substr($obj->LastBootUpTime, 10, 2));
$seconds = intval(substr($obj->LastBootUpTime, 12, 2));
$boottime = mktime($hour, $minute, $seconds, $month, $day, $year);
$diff_seconds = mktime() - $boottime;
$diff_days = floor($diff_seconds / 86400);
$diff_seconds -= $diff_days * 86400;
$diff_hours = floor($diff_seconds / 3600);
$diff_seconds -= $diff_hours * 3600;
$diff_minutes = floor($diff_seconds / 60);
$diff_seconds -= $diff_minutes * 60;
echo "$diff_days days, $diff_hours hours, $diff_minutes minutes, and $diff_seconds seconds";
BTW I'm going to be using a lot more wmi functions, I know there are other ways to find uptime but this is just an example script so I can get this working..
$this->wmi = new COM("WinMgmts:\\\\.");
$objInstance = $this->wmi->InstancesOf("Win32_OperatingSystem");
$obj = $objInstance->Next();
$year = intval(substr($obj->LastBootUpTime, 0, 4));
$month = intval(substr($obj->LastBootUpTime, 4, 2));
$day = intval(substr($obj->LastBootUpTime, 6, 2));
$hour = intval(substr($obj->LastBootUpTime, 8, 2));
$minute = intval(substr($obj->LastBootUpTime, 10, 2));
$seconds = intval(substr($obj->LastBootUpTime, 12, 2));
$boottime = mktime($hour, $minute, $seconds, $month, $day, $year);
$diff_seconds = mktime() - $boottime;
$diff_days = floor($diff_seconds / 86400);
$diff_seconds -= $diff_days * 86400;
$diff_hours = floor($diff_seconds / 3600);
$diff_seconds -= $diff_hours * 3600;
$diff_minutes = floor($diff_seconds / 60);
$diff_seconds -= $diff_minutes * 60;
echo "$diff_days days, $diff_hours hours, $diff_minutes minutes, and $diff_seconds seconds";
