Page 1 of 1

[Windows7+] Smart launcher script

Posted: Fri Jan 26, 2018 6:02 am
by Stoikva
This is intended as a last resort attempt too diagnose and run the client

To use, copy the code from below or from the link into notepad
Save as PKLauncher.bat and make sure to have file type set to all files (*)

(https://www.irccloud.com/pastebin/cUX4J ... uncher.bat)

Code: Select all

::
::
::		PKHonor advanced launcher for departertrons
::			
::			> Requests admin permision
::			> Runs anyway if admin can't be requests
::			> Checks if java is installed
::			> Attempts to run the .jars even if java isn't found
::			> Opens up java or client download pages if needed
::			
::         Feedback thread:  https://forums.pkhonor.net/viewtopic.php?f=49&t=70568
::         Update link:         https://www.irccloud.com/pastebin/cUX4Jd2b/PKLauncher.bat
::         Version:               v0.1
::
::
@echo off
cls
title=PKHonor client launcher

::set path
set log_path="%cd%\%~n0_log.txt"
::display and log information
call :log ----------------%date% PKHonor start

::Write some information from sys32 to none existant file
::Only admin can perform this and the action is benign (does nothing)
::except what it can do is raise the %errorlevel% state to indicate an error
::this means we can know if the script is ran as admin or not
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"

::error level '0' means no errors, we are admin
if '%errorlevel%' EQU '0' (goto launchClient)
::if we are not admin then this code below will run
::This writes a visual basic script that will run this script as admin
::%~s0 is the the variable that outputs the location of this current script
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\RequestAdmin.vbs" 
echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\RequestAdmin.vbs"
::This runs the vb script and exit since we are starting again as admin
"%temp%\RequestAdmin.vbs"
::if we have failed to create the admin prompt script
::user is incapable of having admin priveledges
::this will make the script 
if '%errorlevel%' EQU '5' (
	call :log Cannot launch admin prompt
	goto notAdmin
	)
if '%errorlevel%' EQU '9059' (
	call :log Cannot find admin prompt
	goto notAdmin
	)
exit /B

::If we are admin we come here and skip the admin prompt
:launchClient
::clear up the temperary admin prompt script if it exists
IF EXIST "%temp%\RequestAdmin.vbs" (erase  "%temp%\RequestAdmin.vbs")
pushd "%CD%"
CD /D "%~dp0"
set log_path="%cd%\%~n0_log.txt"

:notAdmin

::Now we begin attempting to launch pkhonor

::First check if java can be located
set javaModule=NOJAVA

java -version >nul 2>&1 && (
 	set javaModule=java
	call :log java found
) 

javaw -version >nul 2>&1 && (
 	set javaModule=javaw
	call :log javaw found
)

::Now we search for pkhonor.jar
set PKClient=NOCLIENT

if exist "%userprofile%\Desktop\PKHonor.jar" (
	set PKClient="%userprofile%\Desktop\PKHonor.jar"
)

if exist "%userprofile%\Downloads\PKHonor.jar" (
	set PKClient="%userprofile%\Downloads\PKHonor.jar"
)

if exist "%cd%\PKHonor.jar" (
	set PKClient="%cd%\PKHonor.jar"
)

if exist %PKClient% (
	call :log PKHonor.jar found at %PKClient%
	call :log Launching client...
	if "%javaModule%" NEQ "NOJAVA" (
		Start %javaModule% -Xmx1000m -jar %PKClient%
	) else (
		start %PKClient%
		if '%errorlevel%' EQU '9059' (
			call :log No java found, please download at https://java.com/en/download/
			start "https://java.com/en/download/"
			pause
		)
		if '%errorlevel%' EQU '5' (
			call :log Unable to run java, please download at https://java.com/en/download/
			start "https://java.com/en/download/"
			pause
		)
	)
) else if exist "%userprofile%\Documents\My Games\PkHonor" (
	call :log No jar files where found but desktop client exists, attempting to run...
	cd "%userprofile%\Documents\My Games\PkHonor"
	start "Play PkHonor.bat"
) else (
	call :log Cannot find PKHonor.jar please download at https://www.pkhonor.net/playnow.php
	start "https://www.pkhonor.net/playnow.php"
	pause
)
exit /B
	
:log
	echo %*>>"%log_path%"
	echo PKHonor^> %*
	EXIT /B 0

Re: [Windows7+] Smart launcher script

Posted: Fri Jan 26, 2018 6:29 am
by Troll n roll
My .jar works fine, thanks though.

Re: [Windows7+] Smart launcher script

Posted: Fri Jan 26, 2018 8:44 am
by Simon
I tried to run this on my Mac and I received the error "unable to load pkhonor.exe"

I think it's an issue with my power supply. I'm going to try flipping the circuit breaker in my basement. Hopefully my client will load after the full restart is completed.

Re: [Windows7+] Smart launcher script

Posted: Fri Jan 26, 2018 4:17 pm
by Jon
Color x wrote:My .jar works fine, thanks though.
^

Re: [Windows7+] Smart launcher script

Posted: Fri Jan 26, 2018 8:49 pm
by Stoikva
Yes if you can run the client with no issues then this post isn't for you (: pretty much of someone is doing something wrong this should work and inform them of why it will not launch too providing a log too which may help provide better info as too why

Re: [Windows7+] Smart launcher script

Posted: Fri Jan 26, 2018 9:52 pm
by Slap a ho
Don’t think it reads through the typos, does it?

Re: [Windows7+] Smart launcher script

Posted: Fri Jan 26, 2018 10:24 pm
by Stoikva
Slap a ho wrote:Don’t think it reads through the typos, does it?
typos? People don't name their pkhonor.jar themselves so it's unlikely, however i will be adding support for finding the last modified one, as redownloading may go to PKHonor (2).jar and then they may delete pkhonor.jar later on aswell.

also planning on preforming manual searches for any java installation if the java/javaw environment variables are not set.