jefhal Posted June 29, 2005 Share Posted June 29, 2005 I have a "cleanup" program that lets me run a series of computer housekeeping tasks on the local computer. I'd like to show the service tag of the computer on the screen of the gui while it runs. I can get the service tag using this code which runs a VB script in dos, puts the service tag into a file, which I then read. However, when I add this code to my cleanup script, the service tag code runs but the gui never appears: FileDelete("c:\dellsertag.txt") ; clear out old file run(@ComSpec & ' /c ' & "\\student2\apps$\_bin\utils\GetDellSerTagOfThisComp.vbs","c:\"); puts Dell service tag into c:\dellsertag.txt $sertagfile = FileOpen("c:\dellsertag.txt", 0); Open file in read mode that contains service tag If $sertagfile = -1 Then ; Check if file opened for reading OK If $file = -1 Then Exit MsgBox(0, "Error", "Unable to open file.") EndIf $stline = FileReadLine($sertagfile) ; Read in first line of text to get service tag If @error = -1 Then Exit I tried making this into a UDF, but the same error occurs. How can I run this code without blowing up the gui? ...by the way, it's pronounced: "JIF"... Bob Berry --- inventor of the GIF format Link to comment Share on other sites More sharing options...
MSLx Fanboy Posted June 29, 2005 Share Posted June 29, 2005 There is a script somewhere on the forums to convert vb scripts to autoit scripts, it may or may not work for every thing though. I don't understand what you mean by 'the gui never appears'. What you should do is put the following line of code at the bottom of that snippet MsgBox(0, "Dell Service Tag", $stline) Which should tell you if your UDF is working correctly.VB_Script_Converter.zip Writing AutoIt scripts since _DateAdd("d", -2, _NowCalcDate()) Link to comment Share on other sites More sharing options...
jefhal Posted June 29, 2005 Author Share Posted June 29, 2005 There is a script somewhere on the forums to convert vb scripts to autoit scripts, it may or may not work for every thing though.I don't understand what you mean by 'the gui never appears'. What you should do is put the following line of code at the bottom of that snippetMsgBox(0, "Dell Service Tag", $stline)Which should tell you if your UDF is working correctly.<{POST_SNAPBACK}>MSLx Fanboy:The $stline variable does return the correct value. However, the entire rest of my GUI never appears. Here's the code:expandcollapse popup#include <GUIConstants.au3> ;AutoItSetOption("guioneventmode",1) ;GetDellServTag() Global $Power, $DelProfs, $IndexOff, $SyncOff, $IECache, $EmptyRecyc, $Defrag, $Reboot, $VirusScan, $GoButton, $sertagfile, $stline SplashTextOn("SHS Tech Support Notice", "Machine being cleaned. Please use another for now...", -1, 100, 50, 75, 4, "", 24) GUICreate("Clean Up Computer", 255, 400) GUICtrlCreateLabel("Choose your Clean Up Tasks:", 12, 18) $Power = GUICtrlCreateCheckbox("Power Always On / Hibernate Off",20,50,190,20) guictrlsetstate(4,$gui_checked) $DelProfs = GUICtrlCreateCheckbox("Delete Local Profiles",20,70,190,20) guictrlsetstate(5,$gui_checked) $IndexOff = GUICtrlCreateCheckbox("Indexing Off",20,90,190,20) guictrlsetstate(6,$gui_checked) $SyncOff = GUICtrlCreateCheckbox("Offline File Sync Off",20,110,190,20) guictrlsetstate(7,$gui_checked) $IECache = GUICtrlCreateCheckbox("IECache 100MB / History 3 Days",20,130,190,20) guictrlsetstate(8,$gui_checked) $EmptyRecyc = GUICtrlCreateCheckbox("Empty Recycle Bin",20,150,190,20) guictrlsetstate(9,$gui_checked) $RegClean = GUICtrlCreateCheckbox("Clean the Registry",20,170,190,20) guictrlsetstate(10,$gui_checked) $Defrag = GUICtrlCreateCheckbox("Defragment the C:\ Drive",20,190,190,20) guictrlsetstate(11,$gui_checked) $VirusScan = GUICtrlCreateCheckbox("Scan for Viruses",20,210,190,20) guictrlsetstate(12,$gui_checked) $WinACLS = GUICtrlCreateCheckbox("Run WinACLS",20,230,190,20) guictrlsetstate(13,$gui_checked) $Reboot = GUICtrlCreateCheckbox("Reboot to Enable Changes",20,250,190,20) guictrlsetstate(14,$gui_checked) $toggleselect = GUICtrlCreateButton("Toggle selection",20,275,190,20) GUICtrlCreateLabel("The target system name is: ",20,300,190,20) GUICtrlSetState(-1,$GUI_ACCEPTFILES) $sysname = GUICtrlCreateInput(@ComputerName,20,315,190,20); will not accept drag&drop files $GoButton = GUICtrlCreateButton("GO...",20,365,100,20) GuiSetState() While 1 ; Wait for user to select checkboxes and then press the "Go" button to begin routines $msg = guigetmsg() Select Case $msg = $GUI_EVENT_CLOSE; If user closes the dialog box the program is ended Exit ; ExitLoop Case $msg = $toggleselect ;msgbox(0,"","toggle selected") $ci = 4 while $ci < 15 ;msgbox(0,"$ci=",$ci & " " & guictrlread($ci)) if GUICtrlRead($ci) = 4 Then GUICtrlSetState($ci,$GUI_CHECKED) else GUICtrlSetState($ci,$gui_UNchecked) EndIf $ci = $ci + 1 Wend Case $msg = $GoButton ; If user selects the Go button, all checked tasks will be run if(GuiCtrlRead($Power) = 1) then ; Make sure power settings are correct RunWait(@ComSpec & ' /c ' & "regedit /s \\student2\apps$\_bin\cleanup\hibernateOFF_heuristics.reg");turn off hibernate RunWait(@ComSpec & ' /c ' & 'regedit /s \\student2\apps$\_bin\cleanup\PowerCFG_AlwaysOn.reg') ;set profile to "Always On" SplashTextOn("Progress Report", "Power is now Always ON, Hibernate is OFF", -1, 25, -1, 200, 4, "", 12) Sleep(3000) SplashOff() EndIf if(GuiCtrlRead($DelProfs) = 1) then ; Remove old local user profiles FileCopy("\\student2\apps$\_bin\cleanup\DelProfilesAnyuser.exe","c:\Documents and Settings\All Users\Desktop") Runwait('\\student2\apps$\_bin\cleanup\DelProfilesAnyuser.exe') ;delete profiles ;Winwaitclose("c:\winnt\system32\cmd.exe") FileDelete("c:\documents and settings\all users\desktop\delProfilesAnyuser.exe") ;msgbox(0,"Wait for Profiles","Click OK when profile deletion is done") SplashTextOn("Progress Report", "User Profiles are now DELETED", -1, 25, -1, 225, 4, "", 12) Sleep(3000) SplashOff() EndIf if(GuiCtrlRead($IndexOff) = 1) then ; Turn off File Indexing RegWrite("HKEY_LOCAL_MACHINE\system\currentcontrolset\services\cisvc","Start","REG_DWORD","4") SplashTextOn("Progress Report", "File Indexing is now OFF", -1, 25, -1, 250, 4, "", 12) Sleep(3000) SplashOff() EndIf if(GuiCtrlRead($SyncOff) = 1) then ; Turn off Offline File Synchronization ;~ if RegEnumval("HKEY_LOCAL_MACHINE\software\microsoft\windows\currentversion\netcache",1) <> "enabled" or RegEnumval("HKEY_LOCAL_MACHINE\software\microsoft\windows\currentversion\netcache",2) <> "enabled" Then ;~ RegWrite("HKEY_LOCAL_MACHINE\software\microsoft\windows\currentversion\netcache","Enabled","REG_DWORD") ;~ RegWrite("HKEY_LOCAL_MACHINE\software\microsoft\windows\currentversion\netcache","DefCacheSize","REG_DWORD") ;~ EndIf RegWrite("HKEY_LOCAL_MACHINE\software\microsoft\windows\currentversion\netcache","Enabled","REG_DWORD","0") RegWrite("HKEY_LOCAL_MACHINE\software\microsoft\windows\currentversion\netcache","DefCacheSize","REG_DWORD","0") SplashTextOn("Progress Report", "Offline File Sync is now OFF", -1, 25, -1, 275, 4, "", 12) Sleep(3000) SplashOff() EndIf if(GuiCtrlRead($IECache) = 1) then ; Reduce IE cache size to 20MB History to 7 days RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Internet Settings\5.0\Cache\Content","CacheLimit","REG_DWORD","102400") RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Internet Settings\5.0\Cache\Content","PerUserItem","REG_DWORD","0") RegWrite("HKEY_Current_User\Software\Microsoft\Windows\CurrentVersion\Internet Settings\5.0\Cache\Content","CachePrefix","REG_SZ","") RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Url History","DaysToKeep","REG_DWORD","3") ;RegWrite("HKEY_Current_User\Software\Microsoft\Windows\CurrentVersion\Internet Settings\5.0\Cache\Content","CacheLimit","REG_DWORD","00005000") SplashTextOn("Progress Report", "IE Cache is now 100MB and History is 3 days", -1, 25, -1, 300, 4, "", 12) Sleep(3000) SplashOff() EndIf if(GuiCtrlRead($EmptyRecyc) = 1) then ; Empty recycle bin RunWait(@comspec & ' /c ' & '\\student2\apps$\_bin\cleanup\erb /empty') SplashTextOn("Progress Report", "Recycle Bin is now EMPTY", -1, 25, -1, 325, 4, "", 12) Sleep(3000) SplashOff() EndIf If(GUICtrlRead($RegClean) = 1) Then ; Clean Registry Run(@comspec & ' /c ' & '\\student2\apps$\_bin\RegClean.exe') ;sleep(40000) winwait("Microsoft RegClean","&Fix Errors") WinActivate("Microsoft RegClean","&Fix Errors") sleep(2000) ControlClick("Microsoft RegClean","&Fix Errors",1009) sleep(2000) ControlClick("Microsoft RegClean","&Fix Errors",1008) SplashTextOn("Progress Report", "Registry is now clean", -1, 25, -1, 337, 4, "", 12) Sleep(3000) SplashOff() EndIf if(GuiCtrlRead($Defrag) = 1) then ; Defragment the hard disk Run(@comspec & ' /c ' & 'dfrg.msc c:') WinWaitActive("Disk Defragmenter") ControlClick("Disk Defragmenter","","Button2") WinWaitActive("Defragmentation Complete","View &Report") ControlClick("Defragmentation Complete", "View &Report",2) WinClose("Disk Defragmenter") SplashTextOn("Progress Report", "Harddisk is now DEFRAGMENTED", -1, 25, -1, 350, 4, "", 12) Sleep(3000) SplashOff() EndIf if(GuiCtrlRead($VirusScan) = 1) then ; Virusscan the hard disk Run('C:\Program Files\Network Associates\VirusScan\mcconsol.exe') WinWaitActive("VirusScan Console - ","Local System") Send("{DOWN}{DOWN}{DOWN}{DOWN}") send("!ss") $text = WinGetText("VirusScan On-Demand","") ;msgbox(0,"Message found!",StringInStr($text,"No infected items were found")) While StringInStr($text,"No infected items were found") <> 20 $text = WinGetText("VirusScan On-Demand","") ;MsgBox(0, "Value of $text is:", $text) WEnd ;msgbox(0,"Message found!",StringInStr($text,"No infected items were found")) ;WinClose("VirusScan On-Demand Scan Progress - New Scan");use this command for quick testing of scan of memory only WinClose("VirusScan On-Demand Scan Progress - Scan All Fixed Disks") WinClose("VirusScan Console - ","Local System") SplashTextOn("Progress Report", "System is now scanned for Viruses", -1, 25, -1, 375, 4, "", 12) Sleep(3000) SplashOff() EndIf if(GuiCtrlRead($WinACLS) = 1) then ; Run WinACLS Run("\\Staff\c$\AdminDocs\Windows_2000_acl_list_v.1.7.bat") WinWaitActive("C:\WINNT\system32\cmd.exe") WinWaitClose("C:\WINNT\system32\cmd.exe") SplashTextOn("Progress Report", "Windows Access Control Lists now updated", -1, 25, -1, 400, 4, "", 12) Sleep(3000) SplashOff() EndIf if(GuiCtrlRead($Reboot) = 1) then ; Restart the computer to finish changing settings RunWait(@comspec & ' /c ' & '\\student2\apps$\_bin\shutdown.exe /L /R') EndIf MsgBox(1,"","done") ExitLoop EndSelect WEnd Exit Func GetDellServTag() FileDelete("c:\dellsertag.txt") ; clear out old file run(@ComSpec & ' /c ' & "\\student2\apps$\_bin\utils\GetDellSerTagOfThisComp.vbs","c:\"); puts Dell service tag into c:\dellsertag.txt $sertagfile = FileOpen("c:\dellsertag.txt", 0); Open file in read mode that contains service tag If $sertagfile = -1 Then ; Check if file opened for reading OK If $file = -1 Then Exit MsgBox(0, "Error", "Unable to open file.") EndIf $stline = FileReadLine($sertagfile) ; Read in first line of text to get service tag If @error = -1 Then Exit ;MsgBox(0,"",$stline) ;FileDelete("c:\dellsertag.txt") EndFuncIf I run this script as is, it works. However, if I uncomment out the third line, the gui never shows up. I have tried moving the third line to many other places with the same result. There is something about running commands that does not agree with the gui process...Jeff ...by the way, it's pronounced: "JIF"... Bob Berry --- inventor of the GIF format Link to comment Share on other sites More sharing options...
GaryFrost Posted June 29, 2005 Share Posted June 29, 2005 (edited) Put some MsgBox checks where you have exit in that function, you'll probably find you are exiting because of an error. Func GetDellServTag() FileDelete("c:\dellsertag.txt") ; clear out old file Run(@ComSpec & ' /c ' & "\\student2\apps$\_bin\utils\GetDellSerTagOfThisComp.vbs", "c:\"); puts Dell service tag into c:\dellsertag.txt $sertagfile = FileOpen("c:\dellsertag.txt", 0); Open file in read mode that contains service tag If $sertagfile = -1 Then ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf $stline = FileReadLine($sertagfile) ; Read in first line of text to get service tag If @error = -1 Then MsgBox(0, "Error", "Unable to read file.") Exit EndIf ;MsgBox(0,"",$stline) ;FileDelete("c:\dellsertag.txt") EndFunc ;==>GetDellServTag Edited June 29, 2005 by gafrost SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
Zedna Posted June 29, 2005 Share Posted June 29, 2005 Func GetDellServTag() FileDelete("c:\dellsertag.txt") ; clear out old filerun(@ComSpec & ' /c ' & "\\student2\apps$\_bin\utils\GetDellSerTagOfThisComp.vbs","c:\"); puts Dell service tag into c:\dellsertag.txt$sertagfile = FileOpen("c:\dellsertag.txt", 0); Open file in read mode that contains service tag If $sertagfile = -1 Then ; Check if file opened for reading OK If $file = -1 Then Exit MsgBox(0, "Error", "Unable to open file.") EndIf$stline = FileReadLine($sertagfile) ; Read in first line of text to get service tag If @error = -1 Then Exit;MsgBox(0,"",$stline);FileDelete("c:\dellsertag.txt")EndFuncI think this id right way:Func GetDellServTag() FileDelete("c:\dellsertag.txt") ; clear out old file run(@ComSpec & ' /c ' & "\\student2\apps$\_bin\utils\GetDellSerTagOfThisComp.vbs","c:\"); puts Dell service tag into c:\dellsertag.txt $sertagfile = FileOpen("c:\dellsertag.txt", 0); Open file in read mode that contains service tag If $sertagfile = -1 Then ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Return -1 EndIf $stline = FileReadLine($sertagfile) ; Read in first line of text to get service tag If @error = -1 Then Return -1 ;MsgBox(0,"",$stline) ;FileDelete("c:\dellsertag.txt") Return 0 EndFunc1) Instead of Exit use in Function Return2) MsgBox before Return (not after)3) And I recommend use return value of function and test it. If it's bad then Exit (but in main prog. and no in function) Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
jefhal Posted June 29, 2005 Author Share Posted June 29, 2005 I think this id right way:Func GetDellServTag() FileDelete("c:\dellsertag.txt") ; clear out old file run(@ComSpec & ' /c ' & "\\student2\apps$\_bin\utils\GetDellSerTagOfThisComp.vbs","c:\"); puts Dell service tag into c:\dellsertag.txt $sertagfile = FileOpen("c:\dellsertag.txt", 0); Open file in read mode that contains service tag If $sertagfile = -1 Then ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Return -1 EndIf $stline = FileReadLine($sertagfile) ; Read in first line of text to get service tag If @error = -1 Then Return -1 ;MsgBox(0,"",$stline) ;FileDelete("c:\dellsertag.txt") Return 0 EndFunc1) Instead of Exit use in Function Return2) MsgBox before Return (not after)3) And I recommend use return value of function and test it. If it's bad then Exit (but in main prog. and no in function)<{POST_SNAPBACK}>Thanks Zedna-You were right on the money. I found I also had to change "run" to "runwait" so that the file was created before the script went on. Finally, I called the function just after the Global's were declared. Here's what I ended up with:Func GetDellServTag() runwait(@ComSpec & ' /c ' & "C:\Documents and Settings\Jeff\My Documents\bin\getsertag.vbs","c:\"); puts Dell service tag into c:\dellsertag.txt $sertagfile = FileOpen("c:\dellsertag.txt", 0); Open file in read mode that contains service tag If $sertagfile = -1 Then ; Check if file opened for reading OK;If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Return -1 EndIf $stline = FileReadLine($sertagfile) ; Read in first line of text to get service tag If @error = -1 Then Return -1 ;MsgBox(0,"",$stline); for debugging ;FileDelete("c:\dellsertag.txt"); this was not necessary Return 0 EndFuncThank you so much!Jeff ...by the way, it's pronounced: "JIF"... Bob Berry --- inventor of the GIF format Link to comment Share on other sites More sharing options...
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