|
|
|
Get the time since given process is started., Получить время с момента запуска данного процесса. |
|
|
neves |
11.5.2020, 23:22
|
Novice
Сообщений: 64
Регистрация: 4.10.2019 Группа: Пользователи Наличность: 0
Пользователь №: 19.419
Возраст: 19
|
Цитата(cirus @ 11.5.2020, 22:16) Код --lua local t = os.clock()
while true do log (os.clock() - t) wait (100) end Thanks for the fast reply, but that's not what I need. Example: I bind given script to 'calculator.exe', and I wanna know at what time 'calculator.exe' was started or for how long calcualtor.exe is running. For what I need this? I just want to make script which checks if process is running for more than 3 hours.
|
|
|
|
neves |
12.5.2020, 0:05
|
Novice
Сообщений: 64
Регистрация: 4.10.2019 Группа: Пользователи Наличность: 0
Пользователь №: 19.419
Возраст: 19
|
Цитата(Fors1k @ 11.5.2020, 22:55) Код --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' }
]]}) Awesome! That's working, but is there any way to do it without using posh? I just found this -> winapi/process.lua and now trying to implement it.
|
|
|
|
Fors1k |
12.5.2020, 0:19
|
Journeyman
Сообщений: 497
Регистрация: 19.12.2017 Группа: Пользователи Наличность: 2420
Пользователь №: 18.746
|
Цитата(neves @ 12.5.2020, 0:05) Awesome! That's working, but is there any way to do it without using posh?
With posh you can solve almost all ur needs, without necessary to install any mods. For example u can remember this issue. Ask, if u'll need more help with the code. Anyway, u can continue writing in lua below this luaposh block. Or above it.
--------------------
Для связи
|
|
|
|
cirus |
12.5.2020, 0:59
|
Elder
Сообщений: 3.480
Регистрация: 18.8.2014 Группа: Пользователи Наличность: 26540
Пользователь №: 16.971
Возраст: 29
|
Цитата but is there any way to do it without using posh? code
Код --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')
|
|
|
|
neves |
12.5.2020, 4:02
|
Novice
Сообщений: 64
Регистрация: 4.10.2019 Группа: Пользователи Наличность: 0
Пользователь №: 19.419
Возраст: 19
|
Цитата(Fors1k @ 11.5.2020, 23:19) With posh you can solve almost all ur needs, without necessary to install any mods. For example u can remember this issue. Ask, if u'll need more help with the code. Anyway, u can continue writing in lua below this luaposh block. Or above it. Posh solution is very simple and clean! Just wanted to see ffi/winapi solution because I already had them imported in my script. About this issue. Other problems popped up and sadly its not finished. :/ Цитата(cirus @ 11.5.2020, 23:59) code
Код --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') Works perfect! Thank you.
|
|
|
|
|
|
1 чел. читают эту тему (гостей: 1, скрытых пользователей: 0)
Пользователей: 0
|
|