Is there any lua function to get the time since given process is started?
Есть ли какая-нибудь функция lua для получения времени с момента запуска данного процесса?
--lua
local t = os.clock()
while true do
log (os.clock() - t)
wait (100)
end
--lua
local t = os.clock()
while true do
log (os.clock() - t)
wait (100)
end
--lua
log"clear";log"mode compact"
require"luaposh";PScode('return',{[[#}
if(((get-date) - (Get-Process *calc*).StartTime).totalhours -gt 3){
log 'YES'
}
else{
log 'NO'
}
]]})
--lua
log"clear";log"mode compact"
require"luaposh";PScode('return',{[[#}
if(((get-date) - (Get-Process *calc*).StartTime).totalhours -gt 3){
log 'YES'
}
else{
log 'NO'
}
]]})
--lua
local PROCESS_ALL_ACCESS = 2097151
local ffi = require("ffi")
local user, kernel = ffi.load('User32'), ffi.load('Kernel32')
ffi.cdef[[
typedef unsigned short WORD;
typedef unsigned long DWORD;
typedef DWORD *LPDWORD;
typedef struct _FILETIME {DWORD dwLowDateTime; DWORD dwHighDateTime;} FILETIME, *PFILETIME, *LPFILETIME;
typedef struct _SYSTEMTIME {WORD wYear; WORD wMonth; WORD wDayOfWeek; WORD wDay;
WORD wHour; WORD wMinute; WORD wSecond; WORD wMilliseconds;} SYSTEMTIME, *PSYSTEMTIME, *LPSYSTEMTIME;
bool CloseHandle(int hObject);
int OpenProcess(DWORD dwDesiredAccess, bool bInheritHandle, DWORD dwProcessId);
bool GetProcessTimes(int hProcess, LPFILETIME lpCreationTime, LPFILETIME lpExitTime, LPFILETIME lpKernelTime, LPFILETIME lpUserTime);
DWORD GetWindowThreadProcessId(int hWnd, LPDWORD lpdwProcessId);
bool FileTimeToSystemTime(const FILETIME *lpFileTime, LPSYSTEMTIME lpSystemTime);
bool FileTimeToLocalFileTime(const FILETIME *lpFileTime, LPFILETIME lpLocalFileTime);
]]
local ft, ft2, ft3, ft4, st = ffi.new('FILETIME'), ffi.new('FILETIME'), ffi.new('FILETIME'), ffi.new('FILETIME'), ffi.new('SYSTEMTIME')
local PID = ffi.new('unsigned long[1]')
function GetProcessTime(handle)
if handle == 0 then return 0 end
user.GetWindowThreadProcessId(handle, PID)
local process = kernel.OpenProcess(PROCESS_ALL_ACCESS, 1, PID[0])
if process > 0 then
kernel.GetProcessTimes(process, ft, ft2, ft3, ft4)
kernel.FileTimeToLocalFileTime(ft, ft);
kernel.FileTimeToSystemTime(ft, st);
local datetime = { year = st.wYear, month = st.wMonth, day = st.wDay, hour = st.wHour, min = st.wMinute, sec = st.wSecond}
kernel.CloseHandle(process);
return os.time() - os.time(datetime)
end
return -1
end
log 'clear' log 'mode compact'
local t = GetProcessTime(workwindow()) -- function call
log (tostring(t) .. ' seconds')
--lua
local PROCESS_ALL_ACCESS = 2097151
local ffi = require("ffi")
local user, kernel = ffi.load('User32'), ffi.load('Kernel32')
ffi.cdef[[
typedef unsigned short WORD;
typedef unsigned long DWORD;
typedef DWORD *LPDWORD;
typedef struct _FILETIME {DWORD dwLowDateTime; DWORD dwHighDateTime;} FILETIME, *PFILETIME, *LPFILETIME;
typedef struct _SYSTEMTIME {WORD wYear; WORD wMonth; WORD wDayOfWeek; WORD wDay;
WORD wHour; WORD wMinute; WORD wSecond; WORD wMilliseconds;} SYSTEMTIME, *PSYSTEMTIME, *LPSYSTEMTIME;
bool CloseHandle(int hObject);
int OpenProcess(DWORD dwDesiredAccess, bool bInheritHandle, DWORD dwProcessId);
bool GetProcessTimes(int hProcess, LPFILETIME lpCreationTime, LPFILETIME lpExitTime, LPFILETIME lpKernelTime, LPFILETIME lpUserTime);
DWORD GetWindowThreadProcessId(int hWnd, LPDWORD lpdwProcessId);
bool FileTimeToSystemTime(const FILETIME *lpFileTime, LPSYSTEMTIME lpSystemTime);
bool FileTimeToLocalFileTime(const FILETIME *lpFileTime, LPFILETIME lpLocalFileTime);
]]
local ft, ft2, ft3, ft4, st = ffi.new('FILETIME'), ffi.new('FILETIME'), ffi.new('FILETIME'), ffi.new('FILETIME'), ffi.new('SYSTEMTIME')
local PID = ffi.new('unsigned long[1]')
function GetProcessTime(handle)
if handle == 0 then return 0 end
user.GetWindowThreadProcessId(handle, PID)
local process = kernel.OpenProcess(PROCESS_ALL_ACCESS, 1, PID[0])
if process > 0 then
kernel.GetProcessTimes(process, ft, ft2, ft3, ft4)
kernel.FileTimeToLocalFileTime(ft, ft);
kernel.FileTimeToSystemTime(ft, st);
local datetime = { year = st.wYear, month = st.wMonth, day = st.wDay, hour = st.wHour, min = st.wMinute, sec = st.wSecond}
kernel.CloseHandle(process);
return os.time() - os.time(datetime)
end
return -1
end
log 'clear' log 'mode compact'
local t = GetProcessTime(workwindow()) -- function call
log (tostring(t) .. ' seconds')