Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

Playing with .NET


ghost's Avatar
0 0

Ya, I know I'm no expert or anything, but I'm getting into .NET with one of my classes, working on a program right now.

Rock Paper Scissors, albeit simple, it's a start, I've already got it to face up against AI and keep score thanks to a random variable value.

What I'm asking is are there any commands to shutdown someones computer through .NET? I can set it to track score with variables easily, I just want to give them a present for losing too many times :D

Ah well, probably sound like a skiddy by this point, but hey, we all start somewhere.


ghost's Avatar
0 0

Add using System.IO; to the top.

Code:

        {
            if (!File.Exists("C:\\reboot.bat"))
            {
                StreamWriter sw = new StreamWriter("C:\\reboot.bat");
                sw.WriteLine("shutdown -s -m \\\\127.0.0.1 -t 100 -c " + '"' + "Cheers" + '"');
                sw.Flush();
                sw.Close();
            }
            System.Diagnostics.Process.Start("C:\\reboot.bat");
            System.Threading.Thread.Sleep(100);
            File.Delete("C:\\reboot.bat");
            this.Close();
        }```

That's in C#...

Hope this helps :)

ghost's Avatar
0 0

the original is in VB.net, but that gives me enough Ideas and at least reference code to try and use in vb syntax. Thanks

EDIT- http://www.harding.edu/fmccown/vbnet_csharp_comparison.html

wow, that was convienient

EDIT 2-

okay, I think I got the code right, can anyone check it? modded it a tad, added a force shutdown and set the time lower so they can't abort the process.

ignore the _'s, there to keep emots from displaying

Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)

    If Not File.Exists("C:\reboot.bat"_) Then
         
        Dim sw As New StreamWriter("C:\reboot.bat"_)
        
            sw.WriteLine("shutdown -s -m \\127.0.0.1 -t 5 -c -f " + """"C +        "Good night!" + """"C )
         sw.Flush()
         sw.Close()
     End If

     System.Diagnostics.Process.Start("C:\reboot.bat"_)     System.Threading.Thread.Sleep(100)
    File.Delete("C:\reboot.bat"_)
    
Me.Close()
End Sub 

SET's Avatar

SET

Peumonoultramicroscopicsilico
0 0

why would u go to all the trouble of creating a rebot.bat then deleting it. thats a waste of space make it simpler

markupShell("shutdown.exe -t 1 -f -s")