Jump to content

Cleaning script routine for windows (xp vista 7)


 Share

Recommended Posts

Hello all:

I'm new to the Autoit community.

I have been using Autoit for a couple years, but have never graduated to more than a basic script. I have been trying to write a new script to automate work that I do on a reoccuring basis across many differant computers (Win xp, vista, 7) as well as x86, and 64bit.

My script starts by downloading all the programs I need to the client computer and locating them on the desktop in a folder, then the script will execute the files from there. Functioning each individual program from start to finish untill the entire routine is complete.

Currently I'm trying to write each script individually to operate just one program(to simplify bug fixes, during the development phase.) When I'm done I will compile them into one large script.

I have written several .bat files that work across xp, vista and 7, differentiating between the architechure without fail everytime. I want to rewrite the .bat files into a funtional .exe using autoit. My reason for using Autoit is to automate the functions that can't be automated from.bat

I have been reading the help file, and parsing the forum but I cant see where or what post can help with my work. I'm trying hard to understand all the many funtions and calls to make it work, but it is slightly overwhelming right now. The only programming knowlegde I have is what I have learned on my own (meaning I may not know the correct terminology as an experianced programer has.)

My bat files are layered in functionality

this is the first bat to start the process, my initial intent was to use this one script from top to bottom, but I kept running into errors when I added more functionality. (but when I kept the scripts simple they would work well everytime.)

I wrote the below code to let you see how my mind is working, Ive worked in forums in the past and I know it is nice to understand what the OP thinks (and the manner in which he does so)

@echo off

REM Check Windows Version
ver | findstr /i "5\.1\." > nul
IF %ERRORLEVEL% EQU 0 goto ver_XP
ver | findstr /i "5\.2\." > nul
IF %ERRORLEVEL% EQU 0 goto ver_Vista
ver | findstr /i "6\.1\." > nul
IF %ERRORLEVEL% EQU 0 goto ver_Win7
goto warn_and_exit

:ver_Win7
if defined ProgramFiles(x86) (
 
"%SYSTEMDRIVE%\users\%USERNAME%\desktop\cleaner\64clean.bat""

) else (
 
"%SYSTEMDRIVE%\users\%USERNAME%\desktop\cleaner\32clean.bat"
)
REM echo OS Version: Windows 7 (debug line)
goto end


:ver_Vista
if defined ProgramFiles(x86) (
 
"%SYSTEMDRIVE%\users\%USERNAME%\desktop\cleaner\64clean.bat""

) else (
 
"%SYSTEMDRIVE%\users\%USERNAME%\desktop\cleaner\32clean.bat"
)
REM echo OS Version: Windows Vista (debug line)
goto end

:ver_XP
if defined ProgramFiles(x86) (
 
"%SYSTEMDRIVE%\Documents and Settings\%USERNAME%\desktop\cleaner\64clean.bat""

) else (
 
"%SYSTEMDRIVE%\Documents and Settings\%USERNAME%\desktop\cleaner\32clean.bat"
)
REM echo OS Version: Windows XP (debug line)
goto end

:warn_and_exit
echo Machine OS cannot be determined.

:end

I know how to create autoit scripts for my computer and all the other computers individually, but I can't wrap my head around making my auto it script work as one unit between them all.

Here is a simple script that I have assembled to run Ninite and close

run("C:\Users\PRCS owner\Desktop\Ninite.exe")
WinActivate( "[class:#32770]", "Close") ;activates the last window in Ninite after the update is complete
WinWaitActive ( "[class:#32770]", "Close") ;waits for the last window to be active
sleep(500)
ControlClick ( "Ninite", "Finished" ,2) ;Closes ninite

My first line is what needs to be scripted for the %systemdrive%, and the %username% variable. I think if I can figure this out I can get most of the rest.

I know there is more to the script, but I don't want to get to crazy on this first post, Thank you to anyone that has read this so far, I thank you for any input you may have. Thank you for your time.

Prcssupport

Link to comment
Share on other sites

Hello. When I first started using AutoIt, I only knew batch files. But AutoIt is much more powerful than them and can probably do everything you want by itself. We can help guide you, but we many need more information to pinpoint what you are trying to accomplish.

