Reuslt of WMI script.

P

Pradeep Bisht

Hello,

I have a script with me, and I want the result of that script in a excel
file.So what is the command for that.
Thanks in advance.

Script -

strComputer = "."
Set objFso = CreateObject("Scripting.FileSystemObject")
strFile = "c:\Scripts\12.xls"
Set objSWbemServices = GetObject("winmgmts:\\" & strComputer)
Set colSWbemObjectSet = objSWbemServices.InstancesOf("Win32_Service")

For Each objSWbemObject In colSWbemObjectSet
Wscript.Echo "Display Name: " & objSWbemObject.DisplayName & vbCrLf & _
" State: " & objSWbemObject.State & vbCrLf & _
" Start Mode: " & objSWbemObject.StartMode
Next
 
M

Mark Dormer

Here you go

'-------------------------------------------------------------------------------------
Const ForWriting = 2
strComputer = "."
Set objFso = CreateObject("Scripting.FileSystemObject")
Set strFile = objFSO.OpenTextFile("c:\Scripts\12.csv", ForWriting, -2)
Set objSWbemServices = GetObject("winmgmts:\\" & strComputer)
Set colSWbemObjectSet = objSWbemServices.InstancesOf("Win32_Service")
strFile.writeline "Display Name" & "," & "State" & "," & "Start Mode"
For Each objSWbemObject In colSWbemObjectSet
strFile.writeline objSWbemObject.DisplayName & "," & objSWbemObject.State &
"," & objSWbemObject.StartMode
Next
strFile.Close
'---------------------------------------------------

Regards
Mark Dormer
 
A

Andres Olvera

You can also try this one out:

strComputer = "."

Set objSWbemServices = GetObject("winmgmts:\\" & strComputer)
Set colSWbemObjectSet = objSWbemServices.InstancesOf("Win32_Service")

Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.DisplayAlerts = False
Set objWorkbook = objExcel.Workbooks.Add()

objExcel.Cells(1,1) = "Display Name"
objExcel.Cells(1,2) = "State"
objExcel.Cells(1,3) = "Start Mode"
objExcel.Range("A1:C1").Font.Bold = True

intRow = 2
For Each objSWbemObject In colSWbemObjectSet
objExcel.Cells(intRow,1) = objSWbemObject.DisplayName
objExcel.Cells(intRow,2) = objSWbemObject.State
objExcel.Cells(intRow,3) = objSWbemObject.StartMode
intRow = intRow + 1
Next

objExcel.Columns("A:C").Autofit
objWorkbook.SaveAs "C:\Scripts\Services.xls"
objExcel.Quit
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top