GregThompson Posted January 23, 2006 Posted January 23, 2006 (edited) I manage about 6000 computers in my company and use AutoIT and other tools for various "fill in the gap" solutions that our suite of purchased tools cannot do easily. I'm the king of AD-HOC if you will, anyway, something came up recently with a quick dead-line and I wrote a hunk-o-code that I felt like sharing. I've been using Auto-IT for many many years now and thought I could contribute back a little. The following script is specific to our applications, however it utilizes MS BITS which is new territory for me. MS BITS, if you're not familiar is a fancy way of saying checkpoint restart for downloads. IE... if your download gets cut off, BITS will resume it where it left off. The code is a bit bloated with our specific needs, which may or may not be of use to the community, but what the script does is the following:Check for a piece of software. If it exists already, exit.Checks if you've already got the full download. If you do, it runs it.Unpacks bitsadminGenerates the bitsadmin listChecks the state of the download, and processes accordingly in a loop until the download is complete or errors outUnpacks the downloaded fileDisconnects our VPN software. IF it's runningDisconnects any RAS connectionsSilently uninstalls 2 possible versions of our old dialer softwareSilently (almost) installs the newly downloaded dialer software. Screw iPass for putting in a proprietary screen that HAD to have a check box and mouse click that InstallShield couldn't record in the .iss file!Confirms via msgbox installation complete.Hope this helps someone somewhere using BITS for downloads. expandcollapse popupOpt("TrayAutoPause",0) Opt("TrayMenuMode",1) $reginstalled = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{AB6FFA58-F491-11D3-8951-000000030169}", "UninstallString") If $reginstalled <> "" Then MsgBox(48, "Installation Detected", "The Installer has detected a previous installation of the same iPass Client, aborting install.") Exit EndIf TrayTip("Installing iPass Dialer", "Creating Directory", 1, 1) Sleep(2000) $count = 0 $temp = @TempDir & "\avedaipass\"; Set our temp variable DirCreate($temp); Create our temp dir TrayTip("Installing iPass Dialer", "Checking File Size", 1, 1) Sleep(2000) $size = FileGetSize($temp & "EsteeLauderIPassver30169.exe") If $size = "8271638" Then Install() FileInstall("Z:\NewSprint\RAW\bitsadmin.exe", $temp & "bitsadmin.exe", 1); Pull in bitsadmin.exe Do TrayTip("Installing iPass Dialer", "Checking State/Downloading", 1, 1) Sleep(2000) RunWait(@ComSpec & " /c bitsadmin /getstate iPass > " & $temp & "state.txt", $temp, @SW_HIDE) $statefile = FileOpen($temp & "state.txt", 0) If $statefile = -1 Then Exit EndIf While 1 $state = FileReadLine($statefile, 6) If @error = -1 Then ExitLoop If $state = "TRANSFERRED" Then RunWait(@ComSpec & " /c bitsadmin /complete iPass", $temp, @SW_HIDE) ExitLoop EndIf If $state = "CONNECTING" OR $state = "TRANSFERRING" Then ExitLoop If $state = 'Unable to find job named "iPass".' Then RunWait(@ComSpec & " /c bitsadmin /create iPass", $temp, @SW_HIDE) RunWait(@ComSpec & " /c bitsadmin /addfile iPass http://us-rp-mgmt06/EsteeLauderIPassver30169.exe " & $temp & "EsteeLauderIPassver30169.exe", $temp, @SW_HIDE) RunWait(@ComSpec & " /c bitsadmin /resume iPass", $temp, @SW_HIDE) ExitLoop EndIf If $state = "SUSPENDED" OR $state = "TRANSIENT_ERROR" OR $state = "ERROR" Then RunWait(@ComSpec & " /c bitsadmin /resume iPass", $temp, @SW_HIDE) $count = $count + 1 If $count >= 100 Then MsgBox(16, "Lost Connection", "It appears you have lost connection to the server, please reconnect and download the Installer file again. It will start from where it left off.") FileClose($statefile) Exit EndIf ExitLoop EndIf Wend FileClose($statefile) Until $state = "TRANSFERRED" Install() Func Install() TrayTip("Installing iPass Dialer", "Unpacking Files", 1, 1) Sleep(2000) RunWait($temp & "EsteeLauderIPassver30169.exe"); Unpack the AutoIT script holding the files for install TrayTip("Installing iPass Dialer", "Closing Connections", 1, 1) Sleep(2000) If ProcessExists("Extranet.exe") OR ProcessExists("Extranet_Serv.exe") Then; Disconnect VPN if Running $nortend = $temp & "nortend.exe" Run($nortend, $temp, @SW_HIDE) Sleep(3000) EndIf Run(@ComSpec & " /c " & "rasdial /disconnect", @WindowsDir & "\System32", @SW_HIDE); Disconnect the Dialer $regaveda = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{AB6FFA58-F491-11D3-8951-000000014460}", "UninstallString") $regestee = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{AB6FFA58-F491-11D3-8951-000000015000}", "UninstallString") TrayTip("Installing iPass Dialer", "Uninstalling old Client(s)", 1, 1) Sleep(2000) If $regaveda <> "" Then RunWait($regaveda & " /s /f1" & $temp & "un14460.iss") If $regestee <> "" Then RunWait($regestee & " /s /f1" & $temp & "un15000.iss") TrayTip("Installing iPass Dialer", "Installing new iPass Client", 1, 1) Sleep(2000) Run($temp & "setup.exe /s /f1" & $temp & "setup.iss"); Run install BlockInput(1); Block User Input TrayTip("Installing iPass Dialer", "Checking Processes", 1, 1); Wait for self closure in case it's already installed Sleep(3000) If NOT ProcessExists("setup.exe") Then; If self closure occurs, prompt user as such BlockInput(0) MsgBox(16, "Current Installation Found", "It appears you already have a similar installation of iPass, please uninstall it before continuing.") Exit EndIf WinWait("iPassConnect Estee Lauder Companies Inc Dialer setup"); Activate the setup WinActivate("iPassConnect Estee Lauder Companies Inc Dialer setup") Sleep(50) Send("{SHIFTDOWN}") Send("{TAB}") Send("{SHIFTUP}") Sleep(50) Send("{SPACE}") Sleep(50) Send("y") BlockInput(0) While ProcessExists("setup.exe") TrayTip("Installing iPass Dialer", "Please wait", 1, 1) Wend MsgBox(64, "Installation Complete", "The installation is complete.") Exit EndFunc Edited January 23, 2006 by GregThompson
GregThompson Posted January 24, 2006 Author Posted January 24, 2006 Nothing huh? FYI: The sad/crying emoticon is broken if you try and click it... Code is: javascript:emoticon(":'(", Should be: javascript:emoticon(':'(', 'smid_4')
Sandman2672 Posted January 24, 2006 Posted January 24, 2006 Awesome script. We use ipass too! I was curious whether or not it was possible to use bits for things like this. I have to copy files back and forth to branches all the time over unreliable circuits. First I have ever heard of the bitsadmin.exe. I will have to search for more info on how to use it. Have you tried using it with a UNC path or will it only work with HTTP? I am the AD-Hoc king where I work as well. We have a Cisco vpn solution, very messy to upgrade. Thanks for contributing your script. Sandman
GregThompson Posted January 24, 2006 Author Posted January 24, 2006 (edited) Awesome script. We use ipass too! I was curious whether or not it was possible to use bits for things like this. I have to copy files back and forth to branches all the time over unreliable circuits. First I have ever heard of the bitsadmin.exe. I will have to search for more info on how to use it. Have you tried using it with a UNC path or will it only work with HTTP? I am the AD-Hoc king where I work as well. We have a Cisco vpn solution, very messy to upgrade. Thanks for contributing your script. Sandman You can get bitsadmin.exe as part of the Support Tools pack. (http://www.microsoft.com/downloads/details...en&Hash=W9VR8F8) I just tried a UNC path, it worked perfectly! Here is the bitsadmin /? it helped me a ton. expandcollapse popupBITSADMIN version 2.0 [ 6.6.2600.2180 ] BITS administration utility. © Copyright 2000-2004 Microsoft Corp. USAGE: BITSADMIN [/RAWRETURN] [/WRAP | /NOWRAP] command The following commands are available: /HELP Prints this help /? Prints this help /UTIL /? Prints the list of utilities commands /LIST [/ALLUSERS] [/VERBOSE] List the jobs /MONITOR [/ALLUSERS] [/REFRESH sec] Monitors the copy manager /RESET [/ALLUSERS] Deletes all jobs in the manager /TRANSFER name [type] [/PRIORITY priority] [/ACLFLAGS flags] remote_url local_name Transfers one of more files. [type] may be /DOWNLOAD or /UPLOAD; default is download Multiple URL/file pairs may be specified. /CREATE [type] display_name Creates a job [type] may be /DOWNLOAD, /UPLOAD, or /UPLOAD-REPLY; default is download /INFO job [/VERBOSE] Displays information about the job /ADDFILE job remote_url local_name Adds a file to the job /ADDFILESET job textfile Adds multiple files to the job Each line of <textfile> lists a file's remote name and local name, separated by spaces. A line beginning with '#' is treated as a comment. Once the file set is read into memory, the contents are added to the job. /ADDFILEWITHRANGES job remote_url local_name range_list Like /ADDFILE, but BITS will read only selected byte ranges of the URL. range_list is a comma-delimited series of offset and length pairs. For example, 0:100,2000:100,5000:eof instructs BITS to read 100 bytes starting at offset zero, 100 bytes starting at offset 2000, and the remainder of the URL starting at offset 5000. /REPLACEREMOTEPREFIX job old_prefix new_prefix All files whose URL begins with <old_prefix> are changed to use <new_prefix> /LISTFILES job Lists the files in the job /SUSPEND job Suspends the job /RESUME job Resumes the job /CANCEL job Cancels the job /COMPLETE job Completes the job /GETTYPE job Retrieves the job type /GETACLFLAGS job Retrieves the ACL propagation flags /SETACLFLAGS job ACL_flags Sets the ACL propagation flags for the job O - OWNER G - GROUP D - DACL S - SACL Examples: bitsadmin /setaclflags MyJob OGDS bitsadmin /setaclflags MyJob OGD /GETBYTESTOTAL job Retrieves the size of the job /GETBYTESTRANSFERRED job Retrieves the number of bytes transferred /GETFILESTOTAL job Retrieves the number of files in the job /GETFILESTRANSFERRED job Retrieves the number of files transferred /GETCREATIONTIME job Retrieves the job creation time /GETMODIFICATIONTIME job Retrieves the job modification time /GETCOMPLETIONTIME job Retrieves the job completion time /GETSTATE job Retrieves the job state /GETERROR job Retrieves detailed error information /GETOWNER job Retrieves the job owner /GETDISPLAYNAME job Retrieves the job display name /SETDISPLAYNAME job display_name Sets the job display name /GETDESCRIPTION job Retrieves the job description /SETDESCRIPTION job description Sets the job description /GETPRIORITY job Retrieves the job priority /SETPRIORITY job priority Sets the job priority /GETNOTIFYFLAGS job Retrieves the notify flags /SETNOTIFYFLAGS job notify_flags Sets the notify flags /GETNOTIFYINTERFACE job Determines if notify interface is registered /GETMINRETRYDELAY job Retrieves the retry delay in seconds /SETMINRETRYDELAY job retry_delay Sets the retry delay in seconds /GETNOPROGRESSTIMEOUT job Retrieves the no progress timeout in seconds /SETNOPROGRESSTIMEOUT job timeout Sets the no progress timeout in seconds /GETERRORCOUNT job Retrieves an error count for the job /SETPROXYSETTINGS job <usage> Sets the proxy usage usage choices: PRECONFIG - Use the owner's IE defaults. AUTODETECT - Force autodetection of proxy. NO_PROXY - Do not use a proxy server. OVERRIDE - Use an explicit proxy list and bypass list. Must be followed by a proxy list and a proxy bypass list. NULL or "" may be used for an empty proxy bypass list. Examples: bitsadmin /setproxysettings MyJob PRECONFIG bitsadmin /setproxysettings MyJob AUTODETECT bitsadmin /setproxysettings MyJob NO_PROXY bitsadmin /setproxysettings MyJob OVERRIDE proxy1:80 "<local>" bitsadmin /setproxysettings MyJob OVERRIDE proxy1,proxy2,proxy3 NULL /GETPROXYUSAGE job Retrieves the proxy usage setting /GETPROXYLIST job Retrieves the proxy list /GETPROXYBYPASSLIST job Retrieves the proxy bypass list /TAKEOWNERSHIP job Take ownership of the job /SETNOTIFYCMDLINE job program_name [program_parameters] Sets a program to execute for notification, and optionally parameters. The program name and parameters can be NULL. IMPORTANT: if parameters are non-NULL, then the program name should be the first parameter. Examples: bitsadmin /SetNotifyCmdLine MyJob c:\winnt\system32\notepad.exe NULL bitsadmin /SetNotifyCmdLine MyJob c:\foo.exe "c:\foo.exe parm1 parm2" bitsadmin /SetNotifyCmdLine MyJob NULL NULL /GETNOTIFYCMDLINE job returns the job's notification command line /SETCREDENTIALS job <target> <scheme> <username> <password> Adds credentials to a job. <target> may be either SERVER or PROXY <scheme> may be BASIC, DIGEST, NTLM, NEGOTIATE, or PASSPORT. /REMOVECREDENTIALS job <target> <scheme> Removes credentials from a job. The following options are valid for UPLOAD-REPLY jobs only: /GETREPLYFILENAME job Gets the path of the file containing the server reply /SETREPLYFILENAME job path Sets the path of the file containing the server reply /GETREPLYPROGRESS job Gets the size and progress of the server reply /GETREPLYDATA job Dumps the server's reply data in hex format The following options can be placed before the command: /RAWRETURN Return data more suitable for parsing /WRAP Wrap output around console (default) /NOWRAP Don't wrap output around console The /RAWRETURN option strips new line characters and formatting. It is recognized by the /CREATE and /GET* commands. Commands that take a job parameter will accept either a job name or a job-ID GUID inside braces. BITSADMIN reports an error if a name is ambiguous. Edited January 24, 2006 by GregThompson
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