By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,837 Members | 1,720 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,837 IT Pros & Developers. It's quick & easy.

Analyze/Defrag

devonknows
100+
P: 137
Good afternoon, if anyone can help me with this i would be most appreciative

Im looking for a way to invoke the Defrag through visual basic, the defrag part i can do but i want to be able to analyze it first, to see if actually needs defragmentation

i know you can use Run
--> CMD --> defrag.exe C: -A
to analyze it, but the question is does it log it anywere? if it writes to a log file then i can just read the logfile.

The problem is i have a lot of hard drives contained within my computer, and files are always being moved, deleted, transferred, renamed and general havoc really so i want to write an efficient program in vb that will take control of that side of it so its one less thing to worry about. I noticed a post on defrag vbscript but cant makes heads or tails out of it.

Any help would be appreciated

Thank you
Kind Regards
Devon.
Aug 15 '07 #1
Share this Question
Share on Google+
5 Replies


pureenhanoi
100+
P: 175
Im looking for a way to invoke the Defrag through visual basic, the defrag part i can do but i want to be able to analyze it first, to see if actually needs defragmentation
This is a big problem. Thats better if you use existing Defragment Tool from Windows

i know you can use Run
--> CMD --> defrag.exe C: -A
to analyze it, but the question is does it log it anywere? if it writes to a log file then i can just read the logfile.
If you want log to file, so do this command: "DEFRAG C: -A >D:\LogFile.TXT"

The problem is i have a lot of hard drives contained within my computer, and files are always being moved, deleted, transferred, renamed and general havoc really so i want to write an efficient program in vb that will take control of that side of it so its one less thing to worry about. I noticed a post on defrag vbscript but cant makes heads or tails out of it.
Defragment Tools can be schedule to run any time, any where (any driver) as you want
Aug 15 '07 #2

Expert 5K+
P: 8,434
This link seems as though it may be relevant, though probably not exactly what you're looking for.

The interesting part starts about half way down, with "Provide Event Logging for Disk Defragmenter Utility with WSH".
Aug 15 '07 #3

devonknows
100+
P: 137
Thank you both for the input, very helpful, now im faced with another difficutly, i wish to do the Defrag Analyze silently. but when i try and shell

%SystemRoot%\System32\Defrag.exe C: -a -v >D:\LogFile.txt

the window just appears and disapears and does not process the command and when i try and when i shell the command

%SystemRoot%\System32\CMD.exe /c defrag.exe c: -a -v >D:\LogFile.txt
(/c Switch terminates window after use)

it shows up the window, now is there anyway to make this window hide, or appear off the screen, i just dont want like 8 different command prompt windows popping up one after the other lol.

Thanks Again
Kind Regards
Devon
Aug 15 '07 #4

Expert 5K+
P: 8,434
Just from memory, doesn't Shell have one or more parameters that let you specify whether to run maximised/minimised, with/without focus?
Aug 16 '07 #5

devonknows
100+
P: 137
Just from memory, doesn't Shell have one or more parameters that let you specify whether to run maximised/minimised, with/without focus?
Thank you kindly, least someone has got their head screwed on, i remember when exactly what it was as soon as you mentioned Maximised/Minimised... It was the hide one. I will display the basic code for the primary question.

Expand|Select|Wrap|Line Numbers
  1.     'This code will Analyze drive C with the Administrator/Developer defrag Application
  2.     '(C:\Windows\System32\defrag.exe)
  3.     'Switches -
  4.     '     CMD: /c (Closes the CMD window after completion
  5.     '  Defrag: -a (Analyze Only) -v (Verbus Output) >d:\lg.log (Outputs Data To File)
  6.  
  7.     Shell "C:\Windows\System32\CMD.exe /c defrag.exe C: -a -v >C:lg.log", _
  8.                                        vbHide
  9.  
Shell Options:
vbNormalFocus
vbNormalNoFocus
vbMaximizedFocus
vbMinimizedFocus
vbMinimizedNoFocus
vbHide

As much basic information as i can think of but thanks for your help, Both of you :-)

Kind Regards
Devon
Aug 18 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.