Jump to content

CALL/RUN defrag.exe from WPI?


Recommended Posts

I'm currently running a defrag.cmd (below) from WPI programlist (as normal applications in config.js) to defrag systemdrive.

Would it work putting something like

cmd1[pn]=['%WinDir%\\system32\\defrag.exe %SystemDrive% -f']

directly into WPI instead of running an external batch?

defrag.cmd

cmdow @ /HID
@echo off

rem Defragmenterer systemdisk.
call %WinDir%\system32\defrag.exe %SystemDrive% -f

exit

Link to comment
Share on other sites


Dude, I was just too lazy to do a fresh test install ;)

What im thinking is that WPI will pass on to next "task" immediatly after defrag STARTS, whilst in a batch I can CALL the defrag and have the batch wait to exit til defrag is done, so WPI don't skip to next task before defrag has completed.

Link to comment
Share on other sites

defrag /?

Usage:

defrag <volume> [-a][-f] [-v] [-?]

volume drive letter or mount point (d: or d:\vol\mountpoint)

-a Analyze only

-f Force defragmentation even if free space is low

-v Verbose output

-? Display this help text

so just start /wait and then the commandline

Link to comment
Share on other sites

actually since its a command utility that wouldnt work, thats why I do CALL not start /wait. Cause it opens up a new command window and the first is terminated.

If that is the Call command of the command interpreter, then you should only need to use it for calling a batch file from another or use it to call a label within the batch file. Luckily the command interpreter may overlook the mistake, but it does not mean that you should use it.

Most commandline tools will open a command interpreter if needed. Those few that do not, you can just execute another command interpreter by using "%Comspec% /c " or "CMD /c ". The /c puts the command interpreter into commandline mode so you can pass your command to it directly.

Defrag will open the command interpreter when executed directly.

Link to comment
Share on other sites

Have you thought of using a VBS file to defrag, this will run the defrag threw all partition and harddrives

Dim Act : Set Act = CreateObject("Wscript.Shell")

Dim Fso : Set Fso = CreateObject("Scripting.FileSystemObject")

Dim Df : Set Df = Fso.Drives

For Each strDf in Df

If strDf.DriveType = 2 Then

Act.Run("Defrag " & strDf & "\ -F"),1,True

End If

Next

Link to comment
Share on other sites

The vbs starts the defrag in it defualt cmd window, as to the wpi question I

do not know about this as I do not use it. You can start the VBS from a

cmd script.

StartDefrag.cmd

This does not need Start /Wait as it will only flash on the screen a quick cmd promt.

Start THE_LOCATION_OF_DEFRAG.VBS
I have add a delete the StartDefrag.cmd to the script.

This needs the quotes ("PLACE_THE_LOCATION_OF_STARTDEFRAG.CMD_HERE")

Re-Edit Save As Defrag.vbs

Dim Act : Set Act = CreateObject("Wscript.Shell")

Dim Fso : Set Fso = CreateObject("Scripting.FileSystemObject")

Dim Df : Set Df = Fso.Drives

For Each strDf in Df

If strDf.DriveType = 2 Then

Act.Run("Defrag " & strDf & "\ -F"),1,True

End If

Next

If Fso.FileExists("PLACE_THE_LOCATION_OF_STARTDEFRAG.CMD_HERE") Then

Fso.DeleteFile("PLACE_THE_LOCATION_OF_STARTDEFRAG.CMD_HERE")

End If

Since I do not use WPI you could ask in the forums if you can run a VBS file directly from

WPI, and if you can then use the first code.

Edited by gunsmokingman
Link to comment
Share on other sites

  • 2 months later...

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...