Tweaking.com Support Forums
Main Forum => Everything Else => Topic started 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
-
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
-
What do these do and how do I put into a bat file?
Chris
-
Here is mine I run before I head to bed. :wink:
Shane
-
Will this do all drives at once?
-
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
-
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
-
Wooo I got this.
Chris
-
I bet you have UAC enabled, right click on the bat file and click run as administrator :wink:
Shane
-
I have it off. Ill try as administrator. I checked and it is there.
Chris
-
Nope, same thing...uhhmm.
Chris
-
Normal defrag works from gui
Chris
-
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
-
yep
-
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
-
Same thing
Chris
-
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
-
Yep works fine
-
Then something is blocking the bat file. What AV do you have installed?
I know Avast has a sandbox mode (Which I disable)
Shane
-
avast but it doesn't show sandbox blocking. ill trun it off and try
Chris
-
Same thing
-
Try disabling avast all together and any other protection you have and see.
Very odd something is blocking the bat file.
Shane
-
I can run other bat files. I recently had diskeeper installed (realized i don't need it). could that be the problem
Chris
-
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
-
Curious for sure. My system runs perfect other wise
Chris
-
Try running the bat file from a cmd window instead of double clicking on it, see what happens then. :wink:
Shane
-
Works! How do i set this up for all my drives (c,i, j, k, and l)?
-
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
-
no .bat on first key and last key all I have "%1" %*. None of them have the @=
Chris
-
Export this reg key
HKEY_CLASSES_ROOT\batfile
zip it up and attach it. I will compare it to my system :wink:
Shane
-
Here ya go
-
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
-
next one
-
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
-
Like I said I don't have .bat file extension
-
Then save this to a reg file and run it
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
-
Keep windows registry editor version with it? then reboot or will it take affect
-
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
-
Problem still there, but this wasn't fixed. check this out
-
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
-
both run under my account (chris)
-
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
-
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
-
: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
-
Shane
I really appreciate you helping. Hope you didn't cus my to bad.
Chris
-
Just a little lol... jk
No problem as always :-)
Shane
-
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
-
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
-
Cool. Thanks much.
Chris
-
This works great with task scheduler. Regular defrag during the week and now the full one set for Sunday morning. Thanks Shane.
Chris
-
No problem :-)
Shane