Skip to content

Instantly share code, notes, and snippets.

@dafzor
Created August 14, 2019 21:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dafzor/4d4964ef8753e6a992ec6691ce974cf0 to your computer and use it in GitHub Desktop.
Save dafzor/4d4964ef8753e6a992ec6691ce974cf0 to your computer and use it in GitHub Desktop.
Proof of concept for launching World of Warcraft Classic
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Windows.Forms;
namespace ProofOfConcept
{
class Program
{
[DllImport("user32.dll")]
private static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
static extern int GetWindowTextLength(IntPtr hWnd);
[DllImport("user32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString,
int nMaxCount);
static void Main(string[] args)
{
// launch battle.net client with the parameters World of Warcraft Launcher.exe gives it, this will open the UI on the correct page
Process.Start("C:\\Program Files (x86)\\Battle.net\\Battle.net.exe", "--game=wow_enus --gamepath=\"G:\\World of Warcraft\" --productcode=wow_classic");
while (true)
{
// Check the foreground window title
IntPtr h = GetForegroundWindow();
int len = GetWindowTextLength(h);
StringBuilder title = new StringBuilder(len + 1);
GetWindowText(h, title, title.Capacity);
Console.WriteLine(title.ToString());
// if it's the battle.net client send the enter key to launch the game
if (title.ToString().Equals("Blizzard Battle.net"))
{
SendKeys.SendWait("{ENTER}");
return;
}
// unsire if i need to trottle down the foreground check or not
// Thread.Sleep(100);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment