Jump to content

howdy all, autoit script questions here.


Recommended Posts

hey all.

I am using Autoit to make a script that will run "Belarc" and "SIW".

I have gotten it to run and it does that just fine ( at least on my xp test VM ), I will be testing it on other platforms shortly ( once I find the time to install the additional VM's )

but my primary questions would be...

1. does my code make sense or am I just lucky that it works. any changes someone would think of please tell me :huh2:.

2. I want to add 2 simple tasks, A. zip up the 2 results file, and B. email the zipped results them out.

for the zip and email I would like to use as basic of a code as I can, ideal a single run cmd for the zip and another for the email, with no usermade functions ect...

however I can not get 7za to execute with the run cmd. so...

anyways here is the code. I will add what I have tried for the zipping later today if I can get to it.

$oktorun = MsgBox(4132, "blah blah blah", "blah blah blah blah blah blah blah blah blah?", 20)
if $oktorun = 7 Then
    Exit
EndIf
if $oktorun = 6 Then
SplashTextOn("blah", "blah blah blah."& @LF & @LF &"blah blah blah blah blah blah blah blah blah." & @LF & @LF & "blah blah blah.", 480, 150, -1, 1, -1, "", 12)
Sleep(1000)
DirCreate(@ScriptDir & "\LOG")
run(@ScriptDir & "\Belarc.exe" & " /s", "", @SW_HIDE)
AutoItSetOption("WinTitleMatchMode",3)
winwait("Belarc Analysis - Check for New Definitions")
WinSetState("Belarc Analysis - Check for New Definitions", "", @SW_HIDE)
Sleep(5000)
ControlClick("Belarc Analysis - Check for New Definitions", "", "Button1", "Primary")
WinSetState("Belarc Analysis", "", @SW_HIDE)
winwait("Belarc Analysis - Download New Definitions")
WinSetState("Belarc Analysis - Download New Definitions", "", @SW_HIDE)
Sleep(5000)
ControlClick("Belarc Analysis - Download New Definitions", "", "Button1", "Primary")
WinSetState("Belarc Analysis", "", @SW_HIDE)
WinWait("Advisor")
WinSetState("Advisor", "", @SW_HIDE)
sleep(5000)
controlclick("Advisor", "", "Button1", "Primary")
sleep(100)
winwait("Belarc Analysis")
WinSetState("Belarc Analysis", "", @SW_HIDE)
sleep(500)
winwait("Belarc Analysis")
WinSetState("Belarc Analysis", "", @SW_HIDE)
AutoItSetOption("WinTitleMatchMode",2)
winwait("Belarc Advisor Current Profile")
WinSetState("Belarc Advisor Current Profile", "", @SW_HIDE)
sleep(5000)
winclose("Belarc Advisor Current Profile")
Filecopy(@ProgramFilesDir & "\Belarc\Advisor\System\tmp\(" & @ComputerName & ").html", @ScriptDir & "\log\Belarc_" & @YEAR & @MON & @MDAY & "_" & @UserName & "_" & @ComputerName & ".html", 1)
run(@ScriptDir & "\siw.exe" & " /log:html=log/SIW_" & @YEAR & @MON & @MDAY & "_" & @UserName & "_" & @ComputerName, "", @SW_HIDE)
;code to run on vm, siw has an additional popup in this senario.
WinWait("Warning!")
WinSetState("Warning!", "", @SW_HIDE)
sleep(5000)
controlclick("Warning!", "", "Button1")
;end of vm code
winwait("SIW -- Progress")
WinSetState("SIW -- Progress", "", @SW_MINIMIZE)
WinWait("Report")
WinSetState("Report", "", @SW_HIDE)
sleep(5000)
controlclick("Report", "", "Button1")
SplashOff()
EndIf
if $oktorun = -1 Then
SplashTextOn("Expert Solutions Inc", "This Automated Process will take 5-10 minutes to run."& @LF & @LF &"Please do not use your computer till this message disappears!" & @LF & @LF & "Thank you for your time.", 480, 150, -1, 1, -1, "", 12)
Sleep(1000)
DirCreate(@ScriptDir & "\LOG")
run(@ScriptDir & "\Belarc.exe" & " /s", "", @SW_HIDE)
AutoItSetOption("WinTitleMatchMode",3)
winwait("Belarc Analysis - Check for New Definitions")
WinSetState("Belarc Analysis - Check for New Definitions", "", @SW_HIDE)
Sleep(5000)
ControlClick("Belarc Analysis - Check for New Definitions", "", "Button1", "Primary")
WinSetState("Belarc Analysis", "", @SW_HIDE)
winwait("Belarc Analysis - Download New Definitions")
WinSetState("Belarc Analysis - Download New Definitions", "", @SW_HIDE)
Sleep(5000)
ControlClick("Belarc Analysis - Download New Definitions", "", "Button1", "Primary")
WinSetState("Belarc Analysis", "", @SW_HIDE)
WinWait("Advisor")
WinSetState("Advisor", "", @SW_HIDE)
sleep(5000)
controlclick("Advisor", "", "Button1", "Primary")
sleep(100)
winwait("Belarc Analysis")
WinSetState("Belarc Analysis", "", @SW_HIDE)
sleep(500)
winwait("Belarc Analysis")
WinSetState("Belarc Analysis", "", @SW_HIDE)
AutoItSetOption("WinTitleMatchMode",2)
winwait("Belarc Advisor Current Profile")
WinSetState("Belarc Advisor Current Profile", "", @SW_HIDE)
sleep(5000)
winclose("Belarc Advisor Current Profile")
Filecopy(@ProgramFilesDir & "\Belarc\Advisor\System\tmp\(" & @ComputerName & ").html", @ScriptDir & "\log\Belarc_" & @YEAR & @MON & @MDAY & "_" & @UserName & "_" & @ComputerName & ".html", 1)
run(@ScriptDir & "\siw.exe" & " /log:html=log/SIW_" & @YEAR & @MON & @MDAY & "_" & @UserName & "_" & @ComputerName, "", @SW_HIDE)
;code to run on vm, siw has an additional popup in this senario.
WinWait("Warning!")
WinSetState("Warning!", "", @SW_HIDE)
sleep(5000)
controlclick("Warning!", "", "Button1")
;end of vm code
winwait("SIW -- Progress")
WinSetState("SIW -- Progress", "", @SW_MINIMIZE)
WinWait("Report")
WinSetState("Report", "", @SW_HIDE)
sleep(5000)
controlclick("Report", "", "Button1")
SplashOff()
EndIf
exit
Link to comment
Share on other sites

well I found some udf files, but I dont understand about them ( I am not the greatest programmer, hence the request for simple code )

is this udf thing easy to understand ?

also as far as me not being good at code, what ya think of what I wrote already, any issues?

There are several UDFs for ZIP functionality, just use search in Examples forum.

For emails there is SmtpEmail... UDF in examples forum I don't remember its name exactly but search will give it to you.

But it's also possible to some external tools (for ZIP) via its commandline.

Link to comment
Share on other sites

so any ideas about how my code looks anyone ?

the zip and email question are actually secondary, I can puzzle them out. but I just want to make sure I am not doing something stupid coding wise that will bite me later down the road.

Thanks

Bob

Link to comment
Share on other sites

  • 2 years later...

Just in case anybody googles this, here's how I scripted our Belarc to run.  It doesn't include SIW and won't break in the 20+ places the original posters script does.  It does some minor error trapping (will alert you if Belarc changed it's run directory yet again...)

Another big difference is that I don't bother hiding the various windows that pop up.

;#include <IE.au3>
$AutoBelarc = MsgBox(1, "Script will start in 5 seconds", "Locating File: " & @ProgramFilesDir & "\Belarc\BelarcAdvisor\BelarcAdvisor.exe" & @LF & "Locating File: " & @ProgramFilesDir & "\Belarc\Advisor\BelarcAdvisor.exe" & @LF & "Document Folder: " & @MyDocumentsDir, 5)
if $AutoBelarc = 2 Then
    Exit
EndIf
if $AutoBelarc = 1 Then
    $AutoBelarc = -1
EndIf
If $oAutoBelarc = -1 Then
SplashTextOn("MY COMPANY LLC", "The Belarc scan will take approxamately 10 minutes to complete" & @LF & @LF & "Thank you for your patience.", 480, 100, -1, 100, 18, "", 12)
Sleep(100)
If FileExists(@ProgramFilesDir & "\Belarc\BelarcAdvisor\BelarcAdvisor.exe") Then
    run(@ProgramFilesDir & "\Belarc\BelarcAdvisor\BelarcAdvisor.exe", "")
    $path = @ProgramFilesDir & "\Belarc\BelarcAdvisor\"
ElseIf FileExists(@ProgramFilesDir & "\Belarc\Advisor\BelarcAdvisor.exe") Then
    run(@ProgramFilesDir & "\Belarc\Advisor\BelarcAdvisor.exe", "")
    $path = @ProgramFilesDir & "\Belarc\Advisor\"
Else
    MsgBox(0, "No Belarc Advisor found", "Belarc has not been found in default paths." & @LF & @LF & "Please contact xyz@abc.com for custom install.")
    SplashOff()
    Exit
EndIf
AutoItSetOption("WinTitleMatchMode",3)
WinWait("Advisor", "", 60)
WinActivate("Advisor")
ControlClick("Advisor", "", "[ID:2]")
AutoItSetOption("WinTitleMatchMode",2)
WinWait("Belarc Advisor Computer Profile")
;$oIE = _IEAttach("Belarc", "text")
Sleep(300)
FileCopy($path & "\System\tmp\(" & @ComputerName & ").html", @MyDocumentsDir & "\Belarc\" & @YEAR & "\" & @ComputerName & "-" & @YEAR & "-" & @MON & ".html", 9)
;_IEQuit($oIE)
SplashOff()
EndIf
exit
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...