Tweaking.com Support Forums

Main Forum => Everything Else => Topic started by: chris635 on October 29, 2012, 12:56:12 pm

Title: Defragment
Post by: chris635 on October 29, 2012, 12:56:12 pm
Hey Guys

  Looking for a way to completely defrag my drives without using third party defragmenters. I read somewhere that -w switch is not supported in windows 7. Is this true? Normally I use "defrag c: -v -w".


Chris
Title: Re: Defragment
Post by: Shane on October 29, 2012, 01:14:55 pm
Put this in a bat file :wink:

start /wait %SYSTEMDRIVE%\Windows\System32\defrag.exe C: /H /V
start /wait %SYSTEMDRIVE%\Windows\System32\defrag.exe C: /H /V /X

Shane
Title: Re: Defragment
Post by: chris635 on October 29, 2012, 01:20:55 pm
What do these do and how do I put into a bat file?


Chris
Title: Re: Defragment
Post by: Shane on October 29, 2012, 01:45:58 pm
Here is mine I run before I head to bed. :wink:

Shane
Title: Re: Defragment
Post by: chris635 on October 29, 2012, 01:46:15 pm
Will this do all drives at once?
Title: Re: Defragment
Post by: Shane on October 29, 2012, 01:47:19 pm
Just the C: drive. If you want to add other drives you do it like this, you will see D: is added

start /wait %SYSTEMDRIVE%\Windows\System32\defrag.exe C: D: /H /V
start /wait %SYSTEMDRIVE%\Windows\System32\defrag.exe C: D: /H /V /X

Shane
Title: Re: Defragment
Post by: chris635 on October 29, 2012, 01:49:37 pm
Thanks for that. Right when you sent it I figured out how to make bat file. It was easier than I thought. Good to know.


Chris
Title: Re: Defragment
Post by: chris635 on October 29, 2012, 01:54:58 pm
Wooo I got this.


Chris
Title: Re: Defragment
Post by: Shane on October 29, 2012, 01:57:10 pm
I bet you have UAC enabled, right click on the bat file and click run as administrator :wink:

Shane
Title: Re: Defragment
Post by: chris635 on October 29, 2012, 02:00:28 pm
I have it off. Ill try as administrator. I checked and it is there.


Chris
Title: Re: Defragment
Post by: chris635 on October 29, 2012, 02:02:10 pm
Nope, same thing...uhhmm.


Chris
Title: Re: Defragment
Post by: chris635 on October 29, 2012, 02:03:59 pm
Normal defrag works from gui


Chris
Title: Re: Defragment
Post by: Shane on October 29, 2012, 02:06:10 pm
Very odd. Can you run it from a cmd window your self?

Also try this in the bat file

start /wait %SYSTEMDRIVE%\Windows\System32\defrag.exe C: /H /V
start /wait %SYSTEMDRIVE%\Windows\System32\defrag.exe C: /H /V /X

Shane
Title: Re: Defragment
Post by: chris635 on October 29, 2012, 02:10:14 pm
yep
Title: Re: Defragment
Post by: Shane on October 29, 2012, 02:12:37 pm
OK so you can run defrag from cmd manually.

Try this, move the bat file to the root of the C: drive and try it.

I notice where you are running the bat file that there is a space in the path. That might be getting in the way.

Shane
Title: Re: Defragment
Post by: chris635 on October 29, 2012, 02:19:32 pm
Same thing


Chris
Title: Re: Defragment
Post by: Shane on October 29, 2012, 02:22:39 pm
what the crap lol. I wonder if something is blocking the bat file?

Here is a way to test. Open a cmd.exe window and past this in

start /wait %SYSTEMDRIVE%\Windows\System32\defrag.exe C: /H /V

Does it work?

Shane
Title: Re: Defragment
Post by: chris635 on October 29, 2012, 02:25:33 pm
Yep works fine
Title: Re: Defragment
Post by: Shane on October 29, 2012, 02:29:23 pm
Then something is blocking the bat file. What AV do you have installed?

I know Avast has a sandbox mode (Which I disable)

Shane
Title: Re: Defragment
Post by: chris635 on October 29, 2012, 02:31:56 pm
avast but it doesn't show sandbox blocking. ill trun it off and try


Chris
Title: Re: Defragment
Post by: chris635 on October 29, 2012, 02:34:02 pm
Same thing
Title: Re: Defragment
Post by: Shane on October 29, 2012, 02:36:04 pm
Try disabling avast all together and any other protection you have and see.

Very odd something is blocking the bat file.

