|
-
May 27th, 2008, 08:17 PM
#1
Thread Starter
Frenzied Member
[2005] Remote shutdown with vb.net
I was just wondering if there was a way to shutdown different computers that were on your network through writing a custom vb application.
If so, what do I need to look into, such as certain objects and such.
Thanks,
Justin Fox
-
May 27th, 2008, 08:25 PM
#2
Re: [2005] Remote shutdown with vb.net
Yes and no. You can execute any file from VB code by calling Process.Start, so if there was a program that would shut down a remote computer you could just run it like that. As it happens, Windows has shutdown.exe that will do just that. Open a command prompt and type "shutdown /?" to get help on it, then write VB code to call it with the appropriate commandline to shutdown the remote machine of your choice.
-
May 28th, 2008, 03:29 AM
#3
Re: [2005] Remote shutdown with vb.net
You probably will also need Domain Administrator permissions.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
May 28th, 2008, 06:45 AM
#4
Fanatic Member
Re: [2005] Remote shutdown with vb.net
Here's the code I use all the time. Works well enough. The account running it needs admin rights on the target machine.
Code:
Private Sub RebootMachine(comp)
If MessageBox.Show("Are you sure you wish to reboot " & comp & "?", "Confirm reboot", _
MessageBoxButtons.YesNo, MessageBoxIcon.Question) = System.Windows.Forms.DialogResult.Yes Then
Me.GenFunctions.WriteLog("Rebooting machine")
Using RebootProc As New Process
With RebootProc.StartInfo
.CreateNoWindow = True
.FileName = "shutdown.exe"
.Arguments = " -r -m \\" & comp & " -c " & _
ChrW(34) & "Windows is shutting down" & ChrW(34) & " -t 1"
.UseShellExecute = False
.WindowStyle = ProcessWindowStyle.Hidden
.RedirectStandardOutput = True
.RedirectStandardInput = True
End With
RebootProc.Start()
End Using
End If
End Sub
ManagePC - the all-in-one PC management and inventory tool
-
May 28th, 2008, 07:54 AM
#5
Re: [2005] Remote shutdown with vb.net
I'd suggest using String.Format rather than string concatentation for the Arguments. What's nicer? This:
vb.net Code:
.Arguments = " -r -m \\" & comp & " -c " & _ ChrW(34) & "Windows is shutting down" & ChrW(34) & " -t 1"
or this:
vb.net Code:
.Arguments = String.Format("-r -m \\{0} -c ""Windows is shutting down"" -t 1", comp)"
-
May 28th, 2008, 08:00 AM
#6
Fanatic Member
Re: [2005] Remote shutdown with vb.net
Thanks for the JMC. That does look better.
Of course, now I have to go through and change all the times I've used concatenation
ManagePC - the all-in-one PC management and inventory tool
-
May 28th, 2008, 08:52 AM
#7
Thread Starter
Frenzied Member
Re: [2005] Remote shutdown with vb.net
does a computer have to be in your "workgroup" for you to be able to shut it down?
because my laptop is in my network, I can go through it and everything, but when I try to execute the shutdown command to it, it says that the network path doesn't exist?
Is it because the laptop is on my wireless network? Or does that not matter?
Thanks,
Justin Fox
-
May 28th, 2008, 08:54 AM
#8
Thread Starter
Frenzied Member
Re: [2005] Remote shutdown with vb.net
Oh, and btw, how do you become recognized as a MVP? Do you just have to help a lot of people out in the msdn forums or what...
Thanks again,
Justin Fox
-
May 28th, 2008, 09:57 AM
#9
Re: [2005] Remote shutdown with vb.net
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
May 28th, 2008, 12:23 PM
#10
Re: [2005] Remote shutdown with vb.net
 Originally Posted by MonkOFox
