dufran3 Posted November 28, 2006 Posted November 28, 2006 (edited) Here is what I am trying to do. I am running a script. The script basically searches for installed versions of a piece of software we use called Star. It finds the uninstall string out of the registry. And then executes that uninstall string for each result it found. Below is my entire script thus far. A message box pops up once the script is executed, and informs that user about what is going to happen. Then they click ok, I then would like this simple GUI to appear. The GUI part is commented out, because as of now, the GUI sits there, and the script pauses until the GUI closes, then proceeds. I would like the GUI to stay open with the message and progress bar, then close when the script is completed. Any help would be greatly appreciated. THX!!!! expandcollapse popup#cs Star House Wide Update Author: ***** Description: The purpose of this script is to apply "House Wide Updates" for Star Navigator. The script will check to see if it has already run on the pc. It will then check for all installed versions of Star and uninstall them all. Then, it will install the most current version of Star and place a shortcut in the "All Users" "Desktop" folder. It writes to a text file that is out on \\fs1 and logs it's computer name along with any logs during the scripting process. It then displays a message when the script is finished. License: This script can be freely copied and distributed, as long as it is not sold for ANY fee (including "distribution" costs.) Any modification to this script must be submitted to the original author if the modified script is distributed in any manner. Any modification must include this header information with this licence, disclaimer and original author information in tact. Disclaimer: The author is not responsible for any damage or harm caused by this script. USE AT YOUR OWN RISK. There is no warranty, express or implied. Revision History 11-02-2006 Version 1.0: -Initial testing 11-03-2006 Version 1.1: -Changed file write to using an Array. #CE ;Includes #include <Process.au3> #include <GuiConstants.au3> ;Hide tray icon #NoTrayIcon ;Variables $FileCheck = '\\fs1\InfoSys\StarTesting\' & @ComputerName & '.txt' ;Check to see if script has run on pc If FileExists($FileCheck) Then Exit EndIf ;-------Informative Message-----------; MsgBox(0,'Star Navigator Maintenance','Mandatory maintenance will be performed to upgrade Star Navigator to the most current version.'& @CRLF & 'This process may take several minutes.'& @CRLF & 'Please do not do anything until the process is complete.',10) ;------End of Message-----------------; #cs ;---------------------------; ; Creating a GUI ; ;---------------------------; $gMain = GUICreate('Star Splash',500,90,-1,-1,$WS_POPUP) GUICtrlSetBkColor($gmain,0xffffff) $time = GUICtrlCreateLabel('Current Time: ' & @HOUR & ':' & @MIN,0,0,150,15) $progress = GUICtrlCreateProgress(105,50,300,25,$PBS_SMOOTH) $ProgressID = GUICtrlRead($progress) GUICtrlSetData(-1, 25) GUISetState(@SW_SHOW) ;GUICtrlSetColor($ProgressID,32250); not working with Windows XP Style GUICtrlCreateLabel('Please wait while Star is updated.',160,20,180,16) ;GUI MESSAGE LOOP GUISetState() While GUIGetMsg() <> $GUI_EVENT_CLOSE WEnd Func SpecialEvents() Select Case @GUI_CtrlId = $GUI_EVENT_CLOSE Exit EndSelect EndFunc ;==>SpecialEvents ;-------------------------------; ; End Of GUI ; ;-------------------------------; #ce ;----------------------------------------------------------- ;Search for any folder in the directory that contains "Star" ;----------------------------------------------------------- ;Search for versions of Star $search = FileFindFirstFile('C:\Program Files\McKesson\Star*') ; Check if the search was successful If $search = -1 Then MsgBox(0, "Error", "No files/directories matched the search pattern") Exit EndIf ;------------------------------------------------------------ ;------------------------------------------------------------- ;Open file and check to see if it opened in a write only state ;------------------------------------------------------------- $FileOpen = FileOpen('\\fs1\InfoSys\StarTesting\' & @ComputerName & '.txt', 1) ; Check if file opened for writing OK If $FileOpen = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf ;------------------------------------------------------------- ;------------------------ ;Write Header on log file ;------------------------ FileWriteLine($FileOpen,'Search Returned:' & @CRLF) FileWriteLine($FileOpen,'----------------' & @CRLF) ;--------------------------------------------------------------------------------- ;Loop goes through each search result returned and writes the name to the log file ;--------------------------------------------------------------------------------- $count = 0 dim $FileArray[50] While 1 $file = FileFindNextFile($search) If @error Then ExitLoop if not (StringInStr($file,"11.15")) then $FileArray[$count]=$file $count = $count + 1 EndIf WEnd $count = $count -1 For $i = 0 to $count step 1 ;MsgBox(0,"","$FileArray[" & $i & "]:" & $FileArray[$i]) FileWriteLine($FileOpen, $FileArray[$i]) Next FileWriteLine($FileOpen, @CRLF) FileClose($FileOpen) ;----------------------------------------------------------------------------------- ;Search through registry for installed versions of Star ;----------------------------------------------------------------------------------- $count = 0 For $i = 0 to $count step 1 SearchDestroyReg('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\','DisplayName',$FileArray[$i]) Next Func SearchDestroyReg($searchpath, $valuename, $searchstring, $specialval = 0) For $i= 1 to 10000 $currentkey = RegEnumKey($searchpath, $i) ;MsgBox(0,'',$currentkey) If @error <> 0 then ExitLoop $displayname = RegRead($searchpath & "\" & $currentkey, $valuename) If $displayname <> '' Then ;MsgBox(0,'',$displayname) EndIf If $displayname == $searchstring Then ;MsgBox(0,'','match') $UninstallString = RegRead($searchpath & $currentkey, "UninstallString") ;MsgBox(0,'',$UninstallString) ;$Uninstall = StringSplit ($UninstallString, " ") ;return $uninstall[2] ;MsgBox(0,'',$Uninstall) If StringInStr($UninstallString,'Msiexec.exe') Then _RunDOS($UninstallString & ' /qn /norestart') While FileExists('C:\Program Files\Mckesson\' & $FileArray[$i] & '\HBOC32\System') Sleep(2000) WEnd EndIf EndIf Next EndFunc ;-------------------------------------------------------------------; ; Searches for files and folders and puts them into seperate arrays ;-------------------------------------------------------------------; #include <array.au3>; Only used for _ArrayDisplay ;Return all files/folders that start with P $a = _FileSearch("C:\Documents and Settings\Star*.lnk",1) ;_ArrayDisplay($a, 'Files and Folders') $b = _FileSearch("C:\Program Files\Mckesson\Star*",0) ;_ArrayDisplay($b, 'Folders') ;-------------------------------------------- ;StringRegExp( Func _FileSearch($szMask,$nOption) $szRoot = "" $hFile = 0 $szBuffer = "" $szReturn = "" $szPathList = "*" Dim $aNULL[1] If Not StringInStr($szMask,"\") Then $szRoot = "C:\" Else While StringInStr($szMask,"\") $szRoot = $szRoot & StringLeft($szMask,StringInStr($szMask,"\")) $szMask = StringTrimLeft($szMask,StringInStr($szMask,"\")) Wend EndIf If $nOption = 0 Then _FileSearchUtil($szRoot, $szMask, $szReturn) Else While 1 $hFile = FileFindFirstFile($szRoot & "*.*") If $hFile >= 0 Then $szBuffer = FileFindNextFile($hFile) While Not @ERROR If $szBuffer <> "." And $szBuffer <> ".." And _ StringInStr(FileGetAttrib($szRoot & $szBuffer),"D") Then _ $szPathList = $szPathList & $szRoot & $szBuffer & "*" $szBuffer = FileFindNextFile($hFile) Wend FileClose($hFile) EndIf _FileSearchUtil($szRoot, $szMask, $szReturn) If $szPathList == "*" Then ExitLoop $szPathList = StringTrimLeft($szPathList,1) $szRoot = StringLeft($szPathList,StringInStr($szPathList,"*")-1) & "\" $szPathList = StringTrimLeft($szPathList,StringInStr($szPathList,"*")-1) Wend EndIf If $szReturn = "" Then $aNULL[0] = 0 Return $aNULL Else Return StringSplit(StringTrimRight($szReturn,1),"*") EndIf EndFunc Func _FileSearchUtil(ByRef $ROOT, ByRef $MASK, ByRef $RETURN) $hFile = FileFindFirstFile($ROOT & $MASK) If $hFile >= 0 Then $szBuffer = FileFindNextFile($hFile) While Not @ERROR If $szBuffer <> "." And $szBuffer <> ".." Then _ $RETURN = $RETURN & $ROOT & $szBuffer & "*" $szBuffer = FileFindNextFile($hFile) Wend FileClose($hFile) EndIf EndFunc $count1 = $a[0] For $i = 0 to $count1 step 1 FileDelete($a[$i]) ;MsgBox(0,'',$a[$i]) Next ;----------------------------------; ; Removed left over Directories ; ;----------------------------------; $count2 = $b[0] For $i = 0 to $count2 step 1 ;MsgBox(0,'',$b[$i]) DirRemove($b[$i],1) Next If FileExists('C:\MckessonHBOC') Then DirRemove('C:\McKessonHBOC',1) EndIf ;End of Removal Process ;=======================================================================================================================================================================; ;-------------------------------------; ; Installing Newest Version of Star ;-------------------------------------; $szGUIRegPath = '\\kmnt2\programs\navrelease\GUI Reg' If FileExists('C:\Temp') Then If FileExists('C:\Temp\McKesson') Then If FileExists('C:\Temp\McKesson\STAR Navigator Setup') Then If FileExists('C:\Temp\McKesson\STAR Navigator Setup\1114') Then FileCopy('\\fs1\IS stuff\NewPC\Automated Installs\Files\Star\STAR Navigator 11.14.msi','C:\Temp\McKesson\STAR Navigator Setup\1114\STAR Navigator 11.14.msi') Else DirCreate('C:\Temp') EndIf Else DirCreate('C:\Temp\McKesson') EndIf Else DirCreate('C:\Temp\McKesson\STAR Navigator Setup') EndIf Else DirCreate('C:\Temp\McKesson\STAR Navigator Setup\1114') EndIf _RunDOS('"C:\Temp\McKesson\STAR Navigator Setup\1114\STAR Navigator 11.14.msi" /qn /norestart') FileCreateShortcut('"C:\Program Files\McKesson\STAR Navigator 11\HBOC32\MckBoot.exe"/nav', @DesktopCommonDir & '\Star Navigator 11.14.lnk','C:\Program Files\McKesson\STAR Navigator 11\hboc32\hbocnav','','','C:\Program Files\McKesson\STAR Navigator 11\HBOC32\HBOCNav\NavigatorX.exe') DirCopy($szGUIRegPath,'C:\Program Files\GUI Reg',1) While Not FileExists('C:\Program Files\McKesson\STAR Navigator 11\HBOC32\MckBoot.exe') Sleep(2000) WEnd MsgBox(0,'','Script is finished',1.5) Edited August 16, 2010 by dufran3
Valuater Posted November 28, 2006 Posted November 28, 2006 maybe... Dim $Plevel = 0, $wait = 3000 ProgressOn("Updating", "Please wait...", 'Current Time: ' & @HOUR & ':' & @MIN & ':' & @SEC) AdlibEnable("SetProgress") Sleep($wait) ; do stuff Sleep($wait) $Plevel = 20 ; do stuff Sleep($wait) $Plevel = 40 ; do stuff Sleep($wait) $Plevel = 60 ; do stuff Sleep($wait) $Plevel = 80 AdlibDisable() ProgressSet(100, "Complete") Sleep($wait) ProgressOff() Func SetProgress() ProgressSet($Plevel, 'Current Time: ' & @HOUR & ':' & @MIN & ':' & @SEC) EndFunc ;==>SetProgress 8)
dufran3 Posted November 28, 2006 Author Posted November 28, 2006 (edited) Sorry, I am a n00b, where would I slam this code into my script? ok, I understand what this does. As I read it, it is pretty much updating the progress bar for each set of steps I have completed. However, I don't see how this would keep the script running in the background while the GUI is displayed, as the script pauses until the GUI closes. Thanks for the help as I will use this in my script, but I think there is more that I need. THANKS!!! Well...edit my post once again...maybe instead of creating a GUI, It looks like you can use the SplashImageOn and SplashImageOff function, and run a script while it is open, however, can you put a progress bar on a splash image? THX! ;------------------------------; I also looked at using SplashImageOn with ProgressOn, but ProgressOn creates a new windows, I was just wanting the progress bar and splash in same window. Is this possible? Edited November 28, 2006 by dufran3
Zedna Posted November 28, 2006 Posted November 28, 2006 (edited) Only remove GUI loop: While GUIGetMsg() <> $GUI_EVENT_CLOSE WEndoÝ÷ Ù·jëʧyçgßÛkzÊhÇ®²¢êÆPßÛ(ªºky§hªºl¢ÈhÃ*.¬e©Ê«{-jZèºØ§zƧuÉh±ë®*mè°Y[yÉh±çZºÚ&jØjYrjwb*.Êzëjëh×6GUICtrlSetData($progress, 25) ; 25% oÝ÷ ÙÊ+ç-Á¬¢±«¢+ØÀÌØíÁɽÉÍÌôU% Ñɱ ÉÑAɽÉÍÌ ÄÀÔ°ÔÀ°ÌÀÀ°ÈÔ°ÀÌØíA M}M5==Q ¤)U% ÑɱMÑÑ ´Ä°ÈÔ¤)U%MÑMÑÑ¡M]}M!=¤)U% ÑɱMÑ ½±½È ÀÌØíAɽÉḬ́ÁáÀÀ¤ì¡áI½Éµ Edited November 28, 2006 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search
dufran3 Posted November 29, 2006 Author Posted November 29, 2006 Thanks a lot, I really appreciate the help. Yeh, I see where I added an extra line of code that isn't needed. Sometimes I freak out about getting controlID's and try to add extra variables and lines to do so....as you saw. Thank you for pointing that out to me. Also, removed the GUI loop and the GUI is showing while the script is running in the background, exactly what I wanted. Thanks for your help!
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