Jump to content

Script Review


 Share

Recommended Posts

Quote

Hey guys, I'm working on a pretty long script to automate the download and activation of a PDF editor called Nitro. I'm trying to implement my own error checks to stop the script if a window opens that shouldn't, incorrect clicks are selected, or whatever it could be. You can probably imagine that with a script like this a lot can go wrong without it necessarily being a syntax issue. I apologize for posting so much code and this isn't a hugely pressing matter, but if you have any tips at all for me I would greatly appreciate it. Thanks!

P.S. This script pulls from a server, so if you try to run it to see how it works, it won't run. It runs well on the computers I've tested so far, but it still has some kinks I'm trying to iron out.

Quote
#include <MsgBoxConstants.au3>
#include <StringConstants.au3>
#include <IE.au3>

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

; Asks for Admin Permission
#RequireAdmin

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

; Alerts User of the Start of the Installation
MsgBox ($MB_SYSTEMMODAL, 'Nitro Installation', 'Welcome to the Nitro 12 automatic installer. During the course of this installation, please do not move the mouse or keyboard unless prompted, and be aware of white text boxes that are used to pause the process. Read directions carefully, and when the installation is complete, a text box will appear to alert you. Select OK to begin.')
WinWaitClose('Nitro Installation')

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

; Opens Nitro Installer
Run('c:\windows\system32\rundll32.exe shell32.dll,#61')
$error = WinWaitActive('Run', '', 15)
if $error == 0 then 
MsgBox ($MB_OK, 'Error', 'An error occured during automation. The process was not completed. Please try again. ')
exit
endif
Send('\\us-lanhdd\software\Nitro-pdf\12.0.0.112\nitro_pro12_x64.msi')
Send('{ENTER}')

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

; Installs and Opens Nitro
$error = WinWaitActive('Open File - Security Warning', '', 15)
if $error == 0 then 
MsgBox ($MB_OK, 'Error', 'An error occured during automation. The process was not completed. Please try again. ')
exit
endif
Sleep(3000)
Send('!R')
Sleep(5000)
$error = WinWaitActive('Nitro Pro Setup', '', 15)
if $error == 0 then 
MsgBox ($MB_OK, 'Error', 'An error occured during automation. The process was not completed. Please try again. ')
exit
endif
Sleep(400)
Send('{TAB 3}')
Sleep(400)
Send('{SPACE}')
Sleep(400)
Send('{TAB}')
Sleep(400)
Send('{SPACE}')
Sleep(200)
Send('{TAB}')
Sleep(1500)
Send('!I')
Sleep(200)
Send('!I')
Sleep(200)
Send('!I')
Sleep(21000)
$error = WinWaitActive('Nitro Pro Setup', '', 15)
if $error == 0 then 
MsgBox ($MB_OK, 'Error', 'An error occured during automation. The process was not completed. Please try again. ')
exit
endif
Send('!F')
Sleep(3000)

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

; Lets Get Productive & Default App Window
WinActivate('Welcome to Nitro Pro')
$vTex2 = WinGetText('Welcome to Nitro Pro')
$devicePos4 = StringInStr ($vTex2, 'Start Free Trial')
if $devicePos4 = '' then

;If Window does not Show
$error = WinWaitActive('Nitro Pro', '', 5)
if $error == 0 then 
MsgBox ($MB_OK, 'Error', 'An error occured during automation. The process was not completed. Please try again. ')
exit
endif
Sleep(1000)
$error = WinWaitActive('Nitro Pro', '', 5)
if $error == 0 then 
MsgBox ($MB_OK, 'Error', 'An error occured during automation. The process was not completed. Please try again. ')
exit
endif
Send('{SPACE}')
Send('{TAB}')
Send('{ENTER}')
MsgBox ($MB_SYSTEMMODAL, 'Pause', 'First, select OK on the blue window that has appeared. Then, select OK on this window to continue.')
WinWaitClose('Pause')

else

;If Window Appears
MsgBox($MB_SYSTEMMODAL, 'Welcome Window', "Select 'Let's get productive' on the 'Welcome to Nitro Pro' Window AFTER selecting OK on this window to continue")
WinWaitClose('Welcome Window')
$error = WinWaitActive('Nitro Pro', '', 5)
if $error == 0 then 
MsgBox ($MB_OK, 'Error', 'An error occured during automation. The process was not completed. Please try again. ')
exit
endif
Sleep(1000)
$error = WinWaitActive('Nitro Pro', '', 5)
if $error == 0 then 
MsgBox ($MB_OK, 'Error', 'An error occured during automation. The process was not completed. Please try again. ')
exit
endif
Send('{SPACE}')
Send('{TAB}')
Send('{ENTER}')
MsgBox ($MB_SYSTEMMODAL, 'Pause', 'First, select OK on the blue window that has appeared. Then, select OK on this window to continue.')
WinWaitClose('Pause')
Sleep(300)
;WinWaitActive('Welcome to Nitro Pro')
ProcessClose('NitroPDF.exe')
Run('NitroPDF.exe')
Sleep(3000)
ShellExecute('NitroPDF.exe')
endif

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

