Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB Login Script to start defrag and gather info

Status
Not open for further replies.

flushie86

IS-IT--Management
Aug 11, 2004
17
US
Hi!

I currently work at a company that is looking to save some money, so I've been tasked with finding a cheap way to defrag the systems on the network. Since defrag.exe is part of Windows I figure a login script would be a perfect solution but we want a way to gather information. I figured the best was to use a defrag -a to do an analysis of the system and then act based on that. I'm finding it hard to find info on how to read out the information. I have a working script that does the defrag -a and outputs it to a log file, just not sure where to go from there to parse the file for the % total frag and the % file frag.

Option Explicit
Dim objShell, objProcEnv, sesDefrag

Set objShell = CreateObject("WScript.Shell")
Set objProcEnv = objShell.Environment("Process")
sesDefrag = objProcEnv("SessionName")

if sesDefrag = "" or LCase(sesDefrag) = "console" Then
objShell.Exec ("cmd /c del /F c:\defrag.log")
objShell.Exec ("cmd /c defrag -a c: > c:\defrag.log")

Dim filesys, demofile, createdate

Set filesys = CreateObject("Scripting.FileSystemObject")
Set demofile = filesys.GetFile("c:\defrag.log")
createdate = demofile.DateCreated
MsgBox "Created on " & createdate

End if

Set objShell = Nothing
Set objProcEnv = Nothing

WScript.Quit
 
Thank-you!!! This pointed me down the right road. As a side note is there a way to hide the cmd windows? so the user doesn't see anything?
 



Maybe second OPTIONAL argument in the Shell call, of ZERO.

Skip,
[sup][glasses]Don't let the Diatribe...
talk you to death![tongue][/sup][sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Use the Run method instead of the Exec.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I think XP Sp3 broke my script. I installed SP3 early this afternoon. The script I posted was working prior to the install, now all it does is spin wildly and take full control of one of my cpu cores. Suggestions???
 
most of my script is now functioning without error. I have a piece of code that opens my log file and reads out a line. I wanna take the line it outputs and search through it for 2 pieces of info. What is the best way?

Code:
Dim fso, MyFile, i,
Const ForReading = 1

Set fso = CreateObject("Scripting.FileSystemObject")
Set Myfile = fso_OpenTextFile(file, ForReading)
For i = 1 to 4
MyFile.ReadLine
Next

MsgBox MyFile.ReadLine
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top