Sign in to follow this  
Followers 0
iHonda

OMG my script is going crazy!

15 posts in this topic

Ok i so i wrote this script that is supposed to run the disk clean up program and stuff and write the instructions to a notepad document but everytime i run the script it launches it self like 8 times its really irratating to close all of the windows and end all of the scipts can you guys help me?? i dont know how to post that Code thing like everyone else does so ill attach it.


A great place to start Autoit 1-2-3

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Ok i so i wrote this script that is supposed to run the disk clean up program and stuff and write the instructions to a notepad document but everytime i run the script it launches it self like 8 times its really irratating to close all of the windows and end all of the scipts can you guys help me?? i dont know how to post that Code thing like everyone else does so ill attach it.

To post code is easy. Above the reply text window, notice the button roughly in the middle, looks like a # in a box? Paste in your code and select it, then click the # button and it'll add the code tags around it. Of course this does not help you with your problem but at least now you know how to do the "code thing". :)

Edited by Peter Hamilton-Scott

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

EDIT:

For the sake of others, i'll repost the code in a code "quote".

; ----------------------------------------------------------------------------
;
; AutoIt Version: 3.1.0
; Author:        A.N.Other <myemail@nowhere.com>
;
; Script Function:
;   Template AutoIt script.
;
; ----------------------------------------------------------------------------

; Script Start

;Displays tip from tray icon

TrayTip("Initiating DisKlean", "Now Starting DisKlean Please refer to the notepad that is being opened for instructions.", 30, 1)

;Launchs notepad, & writes info to notepad document

Run("notepad.exe")
Send("~~DisKlean By: Zmaster)atF(~~{ENTER}")
Send("{ENTER}DO NOT CLOSE THIS WINDOW IT WILL CLOSE IT SELF LATER{ENTER}")

Send("{ENTER}Thank you for using my program, I promise that it is 100% safe to use.This window will automaticaly close itself when the wizard is done running. Please follow all instructions on this page once the text has idled or you will freeze the script if that happens restart the script or the wizard will not work.{ENTER}")


;Launchs Disk Clean Up

Sleep(800)
Run("cleanmgr.exe")
WinWaitActive("Disk Cleanup for  (C:)")
Sleep(800)


;Writes the Disk Clean Up instructions to Notepad


WinActivate("Untitled - Notepad")
Send("{ENTER}1. Make sure that the following Files to Delete are selected in the Disk Clean up for (C:) window")
Send("{ENTER}Downloaded Program Files{ENTER}")
Send("{ENTER}Temporary Internet Files{ENTER}")
Send("{ENTER}Recycle Bing{ENTER}")
Send("{ENTER}Temporary file{ENTER}")
Send("{ENTER}WebClient/Publisher Temporary Files{ENTER}")
Send("{ENTER}Compress old files{ENTER}")
Send("{ENTER}After all of those boxes are selected click OK.{ENTER}")
Sleep(50000)

Send("{ENTER}Thank you for using DisKlean By:Zmaster)atF( if you have any comments or questions send them to <ihonda1@gmail.com>. I strongly recommend that you run this program at least twice a month so that it does not take too long, a good schedule would be to run the program on the first of the month and then again on either the sixteenth or seventeenth. The more often you run the program the better it will work.")

#)

Edited by nfwu

Share this post


Link to post
Share on other sites

Your Send() would triggering the 2nd instance of the script as you do not use WinWaitActive to wait for the Notepad window, so it send to the item which has focus, your script. FAQ 14 will help to prevent uncontrolled 2 instances of your script. My additions are commented with ;ADDED in the line.

; ----------------------------------------------------------------------------
;
; AutoIt Version: 3.1.0
; Author:        A.N.Other <myemail@nowhere.com>
;
; Script Function:
;   Template AutoIt script.
;
; ----------------------------------------------------------------------------

; Script Start
; Place at the top of your script;ADDED
$g_szVersion = "My Script 1.1";ADDED
If WinExists($g_szVersion) Then Exit; It's already running;ADDED
AutoItWinSetTitle($g_szVersion);ADDED
; Rest of your script goes here;ADDED


;Displays tip from tray icon

