Results 1 to 27 of 27

Thread: [2005] Remote shutdown with vb.net

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2008
    Location
    Texas
    Posts
    1,288

    [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
    You down with OOP? Yeah you know me!
    MCAD and MCMICKEYMOUSE (vb.net)

    ----

    If it even kinda helps... rate it : )

    Edit a Multi-page .tif file and save.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  4. #4
    Fanatic Member
    Join Date
    Apr 2006
    Posts
    746

    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

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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:
    1. .Arguments = " -r -m \\" & comp & " -c " & _
    2.                 ChrW(34) & "Windows is shutting down" & ChrW(34) & " -t 1"
    or this:
    vb.net Code:
    1. .Arguments = String.Format("-r -m \\{0} -c ""Windows is shutting down"" -t 1", comp)"
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6
    Fanatic Member
    Join Date
    Apr 2006
    Posts
    746

    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

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2008
    Location
    Texas
    Posts
    1,288

    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
    You down with OOP? Yeah you know me!
    MCAD and MCMICKEYMOUSE (vb.net)

    ----

    If it even kinda helps... rate it : )

    Edit a Multi-page .tif file and save.

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2008
    Location
    Texas
    Posts
    1,288

    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
    You down with OOP? Yeah you know me!
    MCAD and MCMICKEYMOUSE (vb.net)

    ----

    If it even kinda helps... rate it : )

    Edit a Multi-page .tif file and save.

  9. #9
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  10. #10
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: [2005] Remote shutdown with vb.net

    Quote 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"?
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  11. #11
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  12. #12
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Lightbulb Re: [2005] Remote shutdown with vb.net

    Last edited by minitech; May 29th, 2008 at 05:47 PM.

  13. #13
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Remote shutdown with vb.net

    Quote 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!
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  14. #14
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  15. #15
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    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?
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  16. #16
    Addicted Member Lectere's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    222

    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

  17. #17
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    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
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  18. #18
    Fanatic Member
    Join Date
    Apr 2006
    Posts
    746

    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

  19. #19

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2008
    Location
    Texas
    Posts
    1,288

    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
    You down with OOP? Yeah you know me!
    MCAD and MCMICKEYMOUSE (vb.net)

    ----

    If it even kinda helps... rate it : )

    Edit a Multi-page .tif file and save.

  20. #20
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    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?
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  21. #21
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  22. #22
    Member
    Join Date
    Mar 2008
    Posts
    33

    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.

  23. #23
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  24. #24
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: [2005] Remote shutdown with vb.net

    Quote 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.
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  25. #25
    Hyperactive Member
    Join Date
    Jun 2007
    Posts
    261

    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

  26. #26
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    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...
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  27. #27
    Hyperactive Member
    Join Date
    Jun 2007
    Posts
    261

    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
  •  



Click Here to Expand Forum to Full Width