AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Must run .exe twice before it will work correctly

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
firewater
Guest





PostPosted: Tue Jan 12, 2010 7:35 pm    Post subject: Must run .exe twice before it will work correctly Reply with quote

I am trying to put together a maintenance script that can be run with just a double click. I want to be able to give this to others so they can do it too. In testing here is what is happening. I double click, it starts to run, but when it gets to the point where there are keystrokes it stalls. I close out, and run again, it works fine. Every time, Every machine. Any suggestions? The script is below:

setkeydelay, 0500
sleep, 5000
runwait cleanmgr.exe
winwait Disk Cleanup for
Winactivate
send {tab 2} {enter 2}
run cmd.exe
sleep, 1000
send defrag.exe c: {enter}
sleep, 2000000
msgbox, Thank you, it is now safe to restart your computer.

Also, is there a way to get that msgbox to come up after the defrag has run, instead of putting a timer on it? Thanks for any help.
Back to top
Kellianjaxon



Joined: 04 Jan 2008
Posts: 102

PostPosted: Tue Jan 12, 2010 7:56 pm    Post subject: Reply with quote

RunWait waits for cleanmgr.exe process to close before continuing execution. I guess the reason it works every time other than the first must be that the code tries to run cleanmgr.exe as a duplicate process which the executable won't allow but closes the new instance immediately. Try using Run instead.
Code:
setkeydelay, 0500
sleep, 5000
run cleanmgr.exe
winwait Disk Cleanup for
Winactivate
send {tab 2} {enter 2}
run cmd.exe
sleep, 1000
send defrag.exe c: {enter}
sleep, 2000000
msgbox, Thank you, it is now safe to restart your computer.
Back to top
View user's profile Send private message
Guest






PostPosted: Tue Jan 12, 2010 8:19 pm    Post subject: Re: Must run .exe twice before it will work correctly Reply with quote

firewater wrote:
...msgbox to come up after the defrag...

Code:
Send, defrag.exe c:{Enter}
Process, Wait, defrag.exe
Process, WaitClose, defrag.exe
msgbox, Thank you, it is now safe to restart your computer.
Back to top
DJAnonimo



Joined: 10 Sep 2006
Posts: 157

PostPosted: Tue Jan 12, 2010 10:48 pm    Post subject: Reply with quote

Hey Kellianjaxon,

you do not need to run cmd.exe and send text to run defrag.
You can do it like this:
Code:
setkeydelay, 0500
sleep, 5000
run, cleanmgr.exe
winwait Disk Cleanup for
Winactivate
send {tab 2} {enter 2}
RunWait, defrag.exe C:
msgbox, Thank you, it is now safe to restart your computer.
Back to top
View user's profile Send private message MSN Messenger
Kellianjaxon



Joined: 04 Jan 2008
Posts: 102

PostPosted: Tue Jan 12, 2010 11:26 pm    Post subject: Reply with quote

DJAnonimo wrote:
Hey Kellianjaxon,

you do not need to run cmd.exe and send text to run defrag.
You can do it like this:

I know. Had it been my script, I'd have done it that way.
Back to top
View user's profile Send private message
poo_noo



Joined: 08 Dec 2006
Posts: 248
Location: Sydney Australia

PostPosted: Wed Jan 13, 2010 2:00 am    Post subject: Reply with quote

Heres another way. Not fully tested so use with care
Code:
;#############  Below is the auto-executing & persistent code ######################################

#NoEnv                  ; Recommended for performance and compatibility with future AutoHotkey releases.Avoids checking empty variables to see if they are environment variables.
SendMode Input            ; Recommended for new scripts due to its superior speed and reliability.
#persistent
#SingleInstance force
SetTitleMatchMode, 2
#MaxMem 2
#InstallKeybdHook
#NoTrayIcon
DetectHiddenWindows On

;############# Set timer for Process checker ######################################################

SetTimer, processchecker, 5000

;############# below is the timer for Process checker ############################################
; command line switches for defrag.exe are below
; defrag volume [-a] [-f][-v] [-?]
; http://support.microsoft.com/kb/283080

; start defrag
;run defrag.exe -c

Run, %comspec% /C defrag -c,,UseErrorLevel hide
Return



processchecker:
; not sure if should be checking DfrgNtfs.exe OR defrag.exe or both
Process, Exist, defrag.exe       ; check to see if Defrag (defrag.exe) is running.

NewPID = %ErrorLevel%
If errorlevel
   Sleep 900000 ; sleep 15 minutes
Else
   {
   msgbox, Thank you, I will now restart your computer.
   ; Force a reboot (reboot + force = 2 + 4 = 6):
   Shutdown, 6
   }
Return


Enjoy
_________________
Paul O
Back to top
View user's profile Send private message Visit poster's website
Firewater
Guest





PostPosted: Wed Jan 13, 2010 11:53 am    Post subject: Reply with quote

Thanks for the help, I tried them all, and they all worked wonderfully. I appreciate your time.
Back to top
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group