AutoHotkey Community

It is currently May 27th, 2012, 1:17 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: January 12th, 2010, 8:35 pm 
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.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 12th, 2010, 8:56 pm 
Offline

Joined: January 5th, 2008, 12:11 am
Posts: 102
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.


Report this post
Top
 Profile  
Reply with quote  
PostPosted: January 12th, 2010, 9:19 pm 
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.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 12th, 2010, 11:48 pm 
Offline

Joined: September 10th, 2006, 1:41 pm
Posts: 157
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 13th, 2010, 12:26 am 
Offline

Joined: January 5th, 2008, 12:11 am
Posts: 102
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 13th, 2010, 3:00 am 
Offline

Joined: December 8th, 2006, 5:17 am
Posts: 248
Location: Sydney Australia
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 13th, 2010, 12:53 pm 
Thanks for the help, I tried them all, and they all worked wonderfully. I appreciate your time.


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: iDrug, Ohnitiel and 21 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group