473,395 Members | 1,975 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Shutdown a list of computers using VB.net

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
3 10448
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Hannes Grund | last post by:
Dear all, probably offtopic for the general python list, but I don't know were to go else. I'm currently developing somekind of middleware wich makes heavy use of pythonwin/com extensions....
4
by: Bill Sonia | last post by:
I'm written a Windows Service to send e-mails on events like OnStart, OnStop, OnShutDown using System.Web.Mail. It works for everything but OnShutdown. My guess is that once my send mail code is...
0
by: Hansi | last post by:
How can i start a winforms application on remote workstation, no matter who or if there is somebody logged in? My problems: 1) I need to shutdown computers in the evening that have not been...
3
by: newsgroups.jd | last post by:
Let me start by saying I am a noob to VB.net and am not a programmer anyways I am trying to learn and would like to get this to work... so please be gentle, If Im doing it wrong please tell me......
0
by: Christian Jacob | last post by:
Hi there, I've got a serious problem with getting a remote shutdown functionality working with VB.NET. I am using WMI to query the target PC and invoke the Win32Shutdown method like this: Dim...
6
by: diffuser78 | last post by:
I am using 8 computers on a small network. I have one Main computer which should be able to remotely start other computers. I used Wake on LAN to start them all. My Main computer is Linux. ...
5
by: Phil Tusa | last post by:
Greetings to all .... I have a need to issue a shutdown and/or Restart Windows XP inside my application. Any help or example code would be appreciated! -- Phil
3
by: joja15 | last post by:
I am working on a Python script to perform as a remote computer manager. So far I have a WOL function working and I would like to add the ability to show if a machine is on or off (I figured I...
4
by: JB | last post by:
I am trying to get a list of all the active computers running on my domain. I'm writing some remote management style software with WMI, which works fine when i know the computer name, but i just...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.