--- VB.NET CODE ---
Dim strHost As String = "B001279AE624B"
Dim strPath As String = "C:\Tools\SysInternals\PS Service\"
Dim swPingSuccess As StreamWriter = My.Computer.FileSystem.OpenTextFileWriter(Ping_Success, False)
Dim swLogFile As StreamWriter = My.Computer.FileSystem.OpenTextFileWriter(logFile, False)
'Dim strSrvcStatus As String = "" & strPath & "psservice.exe" & " \\" & strHost & " -u " & "Username" & " -p " & "Password" & " query " & """Platform Validation Tool""" & " > " & logFile & "" OR THIS
Dim strSrvcStatus As String = """\\" & strHost & """" & " QUERY " & """Platform Validation Tool""" & " > " & logFile & ""
Dim strStop As String = """\\" & strHost & """" & " STOP " & """Platform Validation Tool"""
Dim strStart As String = """\\" & strHost & """" & " START " & """Platform Validation Tool"""
'Dim strStop As String = "" & strPath & "psservice.exe" & " \\" & strHost & " -u " & "Username" & " -p " & "Password" & " stop"
'Dim strStart As String = "" & strPath & "psservice.exe" & " \\" & strHost & " -u " & "Username" & " -p " & "Password" & " start"
'Dim psi As New ProcessStartInfo()
'psi.WorkingDirectory = "C:\Winnt\System32"
'psi.FileName = "C:\Winnt\System32\sc.exe "
'psi.UseShellExecute = True
'psi.Arguments = strSrvcStatus
'Err.Clear()
'Process.Start(psi)
Shell(strSrvcStatus, AppWinStyle.Hide, True)
swLogFile.Flush()
swLogFile.Close()
Dim srLog As StreamReader = New StreamReader(logFile)
If srLog.ReadToEnd.Contains("STOPPED") Then
Shell(strStart, AppWinStyle.Hide)
Shell(strSrvcStatus, AppWinStyle.Hide)
If srLog.ReadToEnd.Contains("RUNNING") Then
swPingSuccess.WriteLine("PVT Service Status: RUNNING")
ElseIf srLog.ReadToEnd.Contains("STOPPED") Then
swPingSuccess.WriteLine("SERVICE WON'T START")
'SET STATUS = SERVICE BROKE
End If
ElseIf srLog.ReadToEnd.Contains("RUNNING") Then
Shell(strStop, AppWinStyle.Hide)
Shell(strSrvcStatus, AppWinStyle.Hide)
If srLog.ReadToEnd.Contains("RUNNING") Then
swPingSuccess.WriteLine("PVT Service Status: RUNNING")
ElseIf srLog.ReadToEnd.Contains("STOPPED") Then
swPingSuccess.WriteLine("SERVICE WON'T START")
'SET STATUS = SERVICE BROKE
End If
ElseIf srLog.ReadToEnd.Contains("") Then
swPingSuccess.WriteLine("PVT Service Status: SERVICE NON-EXISTANT OR WON'T START")
End If
End Sub
--- VB.NET CODE USING WMI --- I'm close on this one but can't get the loop or the values from the Array extracted properly.
Imports System
Imports System.Management
Imports System.Windows.Forms
Namespace WMIState
Public Class MyWMIQuery
Public Overloads Shared Function Main() As Integer
Try
Dim host() as string = {"B001279AE624B", "B001E0BA97371"}
Dim searcher As New ManagementObjectSearcher( _
"\\" & host() & "\root\CIMV2", _
"SELECT State FROM Win32_Service Where Name = 'Platform Validation Tool'")
Dim i as Integer
For i = 0 To host.Length - 1
Console.WriteLine("Computer: {0}", i)
For Each queryObj As ManagementObject in searcher.Get()
Console.WriteLine("-----------------------------------")
Console.WriteLine("Win32_Service instance")
Console.WriteLine("-----------------------------------")
Console.WriteLine("State: {0}", queryObj("State"))
Next
Next
Catch err As ManagementException
MessageBox.Show("An error occurred while querying for WMI data: " & err.Message)
End Try
End Function
End Class
End Namespace
ASKER
Visual Basic .NET (VB.NET) is an object-oriented programming language implemented on the .NET framework, but also supported on other platforms such as Mono and Silverlight. Microsoft launched VB.NET as the successor to the Visual Basic language. Though it is similar in syntax to Visual Basic pre-2002, it is not the same technology,
TRUSTED BY
Open in new window