gspino Posted August 30, 2018 Share Posted August 30, 2018 I wonder if some of you seasoned developers can help me get off the ground with what started out as a simple project, but I keep hitting roadblocks. The goal is to write to a log file every time someone launches excel.exe, winword.exe, powerpnt.exe, or outlook.exe. I've tried tons of different approaches, but it seems like the ProcessWaitClose is my big hang-up. I can't seem to get over this hump. It's my last year before retirement and I know I'm not as sharp as I used to be, so if someone can give me a nudge in the right direction, I would be most appreciative. I want to run the app on selected pc's - I had one version that just consumed too many resources to be useful - it needs to run as a background process always waiting for one of these apps to launch. I don't care to know how long the app stays open or when it's closed, I just want a simple log every time one of these processes is launched. Thanks very much to anyone who can offer some guidance. Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted August 30, 2018 Moderators Share Posted August 30, 2018 Moving to the correct forum... So to clarify, you want something that sits in the tray or runs in the background, that simply logs to a file whenever someone opens one of the applications? What was the ProcessWaitClose doing that it was "hanging you up"? Your code, even if it is not working as you would like it, would definitely help us help you. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
caramen Posted August 31, 2018 Share Posted August 31, 2018 (edited) You should better work with a loop like that : While 1 If ProcessExist ("Excel.exe") Then ExcelLog() ElseIf ProcessExist ("Word.exe") Then WordLog() EndIf Wend Func ExcelLog() Do Sleep (10) If ProcessExist ("Excel.exe") Then $ExcelHere = 1 Else $ExcelHere = 0 EndIf Until $ExcelHere = 0 EndFunc Func WordLog () EndFunc This is checking one process i am sure you can find a way to do it with all process Edit ; With that code you gonna be stuck : if one office application is detected. It will stay in the loop. But you can manage that easy. Edited August 31, 2018 by caramen My video tutorials : ( In construction ) || My Discord : https://discord.gg/S9AnwHw How to Ask Help || UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote Spoiler Water's UDFs:Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - Wiki Tutorials:ADO - Wiki Link to comment Share on other sites More sharing options...
Simpel Posted August 31, 2018 Share Posted August 31, 2018 (edited) @caramen: In your script only one program at a time could be logged. If Excel.exe exists it is permanently checking if it's currently existing, but not checking existence of Word.exe anymore. Simpel Edit: Wrote it before you edited but sended after. Edited August 31, 2018 by Simpel SciTE4AutoIt = 3.7.3.0 AutoIt = 3.3.14.2 AutoItX64 = 0 OS = Win_10 Build = 19044 OSArch = X64 Language = 0407/german H:\...\AutoIt3\SciTE H:\...\AutoIt3 H:\...\AutoIt3\Include (H:\ = Network Drive) Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. Link to comment Share on other sites More sharing options...
TheSaint Posted August 31, 2018 Share Posted August 31, 2018 (edited) As has been suggested, providing some code can be quite helpful, and no need to feel bashful, as we were all beginners once. It can help us understand where you are at, and also maybe save us some work, with the idea being, we teach to fish, rather than fish for you. That said, here are some ideas to go on with. Get the PID return from ProcessExists, when Excel (etc) is detected, and use that for repeated comparisons, so the same instance is not repeatedly detected. It also frees you from waiting for Excel (etc) to close. For every new instance, use _FileWriteLog to write the program name (i.e. Excel) to a Log file (it includes date and time). Put that all in a While 1 .... Wend loop (with the required If ... Then statements), making sure you give yourself an escape option (check out _IsPressed). Also add a delay in the loop i..e. Sleep(2000). Edited August 31, 2018 by TheSaint gspino 1 Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage) Link to comment Share on other sites More sharing options...
gspino Posted August 31, 2018 Author Share Posted August 31, 2018 (edited) I think I got it. Many thanks to all - you were a big help. #include <Date.au3> #include <WindowsConstants.au3> #include <AutoItConstants.au3> Opt("TrayIconHide", 1) ;============================================== ;LIMIT SCRIPT TO 1 RUNNING INSTANCE $G_SZVERSION = "SWMeter" If WinExists($G_SZVERSION) Then Exit AutoItWinSetTitle($G_SZVERSION) ;============================================== If Not FileExists("c:\wgtemp\swmeter") Then DirCreate("c:\wgtemp\swmeter") ;============================================== Local $PID1 = 0 Local $PID2 = 0 Local $PID3 = 0 Local $PID4 = 0 Local $PID5 = 0 Local $LastPID1 = 0 Local $LastPID2 = 0 Local $LastPID3 = 0 Local $LastPID4 = 0 Local $LastPID5 = 0 Local $aProcessList1 = 0 Local $aProcessList2 = 0 Local $aProcessList3 = 0 Local $aProcessList4 = 0 Local $aProcessList5 = 0 While 1 ProcessList() ;check to see if excel is running If ProcessExists("excel.exe") Then Local $aProcessList1 = ProcessList("excel.exe") $PID1 = $aProcessList1[1][1] EndIf If $PID1 <> $LastPID1 Then FileWriteLine("c:\wgtemp\swmeter\SWMETER" & @ComputerName & ".txt", @ComputerName & " " & @UserName & " " & "Excel" & " " & @MON & "-" & @MDAY & "-" & @YEAR & " " & @HOUR & ":" & @MIN & " " & "OPENED") $LastPID1 = $PID1 EndIf Sleep(2000) ;check to see if word is running If ProcessExists("winword.exe") Then $aProcessList2 = ProcessList("winword.exe") $PID2 = $aProcessList2[1][1] EndIf If $PID2 <> $LastPID2 Then FileWriteLine("c:\wgtemp\swmeter\SWMETER" & @ComputerName & ".txt", @ComputerName & " " & @UserName & " " & "Word" & " " & @MON & "-" & @MDAY & "-" & @YEAR & " " & @HOUR & ":" & @MIN & " " & "OPENED") $LastPID2 = $PID2 EndIf Sleep(2000) ;check to see if outlook is running If ProcessExists("outlook.exe") Then $aProcessList3 = ProcessList("outlook.exe") $PID3 = $aProcessList3[1][1] EndIf If $PID3 <> $LastPID3 Then FileWriteLine("c:\wgtemp\swmeter\SWMETER" & @ComputerName & ".txt", @ComputerName & " " & @UserName & " " & "Outlook" & " " & @MON & "-" & @MDAY & "-" & @YEAR & " " & @HOUR & ":" & @MIN & " " & "OPENED") $LastPID3 = $PID3 EndIf Sleep(2000) ;check to see if powerpoint is running If ProcessExists("powerpnt.exe") Then $aProcessList4 = ProcessList("powerpnt.exe") $PID4 = $aProcessList4[1][1] EndIf If $PID4 <> $LastPID4 Then FileWriteLine("c:\wgtemp\swmeter\SWMETER" & @ComputerName & ".txt", @ComputerName & " " & @UserName & " " & "PowerPoint" & " " & @MON & "-" & @MDAY & "-" & @YEAR & " " & @HOUR & ":" & @MIN & " " & "OPENED") $LastPID4 = $PID4 EndIf Sleep(2000) ;check to see if remote desktop is running If ProcessExists("mstsc.exe") Then $aProcessList5 = ProcessList("mstsc.exe") $PID5 = $aProcessList5[1][1] EndIf If $PID5 <> $LastPID5 Then FileWriteLine("c:\wgtemp\swmeter\SWMETER" & @ComputerName & ".txt", @ComputerName & " " & @UserName & " " & "RemoteDesktop" & " " & @MON & "-" & @MDAY & "-" & @YEAR & " " & @HOUR & ":" & @MIN & " " & "OPENED") $LastPID5 = $PID5 EndIf Sleep(2000) WEnd Edited August 31, 2018 by gspino Link to comment Share on other sites More sharing options...
Uten Posted September 1, 2018 Share Posted September 1, 2018 Take a look at this code: Easy shell hook Should be trivial to make a app logger with it. gspino 1 Please keep your sig. small! Use the help file. Search the forum. Then ask unresolved questions :) Script plugin demo, Simple Trace udf, TrayMenuEx udf, IOChatter demo, freebasic multithreaded dll sample, PostMessage, Aspell, Code profiling Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now