TrayTip("Initiating DisKlean", "Now Starting DisKlean Please refer to the notepad that is being opened for instructions.", 30, 1)

;Launchs notepad, & writes info to notepad document

Run("notepad.exe")
WinWaitActive('Untitled');ADDED
Send("~~DisKlean By: Zmaster)atF(~~{ENTER}")
Send("{ENTER}DO NOT CLOSE THIS WINDOW IT WILL CLOSE IT SELF LATER{ENTER}")

Send("{ENTER}Thank you for using my program, I promise that it is 100% safe to use.This window will automaticaly close itself when the wizard is done running. Please follow all instructions on this page once the text has idled or you will freeze the script if that happens restart the script or the wizard will not work.{ENTER}")


;Launchs Disk Clean Up

Sleep(800)
Run("cleanmgr.exe")
WinWaitActive("Disk Cleanup for  (C:)")
Sleep(800)


;Writes the Disk Clean Up instructions to Notepad


WinActivate("Untitled - Notepad")
Send("{ENTER}1. Make sure that the following Files to Delete are selected in the Disk Clean up for (C:) window")
Send("{ENTER}Downloaded Program Files{ENTER}")
Send("{ENTER}Temporary Internet Files{ENTER}")
Send("{ENTER}Recycle Bing{ENTER}")
Send("{ENTER}Temporary file{ENTER}")
Send("{ENTER}WebClient/Publisher Temporary Files{ENTER}")
Send("{ENTER}Compress old files{ENTER}")
Send("{ENTER}After all of those boxes are selected click OK.{ENTER}")
Sleep(50000)

Send("{ENTER}Thank you for using DisKlean By:Zmaster)atF( if you have any comments or questions send them to <ihonda1@gmail.com>. I strongly recommend that you run this program at least twice a month so that it does not take too long, a good schedule would be to run the program on the first of the month and then again on either the sixteenth or seventeenth. The more often you run the program the better it will work.")

Share this post


Link to post
Share on other sites

If you run your script from SciTe it writes all over the script so it appears there is something wrong with the activation of notepad. I am assuming that you are running it from a compiled exe, Change the name of the exe to something else and try it again, I would suggest test.exe to begin with.



Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

thanx Mhz wut u changed fixed the problem. but now i have another problem i dont remember how to close the notepad window :">

Edited by Zmaster

A great place to start Autoit 1-2-3

Share this post


Link to post
Share on other sites

Look at the notepad demo in the helpfile.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Look at the notepad demo in the helpfile.

; ----------------------------------------------------------------------------
;
; AutoIt Version: 3.1.0
; Author:        A.N.Other <myemail@nowhere.com>
;
; Script Function:
;   Template AutoIt script.
;
; ----------------------------------------------------------------------------

; Script Start
; Place at the top of your script;ADDED
$g_szVersion = "My Script 1.1";ADDED
If WinExists($g_szVersion) Then Exit; It's already running;ADDED
AutoItWinSetTitle($g_szVersion);ADDED
; Rest of your script goes here;ADDED


;Displays tip from tray icon

TrayTip("Initiating DisKlean", "Now Starting DisKlean Please refer to the notepad that is being opened for instructions.", 30, 1)

;Launchs notepad, & writes info to notepad document

Run("notepad.exe")
WinWaitActive('Untitled');ADDED
Send("~~DisKlean By: Zmaster)atF(~~{ENTER}")
Send("{ENTER}DO NOT CLOSE THIS WINDOW IT WILL CLOSE IT SELF LATER{ENTER}")

Send("{ENTER}Thank you for using my program, I promise that it is 100% safe to use.This window will automaticaly close itself when the wizard is done running. Please follow all instructions on this page once the text has idled or you will freeze the script if that happens restart the script or the wizard will not work.{ENTER}")


;Launchs Disk Clean Up

Sleep(800)
Run("cleanmgr.exe")
WinWaitActive("Disk Cleanup for  (C:)")
Sleep(800)


;Writes the Disk Clean Up instructions to Notepad


