Page 1 of 2 12 LastLast
Results 1 to 10 of 11
  1. #1
    Buddy
    Join Date
    16.02.2010
    Posts
    20

    Default Shutdown computer from a plug-in

    Is it possible to make a plug-in shutdown your computer?

  2. #2
    Lifetimer
    Join Date
    15.01.2010
    Location
    The Netherlands
    Age
    19
    Posts
    177

    Default

    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/1...omputer-from-c

  3. #3
    Buddy
    Join Date
    16.02.2010
    Posts
    20

    Default

    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

  4. #4
    ski
    ski is offline
    Community Developer
    Join Date
    12.02.2010
    Location
    Boston
    Posts
    3,564

    Default

    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.

  5. #5
    Buddy
    Join Date
    16.02.2010
    Posts
    20

    Default

    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

  6. #6
    ski
    ski is offline
    Community Developer
    Join Date
    12.02.2010
    Location
    Boston
    Posts
    3,564

    Default

    Quote Originally Posted by zbit View Post
    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.

  7. #7
    Buddy
    Join Date
    16.02.2010
    Posts
    20

    Default

    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()

  8. #8
    ski
    ski is offline
    Community Developer
    Join Date
    12.02.2010
    Location
    Boston
    Posts
    3,564

    Default

    Quote Originally Posted by zbit View Post
    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.

  9. #9
    Buddy
    Join Date
    16.02.2010
    Posts
    20

    Default

    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/....ExitWindowsEx maybe the answer could be found there. I may look at it tomorrow unless someone else decides to give it a try

  10. #10
    Lifetimer
    Join Date
    15.01.2010
    Posts
    36

    Default

    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

 

 
Page 1 of 2 12 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •