Jump to content
Sign in to follow this  
chiners_68

Help with my first GUI Script..

Recommended Posts

right..

Somone a while back gave me the following js script for automatting a defrag. The script works a treat but i want to modift the temp stop button to be a skip button so its possible to skip the defrag if necessary. i still want the script to run after the 5 second period if the button hasnt been pressed. here is the js script.

var Fso = new ActiveXObject("Scripting.FileSystemObject");

var Act = new ActiveXObject("Wscript.Shell");

var Drv, strDrv, s, Defrag, V; V = "\\"

Disk()

function Disk()

{for ( var objEnum = new Enumerator(Fso.drives);!objEnum.atEnd();objEnum.moveNext())

{Drv = objEnum.item()

if (Drv.IsReady) {if (Drv.DriveType == "2")

Defrag = Act.Popup ("Preparing To Defrag This Drive, " + Drv.Path +

V+'\n'+ "Volume Name : " +Drv.VolumeName ,5,"Temp Stop", 0 + 32);

Act.Run("Defrag.exe " +Drv.Path+V+ " -F",0,true);

}} return;}

i am trying to create a GUI for this myself but im stuck from here. can anyone help with the js script or help me on the autoit one.

#include <GUIConstants.au3>

GUICreate("Defragmentation", 200, 100)

GUICtrlCreateLabel("Automating defrag in 6 seconds", 30, 10)

GUICtrlCreateButton("Skip", 70, 50, 60)

GUISetState(@SW_SHOW)

Sleep(6000)

As i said above i want the script to defrag after the sleep time & if the skip button is pressed in that 6 second period i want it to exit out the escript without defragging.

thnks in advance.

Share this post


Link to post
Share on other sites

#include <GUIConstants.au3>

GUICreate("Defragmentation", 200, 100) 
$info = GUICtrlCreateLabel("Automating defrag in 6 seconds", 30, 10)
$skip = GUICtrlCreateButton("Skip", 70, 50, 60)
GUISetState(@SW_SHOW)

$remain_old = 6
$skip_it = False
$start = TimerInit()

While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    If $msg = $skip Then 
        $skip_it = True
        ExitLoop
    EndIf
    
    $dif = TimerDiff($start)
    $remain = Int(6 - $dif/1000)
    If $remain <> $remain_old Then ; avoid flickering
        GUICtrlSetData($info,"Automating defrag in " & $remain & " seconds")
        $remain_old = $remain
    EndIf
    If $remain = 0 Then ExitLoop
Wend
GUIDelete()

If Not $skip_it Then Defrag()

Func Defrag()
    MsgBox(0,'Defrag',':-)')
EndFunc

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  

×
×
  • Create New...