' ------ KONFIGURACJA SKRYPTU ------
strComputer = "."
strExcelPath = "d:\procs.xls"
' ------ KONIEC KONFIGURACJI ---------
On Error Resume Next
set objExcel = CreateObject("Excel.Application")
if Err.Number <> 0 then
    Wscript.Echo "Excel nie jest zainstalowany."
    Wscript.Quit
end if
On Error GoTo 0

' Utworzenie nowego skoroszytu.
objExcel.Workbooks.Add

' Powizanie z arkuszem.
Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)
objSheet.Name = "Procesy"

' Wypenienie komrek arkusza atrybutami uytkownika.
objSheet.Cells(1, 1).Value = "Nazwa procesu"
objSheet.Cells(1, 2).Value = "Wiersz polece"
objSheet.Cells(1, 3).Value = "Identyfikator procesu"
objSheet.Cells(1, 4).Value = "Waciciel"
objSheet.Range("A1:D1").Font.Bold = True

' Uzyskanie informacji dotyczcych procesu.
set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
intProcessCount = 1
for each objProcess in objWMI.InstancesOf("Win32_Process")
    ' Zapisanie w arkuszu dla kadego procesu jego nazwy, 
    ' parametrw wiersza polece i identyfikatora
    intProcessCount = intProcessCount + 1
    objSheet.Cells(intProcessCount,1).Value = objProcess.Name
    objSheet.Cells(intProcessCount,2).Value = ObjProcess.CommandLine
    objSheet.Cells(intProcessCount,3).Value = ObjProcess.ProcessID
    objProcess.GetOwner strUser,strDomain
    objSheet.Cells(intProcessCount,4).Value = strDomain & "\" & strUser
next

' Formatowanie kolumn
objExcel.Columns(1).ColumnWidth = 20
objExcel.Columns(2).ColumnWidth = 50
objExcel.Columns(3).ColumnWidth = 5
objExcel.Columns(4).ColumnWidth = 30

' Zapisanie arkusza, zamknicie skoroszytu i programu.
objExcel.ActiveWorkbook.SaveAs strExcelPath
objExcel.ActiveWorkbook.Close
objExcel.Application.Quit

WScript.Echo "Gotowe"