OK, so you want to download and install software, right? Where are you downloading software from? Is it from a website or a shared folder on a specified computer? Do the individual computer have the rights to install the software or are admin rights necessary? Do you want to perform silent installations?

Let's start simple. The example you provided differentiated between x32 and x64 operating systems. I would run something like this:

If @OSArch = "X64" Then
    Run(@DesktopDir & "\programfile_x64.exe")
ElseIf @OSArch = "X86" Then
    Run(@DesktopDir & "\programfile_x32.exe")
Else
    MsgBox(0, "Error", "Cannot determine if your operating system is 32 or 64 bit")
EndIf

Forget about the workarounds you have used in the past. Let us know what you are trying to accomplish and I think you will be impressed with how concise you can make your tasks.

Link to comment
Share on other sites

Hi abberration,

Thank you for your reply. I tried your script and exchanged out specific info for this situition and it worked perfectly. That actually helps me out alot, I wasn't sure how to use the macros to get the work done. It gives me a great working point.

I know Auto it is very good, I have loved it since I learned about it years ago. But I never spent enough time with it. But times and situations have changed and I need to put it to work. I'm not sure how much code this project is going to entail but I think it will be a good amount. I want to learn as much as I can with pushes in the right direction. I'm not looking for someone to code this for me. (I have seen some excellent people here and other places willing to tweak code) Thank you to all you guys that do that. But I need to become proficent with this. I'm sure someone out there has done this already. But I like to learn.

OK, so you want to download and install software, right? Where are you downloading software from? Is it from a website or a shared folder on a specified computer? Do the individual computer have the rights to install the software or are admin rights necessary? Do you want to perform silent installations?

All computer downloads are going to be from a webserver.

The computers are primarly consumer level, several business class. And they are everywhere. Everything I do is remote. But then even if I'm hands on I would still employ the script method.

Some of the functions in the script require elevation (something I need to make sure happens for the sake of automation) I have Admin rights on all of the computers.

And yes i will be performing silent installs, if supported.

Currently at the beginning of a cleanout I execute a bat file (Similar to the one above.)

It determines the Ver of the OS, downloads several exe, and zips to the "desktop\cleaner" (I use wget to perform this) The files are located on my webserver. Then based on the response of an if statement it executes the appropriate Architecture script with the proper environmental variables for the OS.

This executes:

Ninite

silent install of CCleaner

update of Mbam to the latest defs, automated

silent autorun of CCleaner

Glary with automation

quickscan of Mbam quits on its own if clean (but will cause script to pause indefinatly if infected, until results are handled)

cmd line run of Auslogics

CCleaner\registry save back up (to the desktop) and fix

msert.exe scan automated

Javara (removal of old outdated remenants) automated

Windows update

hitman pro scan

make a dir on the desktop to place security tool icons

move the icons on the desktop created by this script into the above folder

File cleanup including self

I'm hoping this is enough info, I'm going to start working on putting together code(and see how I do)

Thank you again for your time.

Prcssupport

Link to comment
Share on other sites

G'day prcssupport (for want of a name :))

I'd recommend you keep the "shepard" controller script that runs individual scripts (eg ccleaner). The biggest advantage is that if a script locks up you can still continue in the "shepard" and restart the individual one or whatever is apporpirate for the subsection. It also makes maintenance easier as you can concentrate on the individual program, If you are onsite you can run the indivudlal programs if nessacary AND you are able to run processes in parrellel to reduce the overall time taken.

BTW I have scripts that cover some of the elements you're adding to your scirpt. Some of them are on the forum, others I haven't posted because the don't look pretty enough. :) If you're interested PM me and we can compare notes. There are probably aspects of your .Bat files that could enhance the scripts I've allready created.

John Morrison

Link to comment
Share on other sites

Hi storme,

Thank you for the post!

I'd recommend you keep the "shepard" controller script that runs individual scripts (eg ccleaner). The biggest advantage is that if a script locks up you can still continue in the "shepard" and restart the individual one or whatever is apporpirate for the subsection. It also makes maintenance easier as you can concentrate on the individual program, If you are onsite you can run the indivudlal programs if nessacary AND you are able to run processes in parrellel to reduce the overall time taken.

Yea I understand on keeping the shepard script, that is how I initially designed it for simplicity in development(and fixing bugs.) Infact that is how I'm working as I build these AU3 scripts.

