Code: Select all
'Retrieves launcher/client path from .ini or ask user to point them
gameLauncher = ReadIni(iniFile, "General", "Launcher")
if gameLauncher = "" or gameLauncher = " " Then
MSGBOX "Select the LAUNCHER please"
WriteIni scriptDir & iniFile, "General", "Launcher", BrowseForFile()
gameLauncher = ReadIni(iniFile, "General", "Launcher")
end if
gameClient = ReadIni(iniFile, "General", "Client")
if gameClient = "" or gameClient = " " Then
MSGBOX "Select the CLIENT please"
WriteIni scriptDir & iniFile, "General", "Client", BrowseForFile()
gameClient = ReadIni(iniFile, "General", "Client")
end if
'Divide the full path into two variables containing respectively
'only the .exe and only the path without the .exe
Set objFile = oFSO.GetFile(gameLauncher)
lName = objFile.Name
lPath = objFile.Path
lPath = Left(lPath, Len(lPath)-Len(lName))
Set objFile = oFSO.GetFile(gameClient)
cName = objFile.Name
cPath = objFile.Path
cPath = Left(cPath, Len(cPath)-Len(cName))
'Here comes the script
scriptHome = WScript.ScriptFullName
scriptHome = Left(scriptHome, InStr(scriptHome, WScript.ScriptName) - 1)
WScript.Echo "[1/5] starting laucher"
SET objShell = WScript.CreateObject("Shell.Application")
objShell.ShellExecute lName, "", lPath
WScript.Echo "[2/5] waiting for launcher to start game..."
SET objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
DO WHILE TRUE
SET objInstanceList = objWMIService.ExecQuery("Select * from Win32_Process Where Name = '" & cName & "'")
FOR EACH objInstance IN objInstanceList
WScript.Echo "[3/5] game instance detected"
commandLine = objInstance.CommandLine
WScript.Echo "[4/5] killing game instance"
objInstance.Terminate()
EXIT DO
NEXT
WScript.Sleep 1000
LOOP
commandLine = Right(commandLine, Len(commandLine) - (InStr(1, commandLine, """ ") + 1))
WScript.Echo "[5/5] starting game again"
SET objShell = CreateObject("Shell.Application")
objShell.ShellExecute cName, commandLine, cPath
I can see how most of the commands can be converted to AHK equivalents but I'm puzzled on what exactly these lines are doing:
Code: Select all
SET objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
commandLine = objInstance.CommandLine
If anyone can help me out, I would greatly appreciate it.