Or Easier: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);
}
}
Source: http://stackoverflow.com/questions/102567/how-to-shutdown-the-computer-from-cSystem.Diagnostics.Process.Start("Shutdown", "-s -t 10");
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();
}
}
}
}
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![]()
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()
System.Diagnostics.Process.Start("Shutdown", "-s -t 10");