I'm working on the starter script that will kick the whole thing off.

I have the starter working. And I have the file downloads functional as well. I integrated some of my other scripts into the bigger one and it parsed through it. I still have kinks to work out. But i'm running out of steam. it is almost 3 am right now.

I was looking throught the help file,but I didn't see a macro for Program Files (x86) is this something we will have to write out? or is there another way to do that?

Have a good night all, and again Thank you!

Prcssupport

Link to comment
Share on other sites

I was looking throught the help file,but I didn't see a macro for Program Files (x86) is this something we will have to write out? or is there another way to do that?

Glad to see your project is shaping up. There is not a macro for the x86 program files folder. You must use something like this:

@HomeDrive & "Program Files (x86)"

Also, you can run the Auslogics program without command line. Just run the program with the command line parameters after it, like this:

Run("cdefrag -c")

I haven't tried that code, so if it doesn't work, try using the path like this:

Run(@ProgramFiles & "AusolgicsDefragcdefrag.exe -c") ; I made up this path, so it probably needs to be modified.

Edited by abberration
Link to comment
Share on other sites

My first line is what needs to be scripted for the %systemdrive%, and the %username% variable.

Just use environment variables.

Opt("ExpandEnvStrings", 1) is your friend.

Here a sample:

Opt("ExpandEnvStrings", 1)
$myCommandline = "%HOMEDRIVE%%HOMEPATH%\Desktop\Ninite.exe"
MsgBox(0, "", "$MyCommandline --> " & $myCommandline & @LF & @LF & "%%Systendrive%% --> " & "%Systemdrive%" & @LF & @LF & _
"%%Username%% --> " & "%Username%")

App: Au3toCmd              UDF: _SingleScript()                             

Link to comment
Share on other sites

Hi abberation

Thank you for the reply!

Glad to see your project is shaping up. There is not a macro for the x86 program files folder. You must use something like this:

Well shaping up... yes it is getting somewhere. But it is ugly right now!

I have to put in error control and correction handling. (Thats when it will get really fun here!)

To Bad on the macro for x86, I wish they had it! But the solution you have works perfectly! I might have thought off that this morning after some sleep. -_-:robot:

@HomeDrive & "Program Files (x86)"

Also, you can run the Auslogics program without command line. Just run the program with the command line parameters after it, like this:

Run("cdefrag -c")

I didn't mean to call up sys32/cmd.exe I just meant exactly what you said, it was late I was tired...

I haven't tried that code, so if it doesn't work, try using the path like this:

Run(@ProgramFiles & "AusolgicsDefragcdefrag.exe -c") ; I made up this path, so it probably needs to be modified.

I have the main body of an x64 script written, I'm burning through it right now. I will start an x86 soon. I will keep you guys posted. Thank you again!

Prcssupport

I just realized I placed my responses inside your quote without the :oops:

Edited by prcssupport
Link to comment
Share on other sites

Ok Everybody,

Thank you for your time and input thus far. These aren't pretty scripts I will work on making them better later.

Here is the starter script, its only funtion is to determine OSarch then execute the proper cleaning routine based on it. (Thank you abberration, for this one!)

For now the scripts will only call up the programs but not automate any of them.

If @OSArch = "X64" Then
     Run(@DesktopDir & "\PRCScleaner\64bit routine.exe")
ElseIf @OSArch = "X86" Then
Run(@DesktopDir & "\PRCScleaner\32bit routine.exe")
Else
MsgBox(0, "Error", "Cannot determine if your operating system is 32 or 64 bit")
EndIf

The above file will execute the 64 bit code directly below, (or the 32bit one at the bottom) Both files will only advance to the next funtion after the line parameters are met. (With out it I had all the windows open at once on the screen.) It is ok on my desktop, but I'm sure it would send the other systems into a tizzy fit for an hour or so... So I chose to processwaitclose. I cleared out my download link, not that i don't trust the people here, but I don't need to over load my link with bandwidth usage from people .

#cs ----------------------------------------------------------------------------

AutoIt Version: 3.3.8.1
Author: PRCSsupport

Script Function:
Cleaner routine for windows 64bit