does a computer have to be in your "workgroup" for you to be able to shut it down?
because my laptop is in my network, I can go through it and everything, but when I try to execute the shutdown command to it, it says that the network path doesn't exist?
Is it because the laptop is on my wireless network? Or does that not matter?
Thanks,
Justin Fox
It shouldnt matter that its on a wireless network, as long as you are running your app as a user account that has admin permissions on the remote machine.
In a domain environment this kind of thing would usually be run as the domain admin account but as you are in a workgroup then permissions can be a bit more of a pain (assuming you are running windows xp home edition).
Its also possible that your remote PC has a firewall on it that is stopping your connections getting through.
What exactly do you mean when you say you can "go through it and everything"?
-
May 28th, 2008, 12:25 PM
#11
Re: [2005] Remote shutdown with vb.net
If you can get in then that doesnt mean you have admin permissions, only that the drive/system is having "File and Print Sharing" turned on. You need to be a local administrator of the system you wish to shut down.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
May 28th, 2008, 06:45 PM
#12
Re: [2005] Remote shutdown with vb.net
Last edited by minitech; May 29th, 2008 at 05:47 PM.
-
May 28th, 2008, 07:56 PM
#13
Re: [2005] Remote shutdown with vb.net
 Originally Posted by minitech
Run %windir%\system32\shutdown.exe -s -t 00 to shut down a computer. Of course, this only works with Windows XP with the system32 directory. (-t 00 is a time delay, and -s is shut down. Use -l to log off and -r to restart.)
1. We already established that you need to call shutdown.exe 24 hours ago.
2. There's no point to specifying a path because the PATH environment variable will take care of that, so it will work with any OS that supports shutdown.exe by omitting the path.
3. That command line doesn't address the need to shutdown a remote computer.
Strike three!
-
May 28th, 2008, 08:43 PM
#14
Re: [2005] Remote shutdown with vb.net
John, you forgot to mention - need to have local admin perms.
Strike four on you
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
May 29th, 2008, 04:15 AM
#15
Re: [2005] Remote shutdown with vb.net
Random shutdown.exe fact of the day: Run Shutdown.exe -i to make a GUI for the shutdown commands appear, where you can add a list of remote PCs to be shutdown, specify a message and time delay etc etc
What? You already knew that?
-
May 29th, 2008, 04:31 AM
#16
Addicted Member
Re: [2005] Remote shutdown with vb.net
Come on guy, we can do better than that, calling an .exe? 
Here's a vbs version, I'm sure we can all convert that to vb.net right?
Code:
'check flag
' if equal 1 (TRUE) then perform Win32Shutdown action on remote PC
' and display a confirmation message
' if not equal 1 (FALSE) then skip the action and script ends
if flag then
Set OpSysSet=GetObject("winmgmts:{(Debug,RemoteShutdown)}//" _
& ComputerName & "/root/cimv2").ExecQuery( _
"Select * from Win32_OperatingSystem where Primary=true")
for each OpSys in OpSysSet
OpSys.Win32Shutdown(x)
y = msgbox(strAction,vbOKOnly + vbInformation,"Mission Accomplished")
next
end If
-
May 29th, 2008, 05:16 AM
#17
Re: [2005] Remote shutdown with vb.net
Well thats just using WMI so yeah that can be done in VB.NET but I dunno I have had mixed success rates with WMI scripts... personally I would rather use the shutdown.exe but as you say, its not good really having to rely on an external exe ... I suppose just use which ever solution seems to work best in your environment
-
May 29th, 2008, 07:06 AM
#18
Fanatic Member
Re: [2005] Remote shutdown with vb.net
There was a specific reason I didn't use WMI for shutdowns in my application. I can't, for the life of me, remember what is was now though.
ManagePC - the all-in-one PC management and inventory tool
-
May 29th, 2008, 08:10 AM
#19
Thread Starter
Frenzied Member
Re: [2005] Remote shutdown with vb.net
umm, my desktop is xp and my laptop is vista, so could that be the reason why when I try to shutdown my laptop, it gives me a 'network path not found' error?
Thanks,
Justin
-
May 29th, 2008, 08:32 AM
#20
Re: [2005] Remote shutdown with vb.net
I wouldnt imagine so but I guess it is possible. As long as you are running the shutdown command as a user account that is an administrator on the laptop then it shouldnt matter.
Can you post the code that you are using to try execute the shutdown command? Or are you just using shutdown.exe through command prompt?
-
May 29th, 2008, 05:18 PM
#21
Re: [2005] Remote shutdown with vb.net
Its not always good to rely upon WMI because it may not be enabled as some network admins disable it.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jun 2nd, 2008, 09:08 PM
#22
Member
Re: [2005] Remote shutdown with vb.net
You could also enable Remote Desktop on the PC you wish to shut down. Remote into it from another PC and just do a shutdown. No code to write, or software to buy.
-
Jun 2nd, 2008, 10:22 PM
#23
Re: [2005] Remote shutdown with vb.net
Unless a more automated / programmed solution is desired.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jun 3rd, 2008, 02:06 AM
#24
Re: [2005] Remote shutdown with vb.net
 Originally Posted by LloydAZ
