In my batch script, I have updated a few things so I guess maybe it might help some of you struggling to get this working.
Code:
SETLOCAL
ECHO OFF
SET run_as=C:\Windows\System32\runas.exe
REM Name of the local user account you are having launch the EXE
SET local_user=limited
REM Possible EXE names: PathOfExile.exe, PathOfExile_x64.exe, PathOfExileSteam.exe, PathOfExile_x64Steam.exe, PathOfExile_KG.exe, PathOfExile_x64_KG.exe
SET exe_name=PathOfExile_x64.exe
REM You can launch the game with additional Parameters --waitforpreload
SET exe_params=--nologo
REM Keep in mind because of strange reasons this one must have / instead of \
SET exe_path=D:/Program Files (x86)/Grinding Gear Games/Path of Exile
REM Make sure to change this drive letter if not on C: drive
CD D:
REM Now we run the code you provided
TASKLIST /fi "IMAGENAME eq %exe_name%" 2>NUL | FIND /I /N "%exe_name%">NUL
IF NOT "%ERRORLEVEL%"=="0" START %run_as% /user:%local_user% /savecred "cmd /C cd /D \"%exe_path%\" && Start /high %exe_name% %exe_params%"
So lets break down some parts of what its doing:
Code:
SETLOCAL
ECHO OFF
SET run_as=C:\Windows\System32\runas.exe
This section sets a variable which will contain the path to your runas exe
Code:
SET local_user=limited
Here we set a variable with the name of the local user which we are going to use to run the game as
Code:
SET exe_name=PathOfExile_x64.exe
Here we set a variable with the EXE we will run for the game
Code:
SET exe_params=--nologo
Here we set a variable with any additional runtime commands you want passed to the game (optional)
Code:
SET exe_path=D:/Program Files (x86)/Grinding Gear Games/Path of Exile
Here we set a variable with the path to the game, being mindful that you need to reverse the slashes! So if you copy it from windows explorer, just replace all the \ with /
We enter the directory tree at the root of the drive which path of exile is installed, in my case it is the D drive.
Code:
TASKLIST /fi "IMAGENAME eq %exe_name%" 2>NUL | FIND /I /N "%exe_name%">NUL
IF NOT "%ERRORLEVEL%"=="0" START %run_as% /user:%local_user% /savecred "cmd /C cd /D \"%exe_path%\" && Start /high %exe_name% %exe_params%"
First it gathers the processes list from windows, which will contain that exe.
It passes that through a pipe to FIND, which will search for the specified name.
If the search comes up with an errorlevel, then it means the exe was not found
Then it runs the last crucial portion, which launches the exe as another user.
Code:
START %run_as% /user:%local_user% /savecred "cmd /C cd /D \"%exe_path%\" && Start /high %exe_name% %exe_params%"
You can further break down the runas command into a more generic form:
Code:
START %run_as% /user:%local_user% /savecred "<Your command here>"
The key here to notice, is that anything within the quoted section of the runas command must have reversed slashes in the path.