#ce ----------------------------------------------------------------------------
;Creates directories to the desktop
DirCreate(@DesktopDir &"\cleaner")
DirCreate(@DesktopDir &"\cleaner\Javara")
;Downloads files and places them in above directories for later use (forces file download from online sources one at a time)
     InetGet("http://somedownload.com/HitmanPro64.exe", @DesktopDir & "\cleaner\HitmanPro64.exe" ,1)
     InetGet("http://somedownload.com/msert64.exe", @DesktopDir & "\cleaner\msert64.exe" ,1)
     InetGet("http://somedownload.com/ninite.exe", @DesktopDir & "\cleaner\ninite.exe" ,1)
     InetGet("http://somedownload.com/TCPOptimizer.exe", @DesktopDir & "\cleaner\TCPOptimizer.exe" ,1)
     InetGet("http://somedownload.com/ccsetup.exe", @DesktopDir & "\cleaner\ccsetup.exe" ,1)
     InetGet("http://somedownload.com/JavaRa/JavaRa.def", @DesktopDir & "\cleaner\JavaRa\JavaRa.def" ,1)
     InetGet("http://somedownload.com/JavaRa/JavaRa.exe", @DesktopDir & "\cleaner\JavaRa\JavaRa.exe" ,1)
Run(@DesktopDir & "\cleaner\ccsetup.exe /S")
     ProcessWaitClose("ccsetup.exe")
Run(@DesktopDir & "\cleaner\ninite.exe")
     ProcessWaitClose("Ninite.exe")
Run(@homedrive &"\Program Files (x86)\Malwarebytes' Anti-Malware\mbam.exe")
     ProcessWaitClose("mbam.exe")
Run(@ProgramFilesDir & "\CCleaner\CCleaner64.exe /AUTO")
     ProcessWaitClose("CCleaner64.exe")
Run(@homedrive &"\Program Files (x86)\Glary Utilities\Integrator.exe")
     ProcessWaitClose("Integrator.exe")
Run(@Homedrive & "\Program Files (x86)\Malwarebytes' Anti-Malware\mbam.exe/quickscanterminate")
     ProcessWaitClose("mbam.exe")
Run(@Homedrive & "\Program Files (x86)\Auslogics\Auslogics Disk Defrag\cdefrag.exe -c")
     ProcessWaitClose("cdefrag.exe")
Run(@ProgramFilesDir & "\CCleaner\CCleaner64.exe /registry")
     ProcessWaitClose("CCleaner64.exe")
Run(@DesktopDir & "\cleaner\msert64.exe")
     ProcessWaitClose("msert64.exe")
Run(@DesktopDir & "\cleaner\javara.exe")
     ProcessWaitClose("javara.exe")
Run(@DesktopDir & "\cleaner\Hitmanpro64.exe")
     ProcessWaitClose("Hitmanpro64.exe")
Run(@SystemDir & "\wuapp.exe startmenu")
     ProcessWaitClose("wuapp.exe")
Run(@DesktopDir & "\bigone\TCPOptimizer.exe")

#cs ----------------------------------------------------------------------------
Author: PRCSsupport

Script Function:
Cleaner routine for windows 32bit

#ce ----------------------------------------------------------------------------
;Creates directories to the desktop
DirCreate(@DesktopDir &"\cleaner")
DirCreate(@DesktopDir &"\cleaner\Javara")
;Downloads files and places them in above directories for later use (forces file download from online sources one at a time)
     InetGet("http://somedownload.com/msert32.exe", @DesktopDir & "\cleaner\msert32.exe" ,1)
     InetGet("http://somedownload.com/HitmanPro32.exe", @DesktopDir & "\cleaner\HitmanPro32.exe" ,1)
     InetGet("http://somedownload.com/ninite.exe", @DesktopDir & "\cleaner\ninite.exe" ,1)
     InetGet("http://somedownload.com/TCPOptimizer.exe", @DesktopDir & "\cleaner\TCPOptimizer.exe" ,1)
     InetGet("http://somedownload.com/ccsetup.exe", @DesktopDir & "\cleaner\ccsetup.exe" ,1)
     InetGet("http://somedownload.com/JavaRa/JavaRa.def", @DesktopDir & "\cleaner\JavaRa\JavaRa.def" ,1)
     InetGet("http://somedownload.com/JavaRa/JavaRa.exe", @DesktopDir & "\cleaner\JavaRa\JavaRa.exe" ,1)