WinActivate("Untitled - Notepad")
Send("{ENTER}1. Make sure that the following Files to Delete are selected in the Disk Clean up for (C:) window")
Send("{ENTER}Downloaded Program Files{ENTER}")
Send("{ENTER}Temporary Internet Files{ENTER}")
Send("{ENTER}Recycle Bing{ENTER}")
Send("{ENTER}Temporary file{ENTER}")
Send("{ENTER}WebClient/Publisher Temporary Files{ENTER}")
Send("{ENTER}Compress old files{ENTER}")
Send("{ENTER}After all of those boxes are selected click OK.{ENTER}")
Sleep(50000)
WinClose("Untitled - Notepad")
WinWaitActive("Notepad", "The text in the Untitled file has changed")
Send("!n"); !y= yes !n= no

hope this helps..

Sleep(50000) thats quite along wait :)

Edited by slightly_abnormal

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

If ProcessExists("notepad.exe") Then
ProcessClose("notepad.exe")
endif

Edited by thatsgreat2345

Share this post


Link to post
Share on other sites

lol ya but some times the disc clean takes a long time so i had to make it long to acomadate that unless there is a way to detect when its done.


A great place to start Autoit 1-2-3

Share this post


Link to post
Share on other sites

lol ya but some times the disc clean takes a long time so i had to make it long to acomadate that unless there is a way to detect when its done.

Like maybe.. RunWait instead of just Run... or ProcessWaitClose...?

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

i didnt think of that thanx, but how do i get it to write the note pad stuff?? since the runwait thing pauses the script for the cleaner??

Edited by Zmaster

A great place to start Autoit 1-2-3

Share this post


Link to post
Share on other sites

i didnt think of that thanx, but how do i get it to write the note pad stuff?? since the runwait thing pauses the script for the cleaner??

I Think this might work better for you:

Opt("WinTitleMatchMode", 4)

$g_szVersion = "My Script 1.1"
If WinExists($g_szVersion) Then Exit
AutoItWinSetTitle($g_szVersion)


TrayTip("Initiating DisKlean", "Now Starting DisKlean Please refer to the notepad that is being opened for instructions.", 30, 1)

Run("notepad.exe")
WinWaitActive("classname=Notepad")
WinSetTitle("classname=Notepad", "", "Instructions")
ControlSend("classname=Notepad", "", "Edit1", _
                "~~DisKlean By: Zmaster)atF(~~" & @CRLF & @CRLF _
                & "DO NOT CLOSE THIS WINDOW IT WILL CLOSE IT SELF LATER" & @CRLF & @CRLF _
                & "Thank you for using my program, I promise that it is 100% safe to use." & @CRLF _
                & "This window will automaticaly close itself when the wizard is done running." & @CRLF _
                & "Please follow all instructions on this page for optimal script operation." & @CRLF & @CRLF _
                & "1. Make sure that the following Files to Delete are selected in the Disk Clean up for (C:) window" & @CRLF _
                & "Downloaded Program Files" & @CRLF _
                & "Temporary Internet Files" & @CRLF _
                & "Recycle Bing" & @CRLF _
                & "Temporary file" & @CRLF _
                & "WebClient/Publisher Temporary Files" & @CRLF _
                & "Compress old files" & @CRLF _
                & "After all of those boxes are selected click OK." & @CRLF)
Run("cleanmgr.exe")
ProcessWaitClose("cleanmgr.exe")
ProcessClose("notepad.exe")

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

cool thank you, would u guys happen to know if there is a way that i can eliminate the need for a user to select the differnt things and just have the script do it on its own??

Edited by Zmaster

A great place to start Autoit 1-2-3

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

No problem mate, hope you learn something from it. :)

Edit:

Yes there is a way, actually there are a couple of ways you could try, one is Sending {up} or {down} and {space} to select the item(s) that are to be cleaned, OR you could look into the command "ControlListView" (which i dont have any knowledge about, but you could try it) thats my best shot if i where you. :mellow:

Edit2(doh):

Ok, i looked into this a little, and i found out that the easiest way to do it was to use ControlSend, ill post my version of it here, but you need to change the text it searches for, ie. the "diskutrymme" to whatever text you can find in the DiscCleaning window(remember the CaSeInG).

Edit3(....):

Doh! Forgot to upload my version ... to little sleep last night i guess... ah well, here it is

Edited by FreeFry

Share this post


Link to post
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
Sign in to follow this  
Followers 0