Jump to content

[Help] Batch Scripting System Cleanup


Recommended Posts

Hey all,

I know I ask a lot of you guys, but ya'll are always so very helpful.

I'm trying to make a batch file that will detail info about a system and echo info into a txt file (IE Cache Size, # of IE Temp Files, MB of system temp files (as listed in Disk Cleanup), # of Windows Prefetch Files and # of files in C:\Quarantine, Size of the Desktop folder for the current profile, Amount of system ram (as in computer properties) and Free disk space.)

Echo Number of Windows Prefetch Files Cleared: >> %systemdrive%\temp\%computername%_CheckList_%dd%_%mm%-%yy%.txt
Attrib.exe /s %SYSTEMROOT%\Prefetch\*.pf |find /c /v "" >> %systemdrive%\temp\%computername%_CheckList_%dd%_%mm%-%yy%.txt
DEL /q %SYSTEMROOT%\Prefetch\*.pf

My first hurdle... I can't get my batch to echo to the same line..

I would like the output to be something like:

"Number of Prefetch Files = xxx"

instead of:

"Number of Prefetch Files ="

"xxx"

Second, the Attrib command works ok for Prefetch folder... but for example, the IE Temp folder it will only echo that there is 1 file. How do we get a correct reading of how many temp IE files there are?

Third, is there an easy way to script a batch to interpret the IE Cache size (Registry value is in hex) and then echo the dec. value into a txt file?

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\5.0\Cache\Content]

"CacheLimit"=dword:00019000

So, the overall outcome I am looking for is something like this...

Available Memory: xxx

Free Disk Space: xxx

Desktop File Size: xxx

IE Temp Files: xxx

IE Cache Size: xxx

Quarantined Files: xxx

Windows Temp Files: xxx

Windows Prefetch Files: xxx

Link to comment
Share on other sites


This should help:

For /F %%A in ('Attrib /S "%USERPROFILE%\Local Settings\Temporary Internet Files\*" ^| Find /C /V "File not found - "') Do Echo IE Temp Files: %%A
For /F "Tokens=3" %%A in ('Reg Query "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\5.0\Cache\Content" /v CacheLimit') Do Set /A IECacheSize=%%A / 1024
Echo IE Cache Size: %IECacheSize% MB
For /F %%A in ('Attrib /S %SYSTEMROOT%\Prefetch\*.pf ^| Find /C /V "File not found - "') Do Echo Windows Prefetch Files: %%A

Link to comment
Share on other sites

Sweet! This works like a charm!!! (I'm terrible at arrays)

For drive free space I had the idea of running defrag analysis from command exporting it and then using the find feature to grab the info from there... so I think I should be able to get that part.

How would I query installed RAM ammount, Desktop File size and windows temp files (like in Disk Cleanup... as it checks for several temp locations)?

Link to comment
Share on other sites

Try this VBS script it will do what you wanted.

Save As SizeInfo.vbs

 Dim Act :Set Act = CreateObject("Wscript.Shell")
Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")
'-> Varibles For Sizes
Dim KB :KB = 1024
Dim MB :MB = 1048576
Dim GB :GB = 1073741824
'-> Varible Desktop Path
Dim Dtop
Set Dtop = Fso.GetFolder(Act.SpecialFolders("Desktop"))
'-> Varible Ie Temp Path
Dim IeTp
IeTp = Act.ExpandEnvironmentStrings("%UserProfile%\Local Settings\Temporary Internet Files")
Set IeTp = Fso.GetFolder(IeTp)
'-> Varible Ie Cache Path
Dim IeCh
IeCh = "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\5.0\Cache\Content\CacheLimit"
'-> Varible Windows Prefetch Path
Dim WnPr
Set WnPr = Fso.GetFolder(Act.ExpandEnvironmentStrings("%Windir%\Prefetch"))
'-> Varible Windows Temp Path
Dim WTmp, WnTp
WTmp = Act.ExpandEnvironmentStrings("%Windir%\Temp")
'-> Varibles Text File
Dim Ts, Txt
Txt = Dtop & "\SysInfo.txt"
Set Ts = Fso.CreateTextFile(Txt)
'-> Re-Usable Varibles
Dim Obj, Str
'-> Get Ram Amount
For Each Obj in GetObject("winmgmts:\\.\root\CIMV2").ExecQuery("SELECT * FROM Win32_ComputerSystem")
Ts.WriteLine "Installed Ram " & Formatnumber(Obj.TotalPhysicalMemory/MB,2) & " MB" & vbCrLf
Next
'-> Desktop Size
Obj = Dtop.Size
FormatSze()
Ts.WriteLine "Desktop Size " & Str
'-> Ie Temp Size
Obj = IeTp.Size
FormatSze()
Ts.WriteLine "Ie Temp Size " & Str
'-> Ie Cache
Str = FormatNumber(Act.RegRead(IeCh)/KB,2)
Ts.WriteLine "Ie Cache Size " & Str & " MB"
'-> Windows Prefetch Size
Obj = WnPr.Size
FormatSze()
Ts.WriteLine "Prefetch Size " & Str
'-> Windows Temp Size And Demo How To Check For A Folder
If Fso.FolderExists(WTmp) Then
Set WnTp = Fso.GetFolder(WTmp)
Obj = WnTp.Size
FormatSze()
Ts.WriteLine "Win Temp Size " & Str & vbCrLf
Else
Ts.WriteLine "Windows Temp Missing" & vbCrLf
End If
'-> Varibles To Use In Disk Info
Dim Drv, Free, Size ,Used
'-> Disk Information
For Each Drv In Fso.Drives
If Drv.DriveType = 2 Then
Str = Drv.TotalSize - Drv.FreeSpace
Used = Formatnumber(Str/GB,2)
Size = Formatnumber(Drv.TotalSize/GB,2)
Free = Formatnumber(Drv.FreeSpace/GB,2)
If Size >= 10 Then Size = Size
If Size =< 10 Then Size = "0" & Size
If Free >= 10 Then Free = Free
If Free =< 10 Then Free = "0" & Free
If Used >= 10 Then Used = Used
If Used =< 10 Then Used = "0" & Used
Ts.WriteLine _
"Drive Letter " & Drv.DriveLetter & ":\ " & _
"Size " & Size & vbTab & _
"Free " & Free & vbTab & _
"Used " & Used
End If
Next
'-> Format The Size
Function FormatSze()
If Obj >= GB Then
Str = FormatNumber(Obj/GB,2) & " GB"
ElseIf Obj >= MB Then
Str = FormatNumber(Obj/MB,2) & " MB"
Else
Str = FormatNumber(Obj/KB,2) & " KB"
End If
End Function
'-> Open The Text File Then Keep Or Delete
Ts.Close
Act.Run(Chr(34) & Txt & Chr(34)),1,True
Dim A1 : A1 = MsgBox("Did You Want To Keep This File?",4132,"Keep Or Delete")
If A1 = 7 Then Fso.DeleteFile(Txt),True

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...