473,398 Members | 2,427 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Defrag vbscript

I have found a vbscript on the internet that I would like to add some additional info to:

See below. I want to be able to get and save the computer name to each defrag log on a specified server in a specified folder...I've add computerName to the code below. Can someone tell me if I'm on the right track?

Also would like to be able to save time started and finished of each defrag run.
Expand|Select|Wrap|Line Numbers
  1. Const LogFile = "C:\Defrag.log"
  2.  
  3. Const DriveTypeRemovable = 1
  4. Const DriveTypeFixed = 2
  5. Const DriveTypeNetwork = 3
  6. Const DriveTypeCDROM = 4
  7. Const DriveTypeRAMDisk = 5
  8.  
  9. Set FSO = CreateObject("Scripting.FileSystemObject")
  10. Set Drives = FSO.Drives
  11.  
  12. For each Drive in Drives
  13.  if Drive.DriveType = 2 then
  14.   RunCmd Drive
  15.  end if
  16. Next 
  17.  
  18. Sub RunCmd(DriveString)
  19. Set WshShell = WScript.CreateObject("WScript.Shell")
  20. RunString = "%comspec% /c echo " & WeekDayName(WeekDay(Now), True) & " " & Now & " " & DriveString
  21. Return = WshShell.Run(RunString & " >> " & ComputerName & LogFile & " 2>&1", 0, TRUE)
  22. RunString = "%comspec% /c %WINDIR%\System32\Defrag.exe " & DriveString & " -f"
  23. Return = WshShell.Run(RunString & " >> " & ComputerName & LogFile & " 2>&1", 0, TRUE)
  24. Set WshShell = Nothing
  25. End Sub
  26.  
Jun 7 '07 #1
2 3867
I have found a vbscript on the internet that I would like to add some additional info to:

See below. I want to be able to get and save the computer name to each defrag log on a specified server in a specified folder...I've add computerName to the code below. Can someone tell me if I'm on the right track?

Also would like to be able to save time started and finished of each defrag run.
Expand|Select|Wrap|Line Numbers
  1. Const LogFile = "C:\Defrag.log"
  2.  
  3. Const DriveTypeRemovable = 1
  4. Const DriveTypeFixed = 2
  5. Const DriveTypeNetwork = 3
  6. Const DriveTypeCDROM = 4
  7. Const DriveTypeRAMDisk = 5
  8.  
  9. Set FSO = CreateObject("Scripting.FileSystemObject")
  10. Set Drives = FSO.Drives
  11.  
  12. For each Drive in Drives
  13.  if Drive.DriveType = 2 then
  14.   RunCmd Drive
  15.  end if
  16. Next 
  17.  
  18. Sub RunCmd(DriveString)
  19. Set WshShell = WScript.CreateObject("WScript.Shell")
  20. RunString = "%comspec% /c echo " & WeekDayName(WeekDay(Now), True) & " " & Now & " " & DriveString
  21. Return = WshShell.Run(RunString & " >> " & ComputerName & LogFile & " 2>&1", 0, TRUE)
  22. RunString = "%comspec% /c %WINDIR%\System32\Defrag.exe " & DriveString & " -f"
  23. Return = WshShell.Run(RunString & " >> " & ComputerName & LogFile & " 2>&1", 0, TRUE)
  24. Set WshShell = Nothing
  25. End Sub
  26.  
this is easy:
1.click Run in Start then
2.Type:
Expand|Select|Wrap|Line Numbers
  1. cmd /k defrag.exe /?
then OK it ;)

.:!M!LDEREMi:.
Jun 8 '07 #2
this is easy:
1.click Run in Start then
2.Type:
Expand|Select|Wrap|Line Numbers
  1. cmd /k defrag.exe /?
then OK it ;)

.:!M!LDEREMi:.
I know how to run it. The question was how do you change the logname to represent each computer's harddrive that you defrag.

For example I am running this for 80 computers ...


C:\computer1\defraglog.txt
C:\computer2\defraglog.txt
..........
Jun 8 '07 #3

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

Similar topics

15
by: Jim Hubbard | last post by:
Anyone got any info or code examples on defragging your hard drives?
2
by: csomberg | last post by:
SQL 2000 We took SQL Server offline last night and defragged the SAN. Should we reindex or will be be okay ? Thanks, Craig
0
by: Isaac | last post by:
You can perform a defrag by moving tablespaces. Is there a generic script that I can use to run after hours?
1
by: Mohammad-Reza | last post by:
Hi Please tell me how I can defrag my memory. Is there any component that can do this? Is it possible in .NET to do this? How can I do this? Thanks in advance
2
by: Jim Hubbard | last post by:
Anyone got any info or code examples on defragging your hard drives?
1
by: iwdu15 | last post by:
hi, i was wondering if anyone could help me or show some sample code to run disk defrag and handle the error if theres less than 15% free space...ive tried but i cant seem to get it to start to...
5
devonknows
by: devonknows | last post by:
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...
4
by: =?Utf-8?B?TG95ZCBDb3VudHM=?= | last post by:
My defrag stoped on windaws Visea Home. I have tried everything I know and it just wont work. I tried it in TOOLS and in MY COMPUTER opening C: and hit properties and pull tools and hit...
2
by: =?Utf-8?B?RHVhbmU=?= | last post by:
I unistalled Norton Ghost 14.0 and when I went to defrag my HD, I got this error -- basically saying it could not defrag the HD. Here are the specifics of my results. Any help is appreciated!...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.