Shane
Title: Re: Defragment
Post by: chris635 on October 29, 2012, 02:38:48 pm
I can run other bat files. I recently had diskeeper installed (realized i don't need it). could that be the problem

Chris
Title: Re: Defragment
Post by: Shane on October 29, 2012, 02:51:07 pm
Dont see why it would be. You can run the commands from a cmd window but not from a bat file.

Not sure what is going on there. It is like the bat file doesnt have permission to access the system32 dir.

Shane
Title: Re: Defragment
Post by: chris635 on October 29, 2012, 02:52:14 pm
Curious for sure. My system runs perfect other wise

Chris
Title: Re: Defragment
Post by: Shane on October 29, 2012, 02:53:32 pm
Try running the bat file from a cmd window instead of double clicking on it, see what happens then. :wink:

Shane
Title: Re: Defragment
Post by: chris635 on October 29, 2012, 02:57:02 pm
Works! How do i set this up for all my drives (c,i, j, k, and l)?
Title: Re: Defragment
Post by: Shane on October 29, 2012, 03:00:43 pm
OK so it works from a cmd window. But it should be cmd.exe that is running the bat file when you double click it.

I wonder if something else is running the bat file instead?

Do you have this key in your registry?
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.BAT

And what do you have for these?
[HKEY_CLASSES_ROOT\.bat]
@="batfile"

[HKEY_CLASSES_ROOT\.bat\PersistentHandler]
@="{5e941d80-bf96-11cd-b579-08002b30bfeb}"

[HKEY_CLASSES_ROOT\batfile\shell\open\command]
@="\"%1\" %*"

Shane
Title: Re: Defragment
Post by: chris635 on October 29, 2012, 03:11:27 pm
no .bat on first key and last key all I have "%1" %*. None of them have the @=

Chris
Title: Re: Defragment
Post by: Shane on October 29, 2012, 03:15:09 pm
Export this reg key

HKEY_CLASSES_ROOT\batfile

zip it up and attach it. I will compare it to my system :wink:

Shane
Title: Re: Defragment
Post by: chris635 on October 29, 2012, 03:21:50 pm
Here ya go
Title: Re: Defragment
Post by: Shane on October 29, 2012, 03:26:45 pm
Ok those match my system.

Now export
HKEY_CLASSES_ROOT\.bat

And I will compare it.

Also you said you odnt have
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.bat

Because I do on my system.

Shane
Title: Re: Defragment
Post by: chris635 on October 29, 2012, 03:30:24 pm
next one
Title: Re: Defragment
Post by: Shane on October 29, 2012, 03:31:56 pm
Matches as well.

The only thing I have seen different is you dont have these

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.bat]

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.bat\OpenWithProgids]
"batfile"=hex(0):

Shane
Title: Re: Defragment
Post by: chris635 on October 29, 2012, 03:34:37 pm
Like I said I don't have .bat file extension
Title: Re: Defragment
Post by: Shane on October 29, 2012, 03:35:20 pm
Then save this to a reg file and run it

Quote
Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.bat]

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.bat\OpenWithProgids]
"batfile"=hex(0):

Shane
Title: Re: Defragment
Post by: chris635 on October 29, 2012, 03:36:44 pm
Keep windows registry editor version with it? then reboot or will it take affect
Title: Re: Defragment
Post by: Shane on October 29, 2012, 03:37:40 pm
Yes you have to have the top line.

Once added to the reg reboot and confirm the key is in the reg. If it is try the bat file again :-)

Shane
Title: Re: Defragment
Post by: chris635 on October 29, 2012, 03:51:16 pm
Problem still there, but this wasn't fixed. check this out
Title: Re: Defragment
Post by: Shane on October 29, 2012, 03:53:29 pm
Thats is right.

Check something for me. close and cmd.exe that is running.

Run the bat file, when you get the error leave it there. Open task manager. Do you see cmd.exe running? If so what user account does it show it is running under?

Once done open a normal cmd.exe window. In the task scheduler what user name does it show?

Shane
Title: Re: Defragment
Post by: chris635 on October 29, 2012, 04:02:17 pm
both run under my account (chris)
Title: Re: Defragment
Post by: Shane on October 29, 2012, 04:03:08 pm
Well I am out of ideas LOL

Makes no sense how it can run find from a cmd window but not when double clicked.

Shane
Title: Re: Defragment
Post by: chris635 on October 29, 2012, 04:06:29 pm
I figured it out. I was running from cubic explorer. Has to be run from windows explorer (oopps Sorry, all the other bat files run from it). How do I set this up to defrag all drives?

Chris
Title: Re: Defragment
Post by: Shane on October 29, 2012, 04:08:07 pm
 :tongue:

Like I said before.

Defrag C:
start /wait %SYSTEMDRIVE%\Windows\System32\defrag.exe C: /H /V
start /wait %SYSTEMDRIVE%\Windows\System32\defrag.exe C: /H /V /X

Defrag C: & D:
start /wait %SYSTEMDRIVE%\Windows\System32\defrag.exe C: D: /H /V
start /wait %SYSTEMDRIVE%\Windows\System32\defrag.exe C: D: /H /V /X

You can see how you just add the drive letter to the commands.

Shane
Title: Re: Defragment
Post by: chris635 on October 29, 2012, 05:06:28 pm
Shane

  I really appreciate you helping. Hope you didn't cus my to bad.


Chris
Title: Re: Defragment
Post by: Shane on October 29, 2012, 05:14:28 pm
Just a little lol... jk

No problem as always :-)

Shane
Title: Re: Defragment
Post by: chris635 on November 03, 2012, 05:30:06 pm
Shane


I have two questions.

1. Do you have a bat file to fully defrag vista (my laptop).

2. Is there anyway to set up bat file for my desktop (win7) and laptop to run these bat files at a specific time and date.



Chris
Title: Re: Defragment
Post by: Shane on November 03, 2012, 09:04:07 pm
Here is vistas

start /wait %SYSTEMDRIVE%\Windows\System32\defrag.exe -c -w

Should do all drives.

And as for #2. The task scheduler is your friend :-)
http://www.tweaking.com/articles/pages/using_the_power_of_the_windows_task_scheduler,1.html

Shane
Title: Re: Defragment
Post by: chris635 on November 04, 2012, 02:24:26 am
Cool. Thanks much.



Chris
Title: Re: Defragment
Post by: chris635 on November 04, 2012, 03:15:10 pm
This works great with task scheduler. Regular defrag during the week and now the full one set for Sunday morning. Thanks Shane.



Chris
Title: Re: Defragment
Post by: Shane on November 05, 2012, 11:14:20 am
No problem :-)

Shane