What's new
  • Visit Rebornbuddy
  • Visit Panda Profiles
  • Visit LLamamMagic
  • Visit Resources
  • Visit Downloads
  • Visit Portal

Shutdown computer from a plug-in

zbit

New Member
Joined
Feb 16, 2010
Messages
20
Reaction score
0
Is it possible to make a plug-in shutdown your computer?
 
A plugin is just main C# language + a Honorbuddy DLL right?
Then it could be done like this:
using System.Management;

void Shutdown()
{
ManagementBaseObject mboShutdown = null;
ManagementClass mcWin32 = new ManagementClass("Win32_OperatingSystem");
mcWin32.Get();

// You can't shutdown without security privileges
mcWin32.Scope.Options.EnablePrivileges = true;
ManagementBaseObject mboShutdownParams =
mcWin32.GetMethodParameters("Win32Shutdown");

// Flag 1 means we want to shut down the system. Use "2" to reboot.
mboShutdownParams["Flags"] = "1";
mboShutdownParams["Reserved"] = "0";
foreach (ManagementObject manObj in mcWin32.GetInstances())
{
mboShutdown = manObj.InvokeMethod("Win32Shutdown",
mboShutdownParams, null);
}
}
Or Easier:
System.Diagnostics.Process.Start("Shutdown", "-s -t 10");
Source: http://stackoverflow.com/questions/102567/how-to-shutdown-the-computer-from-c
 
Well i am no programmer so i wouldn't know. I was just looking for a way to get a plug-in to shut down wow and the computer after some hours played so it doesn't run all night :)
 
Code:
namespace Styx.Bot.CustomClasses
{
/*
 * TimerLog v1.0
 *
 * Edit logout time: line 33 before you enable plugin
 *
 */

using Logic;
using System;
using Helpers;
using Logic.Pathing;
using System.Threading;
using System.Diagnostics;
using Logic.Common.Combat;
using Object_Dumping_Enumeration;
using CustomCombat.CombatInterface;
using Memory_Read_Write_Inject.Lua;
using Object_Dumping_Enumeration.WoWObjects;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using System.Xml.Linq;
using System.Linq;
using System.Net;
using System.Windows.Forms;
using System.Drawing;
using Styx.Plugins.PluginClass;

  
    public class AutoLog : HBPlugin
    {
        static int logOutAfterMinutes = 1;
        bool useHearth = true;


        int logOutAfterMS = logOutAfterMinutes * 60000;
        private static Stopwatch timer = new Stopwatch();
        
        public override void Pulse()
        {
            //Logging.Write("Pulse");
            if (!timer.IsRunning)
            {
                //Logging.Write("Timer Start");
                timer.Reset();
                timer.Start();
            }
            if (timer.ElapsedMilliseconds > logOutAfterMS && !ObjectManager.Me.Dead && !ObjectManager.Me.Combat)
            {
                //Logging.Write("Timer Elapsed");
                if (useHearth)
                {
                    Logging.Write("Using Hearthstone");
                    Lua.DoString("UseItemByName(\"Hearthstone\")");
                    Thread.Sleep(20000);
                }
                if (!ObjectManager.Me.Dead && !ObjectManager.Me.Combat)
                {
                    timer.Stop();
                    Logging.Write("Quitting WoW!");
                    Lua.DoString("ForceQuit()");
                    System.Diagnostics.Process.Start("Shutdown", "-s -t 10");
                }
            }
        }

        public override string Name { get { return "TimerLog"; } }

        public override string Author { get { return "ski"; } }

        public override Version Version { get { return new Version(1, 0); } }

        public override bool WantButton { get { return false; } }

        public override void OnButtonPress()
        {
            if (timer.IsRunning)
            {
                timer.Stop();
                timer.Reset();
            }
        }

    }
}

That should be almost working.
 
Thanks a lot Ski. Is it for HB1 orHB2 or will it work on both?

Guess i could just test it, but will have to wait till after dinner :)
 
Thanks a lot Ski. Is it for HB1 orHB2 or will it work on both?

Guess i could just test it, but will have to wait till after dinner :)

Its for HB1. I know all of it is functional except for the shutdown part, I just added that to my existing code.
 
Unfortunetly it didnt work :(

It closed wow and hb just fine, but not the computer.

I dont know if the log entries can tell you anything:

[7:51:47 PM:437] Quitting WoW!
[7:51:47 PM:515] Plugin TimerLog threw an exception in 'Pulse'! Exception:
[7:51:47 PM:515] The system cannot find the file specified - From: System at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start()
at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start(String fileName, String arguments)
at Styx.Bot.CustomClasses.AutoLog.Pulse() in c:\hb\Plugins\TimerLog.cs:line 64
at (Object )
at Styx.Plugins.PluginWrapper.Pulse()
 
Unfortunetly it didnt work :(

It closed wow and hb just fine, but not the computer.

I dont know if the log entries can tell you anything:

[7:51:47 PM:437] Quitting WoW!
[7:51:47 PM:515] Plugin TimerLog threw an exception in 'Pulse'! Exception:
[7:51:47 PM:515] The system cannot find the file specified - From: System at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start()
at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start(String fileName, String arguments)
at Styx.Bot.CustomClasses.AutoLog.Pulse() in c:\hb\Plugins\TimerLog.cs:line 64
at (Object )
at Styx.Plugins.PluginWrapper.Pulse()

Yep, its the shutdown line:
Code:
                    System.Diagnostics.Process.Start("Shutdown", "-s -t 10");

You can use my code as a shell and try to find a shutdown method that would work.
 
Yup, I figured that one out also :) Maybe there is a programmer hidden deep inside me anyway :)

I was looking into it a little, but the wife decides i have other plans.

I found this though http://www.pinvoke.net/default.aspx/user32.ExitWindowsEx maybe the answer could be found there. I may look at it tomorrow unless someone else decides to give it a try :)
 
Not a Plugin, but a tool i'm using for a few month now:
http://www.vistashutdowntimer.toflo.de/
Vista Shutdown Timer (not my program,....) You can enter a time when your computer should shutdown, or restart and so on.

I mainly use GatherBuddy and without plugins, i needed another solution. No Idea if it works with XP order SEVEN.
Gatherbuddy is set to logout after 4 hours, and 4hours + 5 Minutes later my computer will shutdown. Works fine for me.

Fry
 
Back
Top