Run(@DesktopDir & "\cleaner\ccsetup.exe /S")
     ProcessWaitClose("ccsetup.exe")
Run(@DesktopDir & "\cleaner\ninite.exe")
     ProcessWaitClose("Ninite.exe")
Run(@ProgramFilesDir &"\Malwarebytes' Anti-Malware\mbam.exe")
     ProcessWaitClose("mbam.exe")
Run(@ProgramFilesDir & "\CCleaner\CCleaner.exe /AUTO")
     ProcessWaitClose("CCleaner.exe")
Run(@ProgramFilesDir &"\Glary Utilities\Integrator.exe")
     ProcessWaitClose("Integrator.exe")
Run(@ProgramFilesDir & "\Malwarebytes' Anti-Malware\mbam.exe/quickscanterminate")
     ProcessWaitClose("mbam.exe")
Run(@ProgramFilesDir & "\Auslogics\Auslogics Disk Defrag\cdefrag.exe -c")
     ProcessWaitClose("cdefrag.exe")
Run(@ProgramFilesDir & "\CCleaner\CCleaner.exe /registry")
     ProcessWaitClose("CCleaner.exe")
Run(@DesktopDir & "\cleaner\msert32.exe")
     ProcessWaitClose("msert64.exe")
Run(@DesktopDir & "\cleaner\javara.exe")
     ProcessWaitClose("javara.exe")
Run(@DesktopDir & "\cleaner\Hitmanpro32.exe")
     ProcessWaitClose("Hitmanpro32.exe")
Run(@SystemDir & "\wuapp.exe startmenu")
     ProcessWaitClose("wuapp.exe")
Run(@DesktopDir & "\cleaner\TCPOptimizer.exe")

The below code is a piece of my ccleaner script. During the registry cleanout procedure either you have "No issues" or you can "fix all the issues" The "Fix" control button is disabled if there is nothing to fix. My thought is I can use this with ControlCommand "IsEnabled" to tell the below statement how to proceed. I haven't been sucessful in making it work.

My questions to learn how this works, If the Local $var = "1" directly follows Controlcommand for example, will it harness the data to apply it to the if, then,else?

ControlCommand("Piriform CCleaner", "&Scan for Issues", "[CLASS:Button; INSTANCE:3]", "IsEnabled", "" )
     Local $var = "1"
If $var = @error Then
     mouseclick("left" ,701, 10) ; having a hardtime with controlclick in ccleaner , resorted to mouseclick
ElseIf $var = 1 Then
     ControlClick("Piriform CCleaner" ,"&Fix selected issues..." ,"[CLASS:Button; INSTANCE:3]")
         sleep(1500)
     ControlClick("CCleaner" ,"Yes" ,"[CLASS:Button; INSTANCE:1]")
         sleep(250)
         mouseclick("left" ,78, 165)
     ControlClick("Save As" , "&Save", "[CLASS:Button; INSTANCE:1]")
     sleep(500)
     ControlClick("[CLASS:#32770]" , "Fix All Selected Issues" ,"[CLASS:Static; INSTANCE:4]")
         BlockInput (1)
         MouseClick("left" ,392 ,362)
         sleep(5000)
         MouseClick("left" ,538, 361)
         WinKill("Piriform CCleaner", "&Scan for Issues")
         BlockInput(0)
Else
     If StringIsDigit($var) Then
MsgBox(4096, "", "Then Ccleaner will close down")
Else
MsgBox(4096, "", "CCleaner will complete registry cleanout.")
EndIf

I'm still working on the automation of each program individually. I orginally wrote them with mouseclicks, I'm rewriting with controlclicks. I have more that I need to do, but I'm going to go to bed early tonight. I will be back tommrow. Thank you all.

Prcssupport

Link to comment
Share on other sites

For Ccleaner why not try a ready made solution?

I think I have a more recent verison on my hard drive somewhere but that one should work fine.

Link to comment
Share on other sites

Opt("ExpandEnvStrings", 1) is your friend.

I would say _WinAPI_ExpandEnvironmentStrings is more your 'friend' than the AutoItSetOption parameter.

UDF List:

 
_AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Exit,

