[CODIGO FONTE] Visualizar o uso da CPU

08-02-2012 09:43

@echo off
REM Autor: Evandro Wirlynthon.
REM Empresa: Hacker Project
REM Site: Www.HackerProject.webnode.com.br
REM Email: wirlynthon@hotmail.com
REM Obs: Esse programa tem interação com VB Script
title Monitor de CPU.
mode con cols=45 lines=9 &color f8
:inicio
cls
Call :Monitora
for /f "tokens=1 delims=#" %%a in (Monitor_PC.txt) do (
set "Data=%%a"
)
for /f "tokens=2 delims=#" %%a in (Monitor_PC.txt) do (
set "Hora=%%a"
)
for /f "tokens=3 delims=#" %%a in (Monitor_PC.txt) do (
set "PC=%%a"
)
for /f "tokens=4 delims=#" %%a in (Monitor_PC.txt) do (
set "Uso_CPU=%%a"
)
for /f "tokens=5 delims=#" %%a in (Monitor_PC.txt) do (
set "Uso_MEM=%%a"
)
for /f "tokens=6 delims=#" %%a in (Monitor_PC.txt) do (
set "Uso_HDS=%%a"
)
for /f "tokens=7 delims=#" %%a in (Monitor_PC.txt) do (
set "Uso_HDS2=%%a"
)
for %%f in (Monitor_PC.txt) do del %%f
ECHO.
Echo Data %Data%
Echo Hora %Hora%
Echo PC %PC%
Echo Uso do CPU %Uso_CPU%
Echo Uso da memoria %Uso_MEM%
Echo Uso do HD %Uso_HDS%
Echo Uso do HD %Uso_HDS2%
ping -n 2 localhost >nul

goto:inicio

:Monitora
(
Echo. Option Explicit
Echo. Dim oWsh, oWshSysEnv, objFSO, objWMIService
Echo. Dim oDrives, oDrive, objOutFile, colItems, objItem
Echo. Dim strLineDate, strLineTime, strLineProcessorTime, strLineDriveSpace, strLinePercentCommittedBytesInUse
Echo.
Echo. Set oWsh = WScript.CreateObject("WScript.Shell"^)
Echo. Set oWshSysEnv = oWsh.Environment("PROCESS"^)
Echo. Set objFSO = CreateObject("Scripting.FileSystemObject"^)
Echo. Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2"^)
Echo.
Echo. strLineDate = Date(^)
Echo. strLineTime = Time(^)
Echo.
Echo. 'uso do processador
Echo. Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_PerfFormattedData_PerfOS_Processor WHERE Name = '_Total'"^)
Echo. For Each objItem In colItems
Echo. strLineProcessorTime = strLineProcessorTime ^& " " ^& objItem.PercentProcessorTime
Echo. Next
Echo.
Echo. 'uso da memória
Echo. Set colItems = GetObject("WinMgmts:root/cimv2"^).ExecQuery("Select * FROM Win32_PerfFormattedData_PerfOS_Memory "^)
Echo. For Each objItem In colItems
Echo. strLinePercentCommittedBytesInUse = strLinePercentCommittedBytesInUse ^& " " ^& objItem.PercentCommittedBytesInUse
Echo. Next
Echo.
Echo. 'espaço em disco
Echo. Set oDrives = objFSO.Drives
Echo. For Each oDrive In oDrives
Echo. Select Case oDrive.DriveType
Echo. Case 2 'Fixed Drives
Echo. strLineDriveSpace = strLineDriveSpace ^& " " ^& oDrive.DriveLetter ^& "\: " ^& Round(oDrive.FreeSpace / (1024 * 1024^) / 1024,2^) ^& " Gb Livres " ^& Round(100 * (oDrive.FreeSpace / oDrive.TotalSize^), 1^) ^& "%%% #"
Echo. End Select
Echo. Next
Echo.
Echo. 'grava
Echo. Set objOutFile = objFSO.OpenTextFile("Monitor_PC.txt", 8 , True^)
Echo. 'objOutFile.WriteLine "Date,hora,nome do computador,uso do processador (%%^),uso da memória (%%^),espaço em disco"'
Echo. objOutFile.WriteLine strLineDate ^& "#" ^& strLineTime ^& "#" ^& oWshSysEnv("COMPUTERNAME"^) ^& "#" ^& strLineProcessorTime ^& "%% #" ^& strLinePercentCommittedBytesInUse ^& "%% #" ^& strLineDriveSpace
Echo. 'WScript.Echo "Pronto"
Echo. WScript.Quit
)>monitor.vbs
CSCRIPT //NOLOGO monitor.vbs
goto:eof

Voltar

Procurar no site

© 2010 - 2013 Todos os direitos reservados. Designed by: Evandro Wirlynthon