; Opens Advanced Activation Settings
$error2 = WinWaitActive('Nitro Pro', '', 5)
if $error2 == 0 then 
MsgBox ($MB_OK, 'Error', 'An error occured during automation. The process was not completed. Please try again. ')
exit
endif
Sleep(1000)
Send('!p')
Sleep(1000)
Send('!i')
$error = WinWaitActive('Nitro Pro Activation Assistant', '', 5)
if $error == 0 then 
MsgBox ($MB_OK, 'Error', 'An error occured during automation. The process was not completed. Please try again. ')
exit
endif
Sleep(500)
;On my computer, the command below is only 2 tabs. I think it's because it's an expired tiral rather than in trial mode.
if WinExists ('Nitro Pro (Expired Trial)') then 
Send('{TAB 2}')
else
Send('{TAB 3}')
endif
Sleep(500)
Send('{ENTER}')

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

; Pulls the Computer ID
WinActivate('Nitro Pro Activation Assistant')
WinWaitActive('Nitro Pro Activation Assistant')
$vText = WinGetText('Nitro Pro Activation Assistant')
;Find the position of the Device Name within the visible text string
$devicePos = StringInStr ($vText, 'Status')
;Find the actual device name using the device position.
$newDevicePosition = $devicePos + 39
$deviceName = StringMid( $vText, $newDevicePosition, 25 )

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

; Opens a Shared Word Doc to Store the Computer ID
Sleep(100)
Run('c:\windows\system32\rundll32.exe shell32.dll,#61')
$error = WinWaitActive('Run', '', 5)
if $error == 0 then 
MsgBox ($MB_OK, 'Error', 'An error occured during automation. The process was not completed. Please try again. ')
exit
endif
Sleep(100)
Send('F:\Departments\IT\Nitro\V12\AutoNitroComputerIDs.docx')
Sleep(100)
Send('{ENTER}')
Sleep(100)

; If Statement for a New User Attempting to Access Word
$vTex3 = WinGetText('User Name')
$devicePos5 = StringInStr ($vTex3, ',')
if $devicePos5 = '' then
;If Not a New User
$error = WinWaitActive('AutoNitroComputerIDs', '', 5)
if $error == 0 then 
MsgBox ($MB_OK, 'Error', 'An error occured during automation. The process was not completed. Please try again. ')
exit
endif
Sleep(100)
Send('{DOWN 120}')
Sleep(100)
Send('{RIGHT 50}')
Sleep(100)
Send('{ENTER 3}')
Sleep(100)
Send($deviceName)
Sleep(100)
Send('{UP}')
Sleep(100)
Send('{BACKSPACE}')
Sleep(100)
Send('User: ')

else

;New User
Sleep(1000)
WinActivate('User Name')
Sleep(300)
Send('{ENTER}')
$error = WinWaitActive('AutoNitroComputerIDs', '', 5)
if $error == 0 then 
MsgBox ($MB_OK, 'Error', 'An error occured during automation. The process was not completed. Please try again. ')
exit
endif
Sleep(100)
Send('{DOWN 120}')
Sleep(100)
Send('{RIGHT 50}')
Sleep(100)
Send('{ENTER 3}')
Sleep(100)
Send($deviceName)
Sleep(100)
Send('{UP}')
Sleep(100)
Send('{BACKSPACE}')
Sleep(100)
Send('User: ')

endif

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

; Opens Dialogue Box to Pause Automation
MsgBox ($MB_SYSTEMMODAL, 'Username Check', 'Please enter the name of the user into the open document, then save and close. When you are ready to continue the automation, select OK.')
WinWaitClose('Username Check')
WinActivate('Nitro Pro Activation Assistant')

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

; Navigates Through Windows, Enters Serial Number
Send('{ENTER}')

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

; Pulls the Installation ID
WinActivate('Nitro Pro Activation Assistant')
WinWaitActive('Nitro Pro Activation Assistant')
$kText = WinGetText('Nitro Pro Activation Assistant')
;Find the position of the Device Name within the visible text string
$devPos = StringInStr ($kText, 'below:')
;Find the actual device name using the device position.
$newDevPosition = $devPos + 7
$devName = StringMid( $kText, $newDevPosition, 32 )

Sleep(300)
Send('{ENTER}')
Sleep(300)
Send('{ENTER}')
Sleep(300)
Send('234600021793050040')
Send('{TAB}')
Sleep(500)
Send('+{TAB}')

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

; Opens Nitro Activation URL in Default Browser
ShellExecute('https://www.internetactivation.com/ECOSYSTEM/ActivationServer/tiactivate/default.aspx')
Sleep(3000)