Have a read of to further demonstrate my point. It can also cause issues as that Opt affects all the environment variables in the script, something as simple as MsgBox(4096, '', 'The environment variable %PATH% was detected.') will be expanded.

Edited by guinness

UDF List:

 
_AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Hi StormE

Hi thank you for the idea to search already created scripts of the programs I use (I hadn't thought of that. I like to build things so it took over) The use of your script helped me alot. Since it was a program I'm familar with it helped me get a better understanding of Autoit. It will take alot of time, but I can't wait for the day when it is all second nature!!!

For Ccleaner why not try a ready made solution?

I think I have a more recent verison on my hard drive somewhere but that one should work fine.

I had to tweak your script, it wasn't functional on my side. I notated in the script what I changed.

I also added "auto cleaning" with ccleaner at the beginning of the script

The message box didn't produce once the scans return clean, I had to move the line above the end loop. I also reworded the msgbox. Not that that matters at all.

I also removed the if installed statements at the beginning.

Also I had to change this:

WinExistsActivateWaitClick("Save As", "", "[CLASS:Button; INSTANCE:1]") ;had to change instance 2 to 1 as it didn't work. After watching the script and the program run several times I nailed down the error.

Here is your script with my changes.

#AutoIt3Wrapper_Run_Debug_Mode=y
Opt("MustDeclareVars", 1)
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Res_Fileversion=1.0.0.0
#AutoIt3Wrapper_Res_LegalCopyright=
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#cs ----------------------------------------------------------------------------

AutoIt Version .: 3.3.6.1
Author .........: John Morrison
Script Version .: 1.0.0.0
Name ...........: CCleaner Auto Registry cleaner
Date ...........: 2012/3/7
Modified .......: 2012/3/7
Company ........:
Copyright ......:
Script Function :

#ce ----------------------------------------------------------------------------

#Region Includes

#EndRegion Includes

#Region Script Constants
Global Const $MY_NAME = "CCleaner"
Global Const $HOME = @ScriptDir & ""
#EndRegion Script Constants

#Region Script Globals

#EndRegion Script Globals

#Region Main Script
; *********************** MAIN ENTRY POINT ****************************
#RequireAdmin
;I removed the if installed statements because I want the newest ver in the system and it is handled in my script
;added Runs CCleaner in auto mode to completion and closes
run(@homedrive & "\Program Files\CCleaner\CCleaner64.exe /auto")
ProcessWaitClose("CCleaner64.exe")

Local $iCount = 10
While $iCount ; Keep looping until ALL registry fixes done or looped 10 times
Run(@homedrive & "\Program Files\CCleaner\CCleaner64.exe /registry") ; changed @path to make functional
;Click Scan button
WinWait("Piriform CCleaner", "&Scan for Issues")
WinExistsActivateWaitClick("Piriform CCleaner", "&Scan for Issues", "[CLASS:Button; INSTANCE:2]")

;Wait for scan to complete
Sleep(500) ; Wait for scan to get started
WinWait("Piriform CCleaner", "&Scan for Issues")

If Not ControlCommand("Piriform CCleaner", "&Fix selected issues", "[CLASS:Button; INSTANCE:3]", "IsEnabled") Then
     ;All Reg problems removed
     MsgBox(0, "CCleaner Status", "CCleaner has completed %temp% file cleanout and registry optimization" ,25) ; moved message box to this line, it was below ExitLoop causing it not to show. added timer as well
ExitLoop

EndIf

WinWait("Piriform CCleaner", "&Fix selected issues")
WinExistsActivateWaitClick("Piriform CCleaner", "&Fix selected issues", "[CLASS:Button; INSTANCE:3]")

If WinWait("CCleaner", "Do you want to backup changes to the registry?", 2) Then
     ;DON'T SAVE Backup I always save my backup!!! Nice for those looking at the option
     ;WinExistsActivateWaitClick("CCleaner", "Do you want to backup changes to the registry?", "[CLASS:Button; INSTANCE:2]")

     ;SAVE Backup
     WinExistsActivateWaitClick("CCleaner", "Do you want to backup changes to the registry?", "[CLASS:Button; INSTANCE:1]")
     ;SetPath
     WinWait("Save As")
     DirCreate(@MyDocumentsDir & "ccleaner");in case it isn't already created
     ControlSetText("Save As", "", "[CLASS:Edit; INSTANCE:1]", @MyDocumentsDir & "ccleaner" & ControlGetText("Save As", "", "[CLASS:Edit; INSTANCE:1]"))
     Sleep(500)
     ;Click Save
     WinExistsActivateWaitClick("Save As", "", "[CLASS:Button; INSTANCE:1]") ;had to change instance 2 to 1 as it didn't work
EndIf

;Fix (ALL) issues
Global $hWnd = WinWait("[CLASS:#32770]", "Fix Issue")
WinExistsActivateWaitClick("[CLASS:#32770]", "Fix Issue", "[CLASS:Button; INSTANCE:4]") ;Fix ALL/Fix Issue
;Wait for Close button to be enabled
While Not ControlCommand("[CLASS:#32770]", "Fix Issue", "[CLASS:Button; INSTANCE:5]", "IsEnabled")
     Sleep(500)
WEnd
Sleep(500)
WinExistsActivateWaitClick("[CLASS:#32770]", "Fix Issue", "[CLASS:Button; INSTANCE:5]") ;Close

$iCount = $iCount - 1
WEnd
WinClose("Piriform CCleaner")
WinWaitClose("Piriform CCleaner")

Exit
#EndRegion Main Script

#Region Utility Functions
; #FUNCTION# ====================================================================================================================
; Name...........: GetInstalledPath
; Description ...: Returns the installed path for specified program
; Syntax.........: GetInstalledPath($sProgamName)
; Parameters ....: $sProgamName - Name of program to seaach for
;                                - Must be exactly as it appears in the registry
; Return values .: Success - returns the install path
;                Failure - 0
;                |@Error - 1 = Unable to find entry in registry
; Author ........: John Morrison aka Storm-E
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......:
; ===============================================================================================================================
Func GetInstalledPath($sProgamName)
;Written
; @error = 1 - Not installed
;Get Installed path
Static $sInstalledPath = ""
If $sInstalledPath = "" Then
     $sInstalledPath = RegRead("HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionUninstall" & $sProgamName, "InstallLocation")
     If @error Then
         $sInstalledPath = ""
         Return SetError(1, 0, "")
     EndIf
EndIf
Return $sInstalledPath
EndFunc ;==>GetInstalledPath

Func WinExistsActivateWaitClick($title, $text, $controlID)
If WinExistsActivateWait($title, $text) Then
     Return ControlClick($title, $text, $controlID)
EndIf
Return False
EndFunc ;==>WinExistsActivateWaitClick

Func WinExistsActivateWait($title, $text = "")
;Got sick of writting this over and over in scripts
If WinExists($title, $text) Then
     ConsoleWrite("WinExists : $title=" & $title & " $text=" & $text & @CR)
     WinActivate($title, $text)
     WinWait($title, $text)
     Return True
EndIf
Return False
EndFunc ;==>WinExistsActivateWait

#EndRegion Utility Functions

I would say _WinAPI_ExpandEnvironmentStrings is more your 'friend' than the AutoItSetOption parameter.

Opt("ExpandEnvStrings", 1) needs no #include. Less typing. Remains my friend. :ILA2:

For right now, i'm trying to stay simple, it may be harder, for now it is better for me. I will work up into the other cmds over time. Thank you for the input. it is greatly appreciated. I just don't know what to do with it right now.

Thank you again all of you for your time and input. Having worked on your side I know how important and thankless your work can feel. You guys get :thumbsup::ILA:

Prcssupport

Link to comment
Share on other sites

Exit,

Have a read of to further demonstrate my point. It can also cause issues as that Opt affects all the environment variables in the script, something as simple as MsgBox(4096, '', 'The environment variable %PATH% was detected.') will be expanded.

This is also true for _WinAPI_ExpandEnvironmentStrings.

And the Messagebox case should be written

MsgBox(4096, '', 'The environment variable %%PATH%% was detected.')

when expansion is active.

App: Au3toCmd              UDF: _SingleScript()                             

Link to comment
Share on other sites

This is also true for _WinAPI_ExpandEnvironmentStrings.

And the Messagebox case should be written

MsgBox(4096, '', 'The environment variable %%PATH%% was detected.')

when expansion is active.

It would only expand when you wrap %PATH% in _WinAPI_ExpandEnvironmentStrings. Anyway, I think I've expressed my opinion on this now!

UDF List:

 
_AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Hi StormE

Hi thank you for the idea to search already created scripts of the programs I use (I hadn't thought of that. I like to build things so it took over) The use of your script helped me alot.

I've learned so much by disecting others scripts and saved myself a lot of time in the process...OH and wasted a lot by going off on tangents but it's all learning. :)

Glad it did help even though it wasn't perfect. :(

Since it was a program I'm familar with it helped me get a better understanding of Autoit. It will take alot of time, but I can't wait for the day when it is all second nature!!!

I'm still waiting for that day. : :)

I had to tweak your script, it wasn't functional on my side. I notated in the script what I changed.

Sorry about that I do have a compiled version I use for cleanups. However, the source is lost somewhere the NAS if I'll have to dig it up.

I thought the version I sent you was the latest but appaerently I was wrong. :(

Link to comment
Share on other sites

Hi StormE,

No problem on the scripts it was good for me, The challanges are what I need to help learn. So it is a good thing. Hey maybe the main devs on the program changed something so your script wasn't correct anymore. I think that is something they do just to screw with us lol. I will keep working, I took last night off, My wife wasn't to happy with all the time I have spent with my second wife (The computer.) Anyways a new day awaits, I'll see what I can come up with.

And I lose things all the time so I understand that one to.

Prcssupport

Link to comment
Share on other sites

I got alot of work done today. Most of it was spent this evening. But nonetheless it is alot better. I have created several scripts that have made this project about 90% functional with complete automation. I have a few more bugs to work out. I will start to post code later after I have it straightened around. For now I'm heading to bed

Prcssupport

Link to comment
Share on other sites

Hey Everyone,

Sorry I have been busy the last few days. Alot going on here, Anyways. I have been working on the scripts, The more I think about them the more I realize I can build so much more functionality in to them. So I'm in a constant cycle of bettering the code.

Anyways, I have been working on a Malwarebytes script. I have been using a while\Wend but I keep getting an error. The error says that I have a WEnd but not a While, I have tried moving things around and I'm not having any luck with it. I found looking at the forum that people have been having some issues with MBAM and Automation, I had to use mouse move because I couldn't use controlclick. I figured a blockinput would work last case scenerio.

The below script starts MBAM and updates it. I haven't written anycode to deal will a complete software upgrade of mbam just def updates. I will work on that after I work the bugs out of this.

Anyways when I don't have the WEnd error, the script excutes all the way to the Auto scan funtion of MBAM. at which time 2 secs in to the scan it is terminated. I have a process close in place to shut down the program, and a processwaitclose, before respawning mbam with \AUTO.

Run(@HomeDrive & "\Program Files (x86)\Malwarebytes' Anti-Malware\mbam.exe")
WinWaitActive("[class:ThunderRT6FormDC]", "Perform flash scan")
WinMove("[class:ThunderRT6FormDC]", "Perform flash scan" ,0 ,0 ,778 ,593)
sleep(1500)
;BlockInput(1);Blocks user (input not blocked for testing purposes, just remove semicolon at the beginning to activate feature. )
MouseClick("left" ,182 ,128);selects update tab in main window
sleep(1500)
MouseClick( "left" ,102 ,328);selects check for updates
sleep(5000)
local $icount =25
While $iCount
If WinActive("[CLASS:#32770]","The database was successfully updated from version") Then
sleep(2500)
winkill("[CLASS:#32770]","The database was successfully updated from version")

If WinActive("[CLASS:#32770]","You have the latest database version") Then
sleep(2500)
WinKill("[CLASS:#32770]","You have the latest database version")
exitloop
EndIf
WEnd
If ProcessExists("mbam.exe") then
ProcessClose("mbam.exe")
MsgBox(0, "Malwarebytes updater", "Malwarebytes has been updated. Please standby for malware scan",5)
EndIf
ProcessWaitClose("mbam.exe")
Run(@HomeDrive & "\Program Files (x86)\Malwarebytes' Anti-Malware\mbam.exe \AUTO")
ProcessWaitClose("mbam.exe")

Hope you all have a good weekend, I will talk to you all another day, Thank you for your time.

Prcssupport

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