mutley1
MIS
- Jul 24, 2003
- 909
Hi Experts,
Sorry this is a cross post, but I put it in the wrong VB forum previously.
Some kind soul helped me once before to write an Active X VB script (for part of a SQL2000 DTS package) to use WMI / WIN32_Services to retrieve the status of services on servers (please see below). I understand there is another WMI that can pull back disk size and free space and was wondering if anyone could help me adapt the below to do this. I have a text file with a list of servers to query and would like to use WIN32_LogicalDisk to run through the same list and bring back the computer name, disk letter, size and free space. Is this possible?
I'm guessing it is the section in red that needs amending - I've been trying but with no success as I have never really touched VB.
Thanks in advance,
M
Sorry this is a cross post, but I put it in the wrong VB forum previously.
Some kind soul helped me once before to write an Active X VB script (for part of a SQL2000 DTS package) to use WMI / WIN32_Services to retrieve the status of services on servers (please see below). I understand there is another WMI that can pull back disk size and free space and was wondering if anyone could help me adapt the below to do this. I have a text file with a list of servers to query and would like to use WIN32_LogicalDisk to run through the same list and bring back the computer name, disk letter, size and free space. Is this possible?
I'm guessing it is the section in red that needs amending - I've been trying but with no success as I have never really touched VB.
Thanks in advance,
M
Code:
'**********************************************************************
' Visual Basic ActiveX Script
'************************************************************************
Function Main()
On Error Resume Next
'Set the report output directory (end with a backslash)
dir = "D:\ServicesAnalysis\"
'Set the text report file name
filename = "ServiceStatus.txt"
'open the file system object
Set oFSO = CreateObject("Scripting.FileSystemObject")
set WSHShell = wscript.createObject("wscript.shell")
'open the data file
Set oTextStream = oFSO.OpenTextFile("D:\ServicesAnalysis\LISTWorkgroup.txt")
'make an array from the data file
RemotePC = Split(oTextStream.ReadAll, vbNewLine)
'close the data file
oTextStream.Close
For Each strComputer In RemotePC
[COLOR=red]Set objWMIService = GetObject _
("winmgmts:\\" & strComputer & "\root\cimv2")
Set colRunningServices = objWMIService.ExecQuery _
("Select * from Win32_Service")
For Each objService in colRunningServices
If ucase (objService.DisplayName) = "WORKGROUP SERVER" Then
Report = Report & vbCrLf & "Computer ," & strComputer & ", reports service ," & objService.DisplayName & ", is ," & objService.State
End If
Next
Next
[/color red]
If Not oFSO.FolderExists(dir) Then
oFSO.CreateFolder(dir)
End If
Set ts = oFSO.CreateTextFile (dir & filename, True)
ts.write report
Main = DTSTaskExecResult_Success
End Function