; Different Actions depending on Chrome or IE as Default Browser
$vBrowser = WinActivate('Activate - Google Chrome')

if $vBrowser == 0 then
; Internet Explorer

$error = WinWaitActive('Activate - Internet Explorer', '', 5)
if $error == 0 then 
MsgBox ($MB_OK, 'Error', 'An error occured during automation. The process was not completed. Verify that the default browser is Internet Explorer and try again. ')
exit
endif
ProcessClose('iexplore.exe')
Sleep(2000)
$brow = _IECreate('https://www.internetactivation.com/ECOSYSTEM/ActivationServer/tiactivate/default.aspx')
_IELoadWait($brow)

;Enters Installation ID
$oForm1 = _IEFormGetObjByName($brow, 'form1')
$oQuery1 = _IEFormElementGetObjByName($oForm1, 'sitecode')
_IEFormElementSetValue($oQuery1, $devName)

;Enters License Number
$oForm2 = _IEFormGetObjByName($brow, 'form1')
$oQuery2 = _IEFormElementGetObjByName($oForm2, 'serial')
_IEFormElementSetValue($oQuery2, '234600021793050040')

;Checks the Terms and Conditions Box
$oForm3 = _IEFormGetObjByName($brow, "form1")
_IEFormElementCheckBoxSelect($oForm3, 'agreed')

;Clicks the Generate Unlock Code/Certificate Box
$oSubmit = _IEGetObjByName($brow, 'activatebutton')
_IEAction($oSubmit, 'click')

Sleep(5000)
$oIE = _IEAttach("Activate")
$sHTML = _IEDocReadHTML($oIE)

;Find the position of the Device Name within the visible text string
$devicePos2 = StringInStr ($sHTML, '"readonly">')

;Find the actual device name using the device position.
$newDevicePosition2 = ($devicePos2 + 11)
$deviceName2 = StringMid($sHTML, $newDevicePosition2, 187)

; Activates Nitro
WinActivate('Nitro Pro Activation Assistant')
Send($deviceName2)
ProcessClose("iexplore.exe")

else
; Google Chrome (DOES NOT WORK AS IS)

$error = WinWaitActive('Activate - Google Chrome', '', 5)
if $error == 0 then 
MsgBox ($MB_OK, 'Error', 'An error occured during automation. The process was not completed. Please try again. ')
exit
endif
Sleep(2000)
Send('{TAB 5}')
Send($devName)
Send('{TAB}')
Send('234600021793050040')
Send('{TAB}')
Send('{SPACE}')
Send('{TAB 2}')
Send('{ENTER}')
Sleep(2000)
Send('^a')
Send('^c')
Sleep(1000)
WinClose('Activate - Google Chrome')

; Activates Nitro
WinActivate('Nitro Pro Activation Assistant')
Send('^v')

endif

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

; Activates Nitro and Closes Windows
ControlClick('Nitro Pro Activation Assistant', '', '[CLASS:Button; INSTANCE:5]')
Send('{TAB 9}')
Send('{ENTER}')

WinActivate('Nitro Pro Activation Assistant')
$vTex = WinGetText('Nitro Pro Activation Assistant')
$devicePos3 = StringInStr ($vTex, 'Error')
if $devicePos3 = '' then

; Closes Nitro Windows
WinClose('Nitro Pro Activation Assistant')
ProcessClose("NitroPDF.exe")

; Adds Nitro to NetApps
Run('c:\windows\system32\rundll32.exe shell32.dll,#61')
$error = WinWaitActive('Run', '', 5)
if $error == 0 then 
MsgBox ($MB_OK, 'Error', 'An error occured during automation. The process was not completed. Please try again. ')
exit
endif
Sleep(300)
Send('C:\Users\Public\Desktop')
Send('{ENTER}')
Sleep(500)
Send('{TAB 7}')
Sleep(100)
Send('{DOWN}')
Sleep(100)
Send('^c')
Sleep(100)
Send('{UP}')
Sleep(100)
Send('{ENTER}')
Sleep(500)
Send('{TAB 9}')
Sleep(100)
Send('^v')
$error = WinWaitActive('Destination Folder Access Denied', '', 5)
if $error == 0 then 
MsgBox ($MB_OK, 'Error', 'An error occured during automation. The process was not completed. Please try again. ')
exit
endif
Send('{ENTER}')
Sleep(2000)
WinClose('NetApps')

; Alerts User that the installation is finished
MsgBox ($MB_SYSTEMMODAL, 'Nitro Installation', 'Your Nitro 12 installation is now complete.')

else
MsgBox ($MB_SYSTEMMODAL, 'Nitro Installation', 'Your Nitro 12 activation has failed.')

endif

 

 

Edited by Mr_Clean
Link to comment
Share on other sites

I would automate the silent installation and not the installation via GUI.
The installation guide describes how to do so.

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

 

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...