G
Guest
Hello All,
I am migrating some scripts to .NET. This has been a learning experience to
say the least.
The whole script pull a list of computers through an LDAP call to AD. It
then writes the computer names to a file. The file is then read, pings the
computer and then if it is alive, checks the OS.
Private Sub ParseComputerList()
'Dim ComputerResultsFile As IO.StreamWriter = New
IO.StreamWriter("C:\ComputerResults.txt")
'Dim ComputerListfile As System.IO.File
Dim ComputerListreader As System.IO.StreamReader
Dim PingStatus As Boolean
ComputerListreader = IO.File.OpenText("C:\DomainList.txt")
While ComputerListreader.Peek <> -1
Computer = ComputerListreader.ReadLine()
If SystemAlive(Computer, PingStatus) Then
CheckOS()
ResultOutput()
ProgressBar1.PerformStep()
Else
'MessageBox.Show("Machine is Offline")
End If
End While
ComputerListreader.Close()
End Sub
Private Sub CheckOS()
'Dim RegSubKey As Microsoft.Win32.RegistryHive
Dim RegKey As RegistryKey
' Dim RegSubKey As RegistryKey
Dim strOS As String
Try
RegKey =
RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine,
Computer).OpenSubKey("SOFTWARE\Microsoft\Windows NT\CurrentVersion", True)
If RegKey.GetValue("CurrentVersion") = "5.1" Then
strOS = "Windows XP Pro"
strResult = Computer & " " & strOS
'MessageBox.Show(Computer & " Is A Windows XP System")
Else
End If
Catch ex As Exception
strOS = "Error"
'MessageBox.Show(ex.InnerException.ToString)
End Try
' System.Threading.Thread.Sleep(5000)
End Sub
Private Sub ResultOutput()
ComputerResultsFile.WriteLine(UCase(strResult))
'ComputerResultsFile.Close()
End Sub
Private Function SystemAlive(ByVal Name As String, ByRef PingResult As
Boolean) As Boolean
Dim pingClient As New Ping
Dim status As IPStatus
'Dim PingResult As Boolean
PingResult = False
Try
status = pingClient.Send(Name, 1000).Status
If status = IPStatus.Success Then
PingResult = True
'StatusBar1.Text = Name & " Ping Successful"
'MessageBox.Show("Machine is on we can now do whatever")
Else
StatusBar1.Text = Name & " Ping TimedOut"
PingResult = False
'MessageBox.Show("Can't contact machine : " & status.ToString)
End If
Catch ex As Exception
PingResult = False
'MessageBox.Show(ex.InnerException.ToString)
StatusBar1.Text = Name & " Error"
End Try
SystemAlive = PingResult
End Function
The script writes the list of computer without issue. However something
breaks after that and I get the following error.
The CLR has been unable to transition from COM context 0x1a0120 to COM
context 0x1a0290 for 60 seconds.
Thanks for any help
I am migrating some scripts to .NET. This has been a learning experience to
say the least.
The whole script pull a list of computers through an LDAP call to AD. It
then writes the computer names to a file. The file is then read, pings the
computer and then if it is alive, checks the OS.
Private Sub ParseComputerList()
'Dim ComputerResultsFile As IO.StreamWriter = New
IO.StreamWriter("C:\ComputerResults.txt")
'Dim ComputerListfile As System.IO.File
Dim ComputerListreader As System.IO.StreamReader
Dim PingStatus As Boolean
ComputerListreader = IO.File.OpenText("C:\DomainList.txt")
While ComputerListreader.Peek <> -1
Computer = ComputerListreader.ReadLine()
If SystemAlive(Computer, PingStatus) Then
CheckOS()
ResultOutput()
ProgressBar1.PerformStep()
Else
'MessageBox.Show("Machine is Offline")
End If
End While
ComputerListreader.Close()
End Sub
Private Sub CheckOS()
'Dim RegSubKey As Microsoft.Win32.RegistryHive
Dim RegKey As RegistryKey
' Dim RegSubKey As RegistryKey
Dim strOS As String
Try
RegKey =
RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine,
Computer).OpenSubKey("SOFTWARE\Microsoft\Windows NT\CurrentVersion", True)
If RegKey.GetValue("CurrentVersion") = "5.1" Then
strOS = "Windows XP Pro"
strResult = Computer & " " & strOS
'MessageBox.Show(Computer & " Is A Windows XP System")
Else
End If
Catch ex As Exception
strOS = "Error"
'MessageBox.Show(ex.InnerException.ToString)
End Try
' System.Threading.Thread.Sleep(5000)
End Sub
Private Sub ResultOutput()
ComputerResultsFile.WriteLine(UCase(strResult))
'ComputerResultsFile.Close()
End Sub
Private Function SystemAlive(ByVal Name As String, ByRef PingResult As
Boolean) As Boolean
Dim pingClient As New Ping
Dim status As IPStatus
'Dim PingResult As Boolean
PingResult = False
Try
status = pingClient.Send(Name, 1000).Status
If status = IPStatus.Success Then
PingResult = True
'StatusBar1.Text = Name & " Ping Successful"
'MessageBox.Show("Machine is on we can now do whatever")
Else
StatusBar1.Text = Name & " Ping TimedOut"
PingResult = False
'MessageBox.Show("Can't contact machine : " & status.ToString)
End If
Catch ex As Exception
PingResult = False
'MessageBox.Show(ex.InnerException.ToString)
StatusBar1.Text = Name & " Error"
End Try
SystemAlive = PingResult
End Function
The script writes the list of computer without issue. However something
breaks after that and I get the following error.
The CLR has been unable to transition from COM context 0x1a0120 to COM
context 0x1a0290 for 60 seconds.
Thanks for any help