quinta-feira, 28 de outubro de 2010

Script Session Part-4 Desfragmentando Discos

Olá pessoal, segue mais um scriptizinho fácil para agilizar uma tarefa adminsitrativa, hoje no caso é um script em VBS que irá fazer a desfragmentação de todos os discos da sua máquina, bem simples rápido e funcional, basta abrir o bloco de notas, copiar/colar e salvar com a extensão .vbs.
Só um conselho, para salvar em uma outra extensão, faça assim: Na hora que você salvar o arquivo, coloque aspas duplas ( " ), como exemplo "desfragmenta.vbs". Pois assim salvará como vbs e ao como .vbs.txt.

Segue abaixo o script

'====================================================
' NAME: Desfragmenta.vbs
'
' AUTHOR: RayzenX
'
'
' MODIFICATIONS:
' DATE MODIFIED MODIFIER MODIFICATION
'
'
'====================================================
' Set Variables
'===============

Dim Logfile, LogPath
'Sets the path and the file for the log file
LogPath = "C:\REPORTS\"
LogFile = "DefragRpt.txt"
'Combinds the File and the path.
Logfile = Logpath & LogFile

Set objShell = CreateObject("WScript.Shell")

'Makes directory for the Logfile
objShell.Run ("cmd /C CD C:\ & if not exist " & Logpath & " mkdir " & Logpath), 1, True

'Clears and creates the Logfile
objShell.Run ("cmd /C CD C:\ & Echo Server: %Computername% - %Date% %Time% > " & _
Logfile), 1, True

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colDiskDrives = objWMIService.ExecQuery("SELECT * FROM Win32_DiskDrive")

For Each objDrive In colDiskDrives
strDeviceID = Replace(objDrive.DeviceID, "\", "\\")
Set colPartitions = objWMIService.ExecQuery _
("ASSOCIATORS OF {Win32_DiskDrive.DeviceID=""" & _
strDeviceID & """} WHERE AssocClass = " & _
"Win32_DiskDriveToDiskPartition")

For Each objPartition In colPartitions
Set colLogicalDisks = objWMIService.ExecQuery _
("ASSOCIATORS OF {Win32_DiskPartition.DeviceID=""" & _
objPartition.DeviceID & """} WHERE AssocClass = " & _
"Win32_LogicalDiskToPartition")

For Each objLogicalDisk In colLogicalDisks
objShell.Run ("cmd /C CD C:\ & echo -------------------------------------- >> " & _
Logfile), 1, True
objShell.Run ("cmd /C CD C:\ & echo " & objLogicalDisk.DeviceID & " Drive >> " & _
Logfile), 1, True
objShell.Run ("cmd /C CD C:\ & defrag.exe " & objLogicalDisk.DeviceID & " -f -v >> " & _
Logfile), 1, True

Next
Next
Next


É isso ai pessoal espero que tenham gostado, até a próxima.

Nenhum comentário:

Postar um comentário