By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,270 Members | 1,582 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,270 IT Pros & Developers. It's quick & easy.

Shutdown a list of computers using VB.net

P: n/a
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

Feb 1 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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

Feb 1 '06 #2

P: n/a
ne***********@gmail.com wrote:
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.


Does psshutdown from www.sysinternals.com cope with that situation?

Andrew
Feb 1 '06 #3

P: n/a
Del
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
Feb 2 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.