N
newsgroups.jd
Im sure there is a better way to do this - just posting what I did to
get it to work.
Please feel free to comment with suggestions - this was my first vb.net
program and I am not a programmer, so im sure it has room for
improvement
Assumptions:
list of computers in C:\shutdownvbs\computers.txt
log file at C:\shutdownvbs\logFile.txt
Aslo had to add reference to System.Management
Project > Add reference > System.Management
Imports System.IO
Imports System.Management
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Try
Dim computerList As StreamReader = New
StreamReader("C:\shutdownvbs\computers.txt")
Dim logFile As StreamWriter =
File.AppendText("C:\shutdownvbs\logFile.txt")
Dim computer As String, logMessage As String
Dim command As String
logMessage = " has been shutdown"
Do
computer = computerList.ReadLine()
Console.WriteLine(computer)
If My.Computer.Network.Ping(computer) Then
Dim theDate As String =
FormatDateTime(DateTime.Now, DateFormat.ShortDate)
Dim theTime As String =
FormatDateTime(DateTime.Now, DateFormat.ShortTime)
logMessage = (theDate + " " + theTime + " " +
computer + " has been shutdown")
command = "shutdown -f -s -t 0 -m \\" + computer
Shell(command)
logFile.WriteLine("{0}", logMessage)
Else
End If
Loop Until computerList.EndOfStream
computerList.Close()
logFile.Close()
Catch
Console.WriteLine("An error occurred.")
End Try
End Sub
End Class
get it to work.
Please feel free to comment with suggestions - this was my first vb.net
program and I am not a programmer, so im sure it has room for
improvement
Assumptions:
list of computers in C:\shutdownvbs\computers.txt
log file at C:\shutdownvbs\logFile.txt
Aslo had to add reference to System.Management
Project > Add reference > System.Management
Imports System.IO
Imports System.Management
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Try
Dim computerList As StreamReader = New
StreamReader("C:\shutdownvbs\computers.txt")
Dim logFile As StreamWriter =
File.AppendText("C:\shutdownvbs\logFile.txt")
Dim computer As String, logMessage As String
Dim command As String
logMessage = " has been shutdown"
Do
computer = computerList.ReadLine()
Console.WriteLine(computer)
If My.Computer.Network.Ping(computer) Then
Dim theDate As String =
FormatDateTime(DateTime.Now, DateFormat.ShortDate)
Dim theTime As String =
FormatDateTime(DateTime.Now, DateFormat.ShortTime)
logMessage = (theDate + " " + theTime + " " +
computer + " has been shutdown")
command = "shutdown -f -s -t 0 -m \\" + computer
Shell(command)
logFile.WriteLine("{0}", logMessage)
Else
End If
Loop Until computerList.EndOfStream
computerList.Close()
logFile.Close()
Catch
Console.WriteLine("An error occurred.")
End Try
End Sub
End Class