You could also enable Remote Desktop on the PC you wish to shut down. Remote into it from another PC and just do a shutdown. No code to write, or software to buy.
Well Remote Desktop is not enabled by default on XP, although you can edit some registry keys remotely to enable it but sometimes this requires a reboot so it wouldnt be a very reliable solution really and like Robdogg said, an automated solution might be required. Perhaps to save the user the time it would take to log on to 10 PCs with Remote Desktop and manually shut them down.
-
Jul 26th, 2010, 05:11 AM
#25
Hyperactive Member
Re: [2005] Remote shutdown with vb.net
hi all
i have a small network with 8 computers on it.
i wrote to programs 1 to do the shutting down and the other to send the command and both programs monitored a folder for commands.
i used a ini file to send information to each of the programs.
i used vb6 to write the programs. i lost all my project when my computer died..
remember to set a permissions to the folder so read write is ok
i wish i still had the project i would post it
programming pc: laptop. running xp pro and vb.net..
media centre xp pc: dual core 6000,4gb memory, 1tb harddrive
mainserver: server 2008, 8gb memory, amd e-350 dual core, 6tb harddrive and local web host
atomvault 1: server 2008, atom 330 with 4 gb memory, 35TB hardrive space for videos and music..
backup pc : xp, 4gb, atom 330, 10tb harddrive(web, pictures, music, databases)
2 x video backup: atom 330, 2gb, 18tb harddrive
everything on remote login..
check out my builds http://AtomVaults.yolasite.com
learning vb.net and php + mysql   - got most of the basics now.
I WISH THERE WAS MORE TIME IN THE DAY  
-
Jul 26th, 2010, 05:30 AM
#26
Re: [2005] Remote shutdown with vb.net
Why have you posted in a 2 year old thread? You dont even appear to be asking a question or posting an answer to the thread...
-
Jul 26th, 2010, 06:21 AM
#27
Hyperactive Member
Re: [2005] Remote shutdown with vb.net
hi
i never looked at the post date..
never mind
programming pc: laptop. running xp pro and vb.net..
media centre xp pc: dual core 6000,4gb memory, 1tb harddrive
mainserver: server 2008, 8gb memory, amd e-350 dual core, 6tb harddrive and local web host
atomvault 1: server 2008, atom 330 with 4 gb memory, 35TB hardrive space for videos and music..
backup pc : xp, 4gb, atom 330, 10tb harddrive(web, pictures, music, databases)
2 x video backup: atom 330, 2gb, 18tb harddrive
everything on remote login..
check out my builds http://AtomVaults.yolasite.com
learning vb.net and php + mysql   - got most of the basics now.
I WISH THERE WAS MORE TIME IN THE DAY  
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|