• Visit Honorbuddy
  • Visit Rebornbuddy
  • Visit Demonbuddy
  • Visit Exilebuddy
  • Visit Hearthbuddy
  • Visit Pokefarmer
  • Visit Buddystore

Shutdown computer from a plug-in

Discussion in 'Archives' started by zbit, Apr 21, 2010.

  1. zbit

    zbit New Member

    Joined:
    Feb 16, 2010
    Messages:
    20
    Likes Received:
    0
    Trophy Points:
    0
    Is it possible to make a plug-in shutdown your computer?
     
  2. Thunderofnl

    Thunderofnl New Member

    Joined:
    Jan 15, 2010
    Messages:
    177
    Likes Received:
    0
    Trophy Points:
    0
    A plugin is just main C# language + a Honorbuddy DLL right?
    Then it could be done like this:
    Or Easier:
    Source: http://stackoverflow.com/questions/102567/how-to-shutdown-the-computer-from-c
     
  3. zbit

    zbit New Member

    Joined:
    Feb 16, 2010
    Messages:
    20
    Likes Received:
    0
    Trophy Points:
    0
    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. ski

    ski Well-Known Member

    Joined:
    Feb 12, 2010
    Messages:
    3,720
    Likes Received:
    48
    Trophy Points:
    48
    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. zbit

    zbit New Member

    Joined:
    Feb 16, 2010
    Messages:
    20
    Likes Received:
    0
    Trophy Points:
    0
    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. ski

    ski Well-Known Member

    Joined:
    Feb 12, 2010
    Messages:
    3,720
    Likes Received:
    48
    Trophy Points:
    48
    Its for HB1. I know all of it is functional except for the shutdown part, I just added that to my existing code.
     
  7. zbit

    zbit New Member

    Joined:
    Feb 16, 2010
    Messages:
    20
    Likes Received:
    0
    Trophy Points:
    0
    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. ski

    ski Well-Known Member

    Joined:
    Feb 12, 2010
    Messages:
    3,720
    Likes Received:
    48
    Trophy Points:
    48
    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. zbit

    zbit New Member

    Joined:
    Feb 16, 2010
    Messages:
    20
    Likes Received:
    0
    Trophy Points:
    0
    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 :)
     
  10. Frymy

    Frymy New Member

    Joined:
    Jan 15, 2010
    Messages:
    36
    Likes Received:
    0
    Trophy Points:
    0
    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
     
  11. LiquidAtoR

    LiquidAtoR Community Developer

    Joined:
    Jan 15, 2010
    Messages:
    1,437
    Likes Received:
    52
    Trophy Points:
    48

Share This Page