My code here loops through all WoW that are currently running and then loops through all offsets I have in an array to find what version of WoW and the character name of that WoW. It then returns a List<string> of all running copies of WoW in the format of:
Character Name (ProcessID) (WoWVersion)
This is way more than what you were asking for, but you should be able to figure out how to trim out the stuff you don't need.. I am using BlackMagic anywhere you see Memory.Memory.
What you want to do is:
Get all Processes of WoW running
Foreach Process in Processes.
-> OpenProcessAndThread(ProcessID)
-> ReadString(CharacterName)
-> Add that character name to a list.
Code:
public static List<string> WoWProcesses()
{
List<string> myList = new List<string>();
Process[] processes = Process.GetProcessesByName("Wow");
string[,] OffsetArray = selectFormOffsetsArray;
if (processes.Length < 0)
{
myList.Clear();
}
else
{
int intCurrentProcessID;
int count = processes.Length - 1;
for (int i = 0; i <= count; i++)
{
intCurrentProcessID = processes[i].Id;
clsMemory.Memory = new Hook(intCurrentProcessID);
try
{
Memory.Memory.OpenProcessAndThread(intCurrentProcessID);
//scan each offset to see if the value checks out.
for (int y = 0; y < 1024; y++)
{
//until we get a null value.
if (OffsetArray[y, 0] != null)
{
//scan
string wowVersion = ReadUTF8String((uint)Memory.Memory.MainModule.BaseAddress + uint.Parse(OffsetArray[y, 2].Replace("0x", "").Trim(), System.Globalization.NumberStyles.HexNumber), 5);
if (wowVersion == OffsetArray[y, 1])
{
//wow version match, check for player
string myCharName = ReadUTF8String((uint)Memory.Memory.MainModule.BaseAddress + uint.Parse(OffsetArray[y, 3].Replace("0x", "").Trim(), System.Globalization.NumberStyles.HexNumber), 30);
if (myCharName != "")
{
myList.Add(myCharName + " (" + intCurrentProcessID + ") (" + wowVersion + ")");
break;
}
else
{
myList.Add("Not Logged In" + " (" + intCurrentProcessID + ") (" + wowVersion + ")");
break;
}
}
}
if (OffsetArray[y, 0] == null)
{
break;
}
}
}
catch
{
//bad read, continue on.
}
}
}
return myList;
}