Sign in to follow this  
Followers 0
dirtymafia

URL logger2

5 posts in this topic

#1 ·  Posted (edited)

Here is what I have so far. It works. Just looking for ways to make it more simple, or not use so many resources, seems like it uses about 8% cpu right now. Would only like constructive criticism, please don't just post crap.

Thanks!

CODE

; ----------------------------------------------------------------------------

;

; AutoIt Version: 3.1.1.126

; Author: dirtymafia<dirtymafia@gmail.com>

;

; Description:

; Logs urls visited, when IE opens, and when IE closes.

; ini file optional -- [iNI file explanation to be added later]

;

; [more to be added later]

;

;

; ----------------------------------------------------------------------------

;/// Load include files

#include<ie.au3>

#include<date.au3>

#include<file.au3>

;/// Set options needed

_IEErrorHandlerRegister() ;disable ie UDF's from exiting program

Opt("WinTitleMatchMode", 2) ;match title on sub-string

;Opt("TrayIconHide", 1) ;hide tray icon

;/// Set variables

$inipath = @scriptdir & "\" & "start.ini"

$inifile = loadini($inipath)

global $title = iniread($inifile,"Standard","Title","Microsoft Internet Explorer");title to match for IE/browser

global $logpath = iniread($inifile,"Standard","LogPath",@scriptdir & "\") ;logpath (without log filename)

global $logfile = $logpath & @YEAR & "-" & @MON & "-" & @MDAY & "_" & @ComputerName & "_" & @UserName & ".log";log filename

global $lognumb = iniread($inifile,"Standard","LogNumb","14") ;number of days to keep logs

$url1 = ''

$ieexist = 0

logcleanup()

$daycalc = _nowcalc();start daycalc on todays date --used for knowing when to run logcleanup or change date on current .log

;/// Main loop

While 1

If _datediff('D',$daycalc,_NowCalc()) >= 1 Then $daycalc = daychange()

sleep(200)

IF Winexists($title) Then

if $ieexist = 0 Then

writelog("IE Start")

$ieexist = 1

EndIf

$hwnd = wingethandle($title)

$urlgrab = geturl($hwnd)

If $urlgrab <> $url1 Then

writelog($urlgrab)

;msgbox(0,"",$urlgrab);--debugger only--used for testing to make sure URL is grabbed

$url1 = $urlgrab

EndIf

else

if $ieexist = 1 Then

writelog("IE Exit")

$ieexist = 0

$url1 = ''

EndIf

EndIf

WEnd

;/// Things to do when day has changed

Func daychange()

$logfile = $logpath & @YEAR & "-" & @MON & "-" & @MDAY & "_" & @ComputerName & "_" & @UserName & ".log"

logcleanup()

return(_Nowcalc())

EndFunc

;/// check ini file and return path/filename.ini if exists

Func loadini($path)

If fileexists($path) = 1 Then return($path)

EndFunc

;/// trim up logs so that only $lognumb exist

Func logcleanup()

$logfilelist = _FilelistToArray($logpath,"*.log",1)

If Not IsArray($logFileList) Then

;MsgBox (0,"","No Files\Folders Found.")

Elseif IsArray($logfilelist) Then

If $logfilelist[0] > $lognumb Then

For $n = 1 to $logfilelist[0]

$split = stringsplit($logfilelist[$n],"_")

$fdate = $split[1]

$datesp = stringsplit($fdate,"-")

$year = $datesp[1]

$month = $datesp[2]

$day = $datesp[3]

$daydiff = _datediff('D',$year & "/" & $month & "/" & $day & " 00:00:00",_NowCalc())

If $daydiff >= $LogNumb then

filedelete($logpath & $logfilelist[$n])

EndIf

Next

EndIf

EndIf

EndFunc

;/// grab url from IE window

Func geturl($hwnd)

$oIE = ''

$url = ''

$oIE = _IEAttach ($hwnd,"hwnd")

$url = _IEpropertyget($oIE,"locationurl")

return($url)

EndFunc

;/// write passed argument to log

Func writelog($logtxt)

$log = FileOpen($logfile,1)

Filewrite($log, @HOUR & ":" & @MIN & ":" & @SEC & " " & $logtxt & @CRLF)

fileclose($log)

EndFunc

Edited by dirtymafia

Share this post


Link to post
Share on other sites



Anyone got any suggestions to make this more effecient? Or should this be moved to scripts/scraps.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

My gut feeling is that you can optimize your script considerably by exploringe the other options in the Win* function family.

testWindowsChange()
Exit
; ========================================
Func testWindowsChange()
    Local $count = 0, $orgWinTitleMatchMode, $lastTitle
    $orgWinTitleMatchMode = Opt("WinTitleMatchMode", 1)
    $lastTitle = WinGetTitle('')
        TrayTip("CHANGED TO: ", $lastTitle ,0)
    ConsoleWrite("CUREENT: " & $lastTitle & @LF)
    While $count < 10
        WinWaitNotActive($lastTitle)
        $lastTitle = WinGetTitle('')
                TrayTip("CHANGED TO: ", $lastTitle ,0)
        ConsoleWrite("CHANGED TO: " & $lastTitle & @LF)
        $count += 1
    WEnd 
    Opt("WinTitleMatchMode", $orgWinTitleMatchMode)
    Return 1
EndFunc

EDIT: Added TrayTip code

Edited by Uten

Share this post


Link to post
Share on other sites

Hmmm, not sure what your going at with all that...but ok.

Does anyone have any other ideas/suggestions. I need to put this little thing to work and I want to be sure it's going to be working properly. I'm not the best coder and just want someone to look over it to make sure it looks like it should and that it looks like it will run properly for some time.

Thanks.

Share this post


Link to post
Share on other sites

...or not use so many resources...

Just try it out and see your cpu usage decrease, that's what was asked for was it not?

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0