|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Shutdown a list of computers using VB.netget 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 One thing I have not figured out yet is that if there is a computer in
the list that does not resolve it breaks the task and does not continue. JD newsgroups***@gmail.com wrote:
> One thing I have not figured out yet is that if there is a computer in Does psshutdown from www.sysinternals.com cope with that situation?> the list that does not resolve it breaks the task and does not > continue. Andrew I wrote a program in VB.NET that shuts down all computer on the domain using
wired or wireless There are two ways to do it; InitializeSystemShutdown (API), but the machines need the remote shutdown privilige set. In XP, you can use shutdown.exe using the switches. InitializeSystemShutdown works across platforms, shutdown.exe doesn't Example: Dim pi As New ProcessInfo With pi .Filename = "shutdown.exe" .Arguments = "-s -m \\" & YourComputerNameHere & " -c " & chr(34) & "Windows is shutting down" & chrs(34) & " -t 120" End With System.Diagnostics.Process.Start(pi) Just typed the above in here. You will have to double-check the above to get the code 100% perfect... You have the main idea though Crouchie1998 BA (HONS) MCP MCSE I don't recomment the SysemInternals tool
Coding Standards - We need a hero
TextBox MAPI Q: DataGrid Select Need equivalant code in VB.Net 2005 ? "friend" accessor and inherited forms Waht is the fastest/bets? Outlook Object/CDO/Redemption/...? TCPListener / GUI Responsivness Calling all (any?) NDoc'ers Register insertion of USB drives in .NET 1.1 |
|||||||||||||||||||||||