Altecice Posted February 17, 2012 Posted February 17, 2012 (edited) Hey guys I have only just started using AutoIt and this is my first batch file ever! I have come across a few problems, I have the vast majority of my script working. My script will install three programs by its self and I then use it to create a report asking for a part number (on the actual laptop) and including it in the report and then save it to the desktop. My trouble is some of my laptops come from the server (PXE image) and have the three programs already installed, Is there some way I can get my script to search for the program(s). Or check to see if a desktop short cut is there and if so skip the installs and just go straight to creating the reports? Through registry search or some sort of file search? All the laptops are running Windows XP Pro and have "User" set as there account info. installed on (C:) Programs: Avast anti virus Open Office VLC Media player (all create desktop short cuts) expandcollapse popup;-----------------part one. - Creates report and saves it - -------------- ;Opens System Information, waits 10 seconds and selects all and copys to clipboard . Send("#r") WinWaitActive("Run") Send("msinfo32{Enter}") WinWaitActive("[CLASS:SysListView32", "", 10) Send("^a") Send("^c") ProcessClose("HelpCtr.exe") ;Opens notepad, pastes clipboard,closes and saves file to desktop as "report.txt" Run("notepad.exe") WinWaitActive("Untitled - Notepad") Send("^v") Send("!f") Send("x") WinWaitActive("Notepad") Send("y") Send("report.txt") Send("{ENTER}") WinWaitClose("Untitled - Notepad") ;Opens an inputbox asking for part number, reopens report.txt, moves data down 2 lines ;adds three titles, pastes the input box data. $Input = InputBox("What is the part number?", "Please Enter the Part Number of the laptop you are working on.", "(Part Number here!)") ShellExecute("C:Documents and SettingsuserDesktopreport.txt") WinWaitActive("report - Notepad") Send("{ENTER}") Send("{ENTER}") Send("{UP}") Send("{UP}") send("----------------- Spec Report----------------- ") Send("{ENTER}") send("http://www.cheaper-laptops.co.uk/") Send("{ENTER}") Send("Part Number:") ControlSend("report", "", "Edit1", $Input) Send("{ENTER}") ;-----------------part two. - Installs three programs - -------------- ;Run("install1.exe") ;WinWaitActive("Installer Language") ;Send("{ENTER}") ;WinWaitActive("VLC media player 1.1.11 Setup") ;Send("{ENTER}") ;WinWaitActive("VLC media player 1.1.11 Setup", "Press Page Down to see the rest of the agreement") ;send("{ENTER}") ;winWaitActive("VLC media player 1.1.11 Setup", "Select the type of install") ;send("{ENTER}") ;winWaitActive("VLC media player 1.1.11 Setup", "Space required") ;send("{ENTER}") ;winWaitActive("VLC media player 1.1.11 Setup", "VLC media player 1.1.11 has been installed") ;send("{ENTER}") ;winWaitActive("VLC media player") ;WinClose("VLC media player") ; ;Run("install2.exe") ;winWaitActive("OpenOffice.org 3.3 Installation Preparation") ;send("{ENTER}") ;winWaitActive("OpenOffice.org 3.3 Installation Preparation", "Space required") ;send("{ENTER}") ;winWaitActive("OpenOffice.org 3.3 - Installation Wizard", "Build contributed in collaboration with the") ;send("{ENTER}") ;winWaitActive("OpenOffice.org 3.3 - Installation Wizard", "Install this application for") ;send("{ENTER}") ;winWaitActive("OpenOffice.org 3.3 - Installation Wizard", "Please select a setup type") ;send("{ENTER}") ;winWaitActive("OpenOffice.org 3.3 - Installation Wizard", "If you want to review or change") ;send("{ENTER}") ;winWaitActive("OpenOffice.org 3.3 - Installation Wizard", "Installation Wizard Completed") ;send("{ENTER}") ; ;Run("install3.exe") ;winWaitActive("avast! Free Antivirus Setup") ;send("{ENTER}") ;winWaitActive("avast! Free Antivirus Setup", "By clicking the Next button") ;send("{ENTER}") ;winWaitActive("avast! Free Antivirus Setup", "We hope the product will serve you well") ;send("{ENTER}") I have searched the forums but not found anything. Currently they are on the same script but I have disabled the installing section (part2) because is know it works and I was working on the report section. (In case your wondering why i have put ; ) Edited February 17, 2012 by Altecice
Moderators JLogan3o13 Posted February 17, 2012 Moderators Posted February 17, 2012 Hi, Altecice, welcome to the forum. There is a couple of way you could accomplish this. If you would like to search for the existence of a shortcut, check out FileExists in the helpfile. If FileExists("my file.txt") Then ;do something here EndIf If you're looking at the registry, you can look for the application's uninstall key (HKLMSOFTWAREMicrosoftWindowsCurrentVersionUninstall). Check out the Reg functions in the helpfile. "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!
Altecice Posted February 17, 2012 Author Posted February 17, 2012 (edited) Thanks for that JLogan3o13. Very helpful . I understand that if will need to use three If loops (as you posted) to check for files but im not sure how i would go about "skipping" that section if the file is there. (To the next program Or If all 3 exist move onto the report section) . Sorry for being such a newb haha. Sorted my code into the proper order expandcollapse popup;-----------------part one. - Installs three programs - -------------- Run("install1.exe") WinWaitActive("Installer Language") Send("{ENTER}") WinWaitActive("VLC media player 1.1.11 Setup") Send("{ENTER}") WinWaitActive("VLC media player 1.1.11 Setup", "Press Page Down to see the rest of the agreement") send("{ENTER}") winWaitActive("VLC media player 1.1.11 Setup", "Select the type of install") send("{ENTER}") winWaitActive("VLC media player 1.1.11 Setup", "Space required") send("{ENTER}") winWaitActive("VLC media player 1.1.11 Setup", "VLC media player 1.1.11 has been installed") send("{ENTER}") winWaitActive("VLC media player") WinClose("VLC media player") Run("install2.exe") winWaitActive("OpenOffice.org 3.3 Installation Preparation") send("{ENTER}") winWaitActive("OpenOffice.org 3.3 Installation Preparation", "Space required") send("{ENTER}") winWaitActive("OpenOffice.org 3.3 - Installation Wizard", "Build contributed in collaboration with the") send("{ENTER}") winWaitActive("OpenOffice.org 3.3 - Installation Wizard", "Install this application for") send("{ENTER}") winWaitActive("OpenOffice.org 3.3 - Installation Wizard", "Please select a setup type") send("{ENTER}") winWaitActive("OpenOffice.org 3.3 - Installation Wizard", "If you want to review or change") send("{ENTER}") winWaitActive("OpenOffice.org 3.3 - Installation Wizard", "Installation Wizard Completed") send("{ENTER}") Run("install3.exe") winWaitActive("avast! Free Antivirus Setup") send("{ENTER}") winWaitActive("avast! Free Antivirus Setup", "By clicking the Next button") send("{ENTER}") winWaitActive("avast! Free Antivirus Setup", "We hope the product will serve you well") send("{ENTER}") ;---------------part one end---------------- ;-----------------part two. - Creates report and saves it - -------------- ;Opens System Information, waits 10 seconds and selects all and copys to clipboard. Send("#r") WinWaitActive("Run") Send("msinfo32{Enter}") WinWaitActive("[CLASS:SysListView32", "", 10) Send("^a") Send("^c") ProcessClose("HelpCtr.exe") ;Opens notepad, pastes clipboard,closes and saves file to desktop as "report.txt" Run("notepad.exe") WinWaitActive("Untitled - Notepad") Send("^v") Send("!f") Send("x") WinWaitActive("Notepad") Send("y") Send("report.txt") Send("{ENTER}") WinWaitClose("Untitled - Notepad") ;Opens an inputbox asking for part number, reopens report.txt, moves data down 2 lines ;adds three titles, pastes the input box data. $Input = InputBox("What is the part number?", "Please Enter the Part Number of the laptop you are working on.", "(Part Number here!)") ShellExecute("C:Documents and SettingsuserDesktopreport.txt") WinWaitActive("report - Notepad") Send("{ENTER}") Send("{ENTER}") Send("{UP}") Send("{UP}") send("----------------- Spec Report----------------- ") Send("{ENTER}") send("http://www.cheaper-laptops.co.uk/") Send("{ENTER}") Send("Part Number:") ControlSend("report", "", "Edit1", $Input) Send("{ENTER}") ;---------------part two end---------------- Edited February 17, 2012 by Altecice
somdcomputerguy Posted February 17, 2012 Posted February 17, 2012 Read thru the Help file, AutoIt, particularly this section - Keyword If...ElseIf...Else...EndIf. - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change.
Altecice Posted February 17, 2012 Author Posted February 17, 2012 (edited) Hey thank you very much for posting that somdcomputerguy. I have edited my script to something that I think would work (i may be wrong). Does this look ok? (I cant check it as I am at my home and my computers are at work >.> expandcollapse popup;-----------------part one. - If loops to check for program installations. - -------------- Global $check1 = "" If FileExists("my file.txt") Then $check1 = "1" EndIf Global $check2 = "" If FileExists("my file.txt") Then $check2 = "1" EndIf Global $check3 = "" If FileExists("my file.txt") Then $check3 = "1" EndIf ;============part one end=========== ;-----------------part two. - If $var = 1 then installs program(s). - -------------- If $check1 = "1" then Run("install1.exe") WinWaitActive("Installer Language") Send("{ENTER}") WinWaitActive("VLC media player 1.1.11 Setup") Send("{ENTER}") WinWaitActive("VLC media player 1.1.11 Setup", "Press Page Down to see the rest of the agreement") send("{ENTER}") winWaitActive("VLC media player 1.1.11 Setup", "Select the type of install") send("{ENTER}") winWaitActive("VLC media player 1.1.11 Setup", "Space required") send("{ENTER}") winWaitActive("VLC media player 1.1.11 Setup", "VLC media player 1.1.11 has been installed") send("{ENTER}") winWaitActive("VLC media player") WinClose("VLC media player") Else EndIf If $check2 = "1" then Run("install2.exe") winWaitActive("OpenOffice.org 3.3 Installation Preparation") send("{ENTER}") winWaitActive("OpenOffice.org 3.3 Installation Preparation", "Space required") send("{ENTER}") winWaitActive("OpenOffice.org 3.3 - Installation Wizard", "Build contributed in collaboration with the") send("{ENTER}") winWaitActive("OpenOffice.org 3.3 - Installation Wizard", "Install this application for") send("{ENTER}") winWaitActive("OpenOffice.org 3.3 - Installation Wizard", "Please select a setup type") send("{ENTER}") winWaitActive("OpenOffice.org 3.3 - Installation Wizard", "If you want to review or change") send("{ENTER}") winWaitActive("OpenOffice.org 3.3 - Installation Wizard", "Installation Wizard Completed") send("{ENTER}") Else EndIf If $check3 = "1" then Run("install3.exe") winWaitActive("avast! Free Antivirus Setup") send("{ENTER}") winWaitActive("avast! Free Antivirus Setup", "By clicking the Next button") send("{ENTER}") winWaitActive("avast! Free Antivirus Setup", "We hope the product will serve you well") send("{ENTER}") Else EndIf ;============part two end=========== ;-----------------part three. - Creates report and saves it - -------------- ;Opens System Information, waits 10 seconds and selects all and copys to clipboard. Send("#r") WinWaitActive("Run") Send("msinfo32{Enter}") WinWaitActive("[CLASS:SysListView32", "", 10) Send("^a") Send("^c") ProcessClose("HelpCtr.exe") ;Opens notepad, pastes clipboard,closes and saves file to desktop as "report.txt" Run("notepad.exe") WinWaitActive("Untitled - Notepad") Send("^v") Send("!f") Send("x") WinWaitActive("Notepad") Send("y") Send("report.txt") Send("{ENTER}") WinWaitClose("Untitled - Notepad") ;Opens an inputbox asking for part number, reopens report.txt, moves data down 2 lines ;adds three titles, pastes the input box data. $Input = InputBox("What is the part number?", "Please Enter the Part Number of the laptop you are working on.", "(Part Number here!)") ShellExecute("C:Documents and SettingsuserDesktopreport.txt") WinWaitActive("report - Notepad") Send("{ENTER}") Send("{ENTER}") Send("{UP}") Send("{UP}") send("----------------- Spec Report----------------- ") Send("{ENTER}") send("http://www.cheaper-laptops.co.uk/") Send("{ENTER}") Send("Part Number:") ControlSend("report", "", "Edit1", $Input) Send("{ENTER}") ;============part two end=========== "My file.txt" is where I will be locating it to the desktop short cut to see if its there (There will be 3 different short cuts hence three FileExists) Edited February 17, 2012 by Altecice
Moderators JLogan3o13 Posted February 17, 2012 Moderators Posted February 17, 2012 Hi, Altecice. May I suggest you look into the silent installation switches for all three applications, so you don't have to bother with the Send commands? This website can be your best friend www.appdeploy.com.I downloaded just the most recent version of all three (I went LibreOffice instead of OpenOffice, but their installs are similar). And would do something like this to cut down on the length of your script.If Not FileExists(@DesktopDir & "avast! Free Antivirus.lnk") Then ShellExecuteWait(@ScriptDir & "setup_av_free_cnet.exe", "/VERYSILENT /norestart") EndIf If Not FileExists(@DesktopDir & "VLC media player.lnk") Then ShellExecuteWait(@ScriptDir & "vlc-1.1.11-win32.exe", "/L=1033 /S") EndIf If Not FileExists(@DesktopDir & "LibreOffice 3.5.lnk") Then ShellExecuteWait("msiexec.exe", '/i "LibO_3.5.0_Win_x86_install_multi.msi" /qn') EndIf "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!
Altecice Posted February 17, 2012 Author Posted February 17, 2012 (edited) Ok guys (sorry for all the posting) I ran the script and it will install VLC fine and when i rerun it it will skip it so i know my $checks are working but i always get an error on line 20 Line 20 (File "E:AITest_2.exe") <---- i compile the script to a exe called test_2.exe and put it on a pen drive. Error: Illegal text at the end of statement (one statement per line)... Line 20 in my code = send("{ENTER}") All my code as it is right now expandcollapse popup;-----------------part one. - If loops to check for program installations. - -------------- Global $check1 = "" If FileExists("C:Program FilesVideoLANVLCvlc.exe") Then $check1 = "1" EndIf If $check1 = "" then Run("install1.exe") WinWaitActive("Installer Language") Send("{ENTER}") WinWaitActive("VLC media player 1.1.11 Setup") Send("{ENTER}") WinWaitActive("VLC media player 1.1.11 Setup", "Press Page Down to see the rest of the agreement") send("{ENTER}") winWaitActive("VLC media player 1.1.11 Setup", "Select the type of install") send("{ENTER}") winWaitActive("VLC media player 1.1.11 Setup", "Space required") send("{ENTER}") winWaitActive("VLC media player 1.1.11 Setup", "VLC media player 1.1.11 has been installed") send("{ENTER}") winWaitActive("VLC media player") WinClose("VLC media player") Else EndIf Global $check2 = "" If FileExists("C:Program FilesOpenOffice.orgprogramsoffice.exe") Then $check2 = "1" EndIf If $check2 = "" then Run("install2.exe") winWaitActive("OpenOffice.org 3.3 Installation Preparation") send("{ENTER}") winWaitActive("OpenOffice.org 3.3 Installation Preparation", "Space required") send("{ENTER}") winWaitActive("OpenOffice.org 3.3 - Installation Wizard", "Build contributed in collaboration with the") send("{ENTER}") winWaitActive("OpenOffice.org 3.3 - Installation Wizard", "Install this application for") send("{ENTER}") winWaitActive("OpenOffice.org 3.3 - Installation Wizard", "Please select a setup type") send("{ENTER}") winWaitActive("OpenOffice.org 3.3 - Installation Wizard", "If you want to review or change") send("{ENTER}") winWaitActive("OpenOffice.org 3.3 - Installation Wizard", "Installation Wizard Completed") send("{ENTER}") Else EndIf Global $check3 = "" If FileExists("C:Program FilesAVAST SoftwareAvastAvastUI.exe") Then $check3 = "1" EndIf If $check3 = "" then Run("install3.exe") winWaitActive("avast! Free Antivirus Setup") send("{ENTER}") winWaitActive("avast! Free Antivirus Setup", "By clicking the Next button") send("{ENTER}") winWaitActive("avast! Free Antivirus Setup", "We hope the product will serve you well") send("{ENTER}") Else EndIf ;============part one end=========== ;-----------------part two. - Creates report and saves it - -------------- ;Opens System Information, waits 10 seconds and selects all and copys to clipboard. Send("#r") WinWaitActive("Run") Send("msinfo32{Enter}") WinWaitActive("[CLASS:SysListView32", "", 10) Send("^a") Send("^c") ProcessClose("HelpCtr.exe") ;Opens notepad, pastes clipboard,closes and saves file to desktop as "report.txt" Run("notepad.exe") WinWaitActive("Untitled - Notepad") Send("^v") Send("!f") Send("x") WinWaitActive("Notepad") Send("y") Send("report.txt") Send("{ENTER}") WinWaitClose("Untitled - Notepad") ;Opens an inputbox asking for part number, reopens report.txt, moves data down 2 lines ;adds three titles, pastes the input box data. $Input = InputBox("What is the part number?", "Please Enter the Part Number of the laptop you are working on.", "(Part Number here!)") ShellExecute("C:Documents and SettingsuserDesktopreport.txt") WinWaitActive("report - Notepad") Send("{ENTER}") Send("{ENTER}") Send("{UP}") Send("{UP}") send("----------------- Spec Report----------------- ") Send("{ENTER}") send("http://www.cheaper-laptops.co.uk/") Send("{ENTER}") Send("Part Number:") ControlSend("report", "", "Edit1", $Input) Send("{ENTER}") ;============part two end=========== Edited February 17, 2012 by Altecice
Moderators JLogan3o13 Posted February 17, 2012 Moderators Posted February 17, 2012 (edited) Hi, Altecice. I see this: WinClose("VLC media player") Else If you have a true "else" statement, it should be: WinClose("VLC media player") Else Otherwise you can get rid of it altogether. Edit: Actually I see a couple examples of you having Else on the same line. If you're using the full version of SciTe, try Ctrl+F5 to check for Syntax errors. Edited February 17, 2012 by JLogan3o13 "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!
Altecice Posted February 17, 2012 Author Posted February 17, 2012 AHHHHH sorry i was being a newb again.... i forgot that comment lines don't count towards code. Your right! I see the problem now. I will just get rid of the Else. dont really need it anyway. Thank you once again
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