kylomas Posted November 5, 2011 Posted November 5, 2011 Hi, I am running a script at system startup using the task schedular (for elevated authority). @username is returning the name of the authority that the script is running under, NOT the logged on user. Anyone know of a way to get the logged on user givern this scenario? Running Win 7 (64bit) at latest maintenance levels. Script: expandcollapse popup#NoTrayIcon #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Outfile_x64=..\EXE\watcher.exe #AutoIt3Wrapper_UseUpx=n #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <array.au3> #include <date.au3> #cs watchlist structure n,0 = process to watch for n,1 = program to run n,2 = program to run parm #1 n,3 = this slot intentionally left blank n,4 = run program when process starts n,5 = run program when process ends #ce local $a_watchlist[20][6] $a_watchlist[0][0] = "iexplore.exe" $a_watchlist[0][1] = "c:\program files\ccleaner\ccleaner64.exe" $a_watchlist[0][2] = "/auto" $a_watchlist[0][3] = "" $a_watchlist[0][4] = false $a_watchlist[0][5] = true $a_watchlist[1][0] = "outlook.exe" $a_watchlist[1][1] = "c:\program files\ccleaner\ccleaner64.exe" $a_watchlist[1][2] = "/auto" $a_watchlist[1][3] = "" $a_watchlist[1][4] = false $a_watchlist[1][5] = true $a_watchlist[2][0] = "wlmail.exe" $a_watchlist[2][1] = "c:\program files\ccleaner\ccleaner64.exe" $a_watchlist[2][2] = "/auto" $a_watchlist[2][3] = "" $a_watchlist[2][4] = false $a_watchlist[2][5] = true local $a_curractive, $a_prevactive = processlist() while 1 $a_curractive = processlist() checkstarts() checkends() $a_prevactive = $a_curractive sleep(5000) wend func checkstarts() local $hit for $i = 1 to $a_curractive[0][0] $hit = false for $j = 1 to $a_prevactive[0][0] if $a_curractive[$i][0] = $a_prevactive[$j][0] and $a_curractive[$i][1] = $a_prevactive[$j][1] then $hit = True exitloop endif next if $hit = false then ; yes, got something new now check if we are watching for it ;dbgarrays() for $k = 0 to ubound($a_watchlist,1) - 1 if $a_curractive[$i][0] = $a_watchlist[$k][0] then ;yes, we are watching for it, now what to do??? if $a_watchlist[$k][4] then shellexecute($a_watchlist[$k][1],$a_watchlist[$k][2]) lf(" Event: " & @username & @tab & $a_watchlist[$k][1] & $a_watchlist[$k][2] & " initiated by program start [" & $a_curractive[$i][0] & ']') endif EndIf next endif next endfunc func checkends() local $hit for $i = 1 to $a_prevactive[0][0] $hit = false for $j = 1 to $a_curractive[0][0] if $a_prevactive[$i][0] = $a_curractive[$j][0] and $a_prevactive[$i][1] = $a_curractive[$j][1] then $hit = True exitloop endif next if $hit = false then ; yes, something ended now check if we are watching for it ;dbgarrays() for $k = 0 to ubound($a_watchlist,1) - 1 if $a_prevactive[$i][0] = $a_watchlist[$k][0] then ;yes, we are watching for it, now what to do??? if $a_watchlist[$k][5] then shellexecute($a_watchlist[$k][1],$a_watchlist[$k][2]) lf(" Event: " & @username & @tab & $a_watchlist[$k][1] & $a_watchlist[$k][2] & " initiated by program stop [" & $a_prevactive[$i][0] & ']') endif EndIf next endif next endfunc func dbgarrays() ; this will create a 2d 4 column array of 2 2d arrays side by side (for debugging arrays created by processlist()) if $a_curractive[0][0] > $a_prevactive[0][0] then local $a_tmp[$a_curractive[0][0]][4] Else local $a_tmp[$a_prevactive[0][0]][4] endif local $a_tmp_curractive = $a_curractive local $a_tmp_prevactive = $a_prevactive _arraysort($a_tmp_curractive) _arraysort($a_tmp_prevactive) for $i = 0 to ubound($a_tmp) - 1 if $i < ubound($a_tmp_curractive) then $a_tmp[$i][0] = $a_tmp_curractive[$i][0] $a_tmp[$i][1] = $a_tmp_curractive[$i][1] EndIf if $i < ubound($a_tmp_prevactive) then $a_tmp[$i][2] = $a_tmp_prevactive[$i][0] $a_tmp[$i][3] = $a_tmp_prevactive[$i][1] endif next _arraydisplay($a_tmp) endfunc Func lf($le) Local $file $file = FileOpen('c:\watcher_event_log', 1) If $file = -1 Then MsgBox(0,"Watcher Error", "Error Unable to open log file") exit EndIf FileWriteLine($file, _Now() & $le) FileClose($file) EndFunc Thanks, Kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
sleepydvdr Posted November 5, 2011 Posted November 5, 2011 The problem lies in the credentials you specify in Task Scheduler. When you specify administrator credentials, it runs your executable as if the administrator executed the program from the administrator account. If you want Ccleaner to run for a specific account, you must specify that account's credentials. #include <ByteMe.au3>
water Posted November 5, 2011 Posted November 5, 2011 A similar questions has been discussed before. Please check this My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
kylomas Posted November 6, 2011 Author Posted November 6, 2011 @sleepydvdr, I figured such, was hoping that I was missing something obvious... @water, Thanks, the example will work perfectly... kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
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