473,662 Members | 2,588 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Manageme nt
Project > Add reference > System.Manageme nt
Imports System.IO
Imports System.Manageme nt

Public Class Form1

Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Try
Dim computerList As StreamReader = New
StreamReader("C :\shutdownvbs\c omputers.txt")
Dim logFile As StreamWriter =
File.AppendText ("C:\shutdownvb s\logFile.txt")
Dim computer As String, logMessage As String
Dim command As String
logMessage = " has been shutdown"
Do
computer = computerList.Re adLine()
Console.WriteLi ne(computer)
If My.Computer.Net work.Ping(compu ter) Then
Dim theDate As String =
FormatDateTime( DateTime.Now, DateFormat.Shor tDate)
Dim theTime As String =
FormatDateTime( DateTime.Now, DateFormat.Shor tTime)
logMessage = (theDate + " " + theTime + " " +
computer + " has been shutdown")
command = "shutdown -f -s -t 0 -m \\" + computer
Shell(command)
logFile.WriteLi ne("{0}", logMessage)
Else
End If
Loop Until computerList.En dOfStream
computerList.Cl ose()
logFile.Close()
Catch
Console.WriteLi ne("An error occurred.")
End Try
End Sub
End Class

Feb 1 '06 #1
3 10486
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***********@g mail.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; InitializeSyste mShutdown (API), but the
machines need the remote shutdown privilige set. In XP, you can use
shutdown.exe using the switches. InitializeSyste mShutdown works across
platforms, shutdown.exe doesn't

Example:

Dim pi As New ProcessInfo

With pi
.Filename = "shutdown.e xe"
.Arguments = "-s -m \\" & YourComputerNam eHere & " -c " & chr(34) &
"Windows is shutting down" & chrs(34) & " -t 120"
End With

System.Diagnost ics.Process.Sta rt(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
2072
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. (The complete setup is: win2000/winXP, python2.2, win32all-152, wxPython resp. wxWindows). The software is aimed to manage data held by a software
4
7122
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 executed, other necessary Windows Services have been terminated before it can actually send the mail. I've updated my HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services registry DependOnService value including SMPTSVC and others. My hope is...
0
1798
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 shutdown by the (roaming) users, no matter if there is somebody logged in or not. If there is somebody logged in and sitting in front of the PC, he should get a dialogue and be able to refuse the
3
2272
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... I have users that leave their computers on all night and I want them to shut them off. Local admin is removed from the computers, so I had difficulties just kix scripting a task on the local PC to shutdown at a given time... Plan 2 - Run a...
0
1708
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 aoInParams() As Object = {8} For Each mngObj As ManagementObject In mngColl mngObj.Scope.Options.EnablePrivileges = True
6
6825
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. Other 4 are Windows and 3 are Linux. How can I shutdown Windows box from my Main (Linux) ?
5
17405
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
27032
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 would do so by pinging the machine and seeing if I get a response). I would also like to add the ability to remotely shutdown a computer from the python script. Does anyone have a code snippet for pinging an IP, a code snippet for shutting down a...
4
7683
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 want to be able to produce a list and work it from there. I found the following method: String path = "WinNT://MY.DOMAIN.COM"; String username = "administrator";
0
8344
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8857
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8764
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8633
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5654
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4180
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4347
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1993
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1752
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.