Gaming Profile Topic is solved

Ask gaming related questions (AHK v1.1 and older)
User avatar
mikeyww
Posts: 26602
Joined: 09 Sep 2014, 18:38

Re: Gaming Profile

04 Dec 2021, 15:05

That is what your script said to do. If you need to parse your command line to get the first process name on the line, then you would need to add that code to your script.
TrebleTA
Posts: 134
Joined: 20 Nov 2021, 06:44

Re: Gaming Profile

05 Dec 2021, 06:04

Yes but stll i dont get it putting notepad.exe1 in the game.txt should not affected the other ES2-Win64-Shipping.exe1, if notepad.exe then it reads this as ES2-Win64-Shipping.exe, yet it should see the 1
TrebleTA
Posts: 134
Joined: 20 Nov 2021, 06:44

Re: Gaming Profile

05 Dec 2021, 06:06

I think it would read a line till it hit a , then will look at last letter see if it's a e or a 1.
User avatar
mikeyww
Posts: 26602
Joined: 09 Sep 2014, 18:38

Re: Gaming Profile

05 Dec 2021, 07:04

I will stop posting here, because we are on page 5, and I have not solved your problem yet. My impression is that your actual games.txt file is not what you described initially, if it contains multiple process names per line. You could go through your script line by line, to see what happens with each line. Display the values of your variables and conditional statements. To ease the debugging, I also suggest that you shorten your test script to include only the essential parts.
TrebleTA
Posts: 134
Joined: 20 Nov 2021, 06:44

Re: Gaming Profile

05 Dec 2021, 08:52

well this was not a problem post it was a request for help with making the script, the only part I have used is your file read script, and now am asking for help with that as its not responding how it should.
At moment am trying to see what is in the ahk_group Fun just unsure how to put it in a message box.

p.s the games.txt is how i have linked above. no extra space's or commands just them 3 exe's for now how shown above ending with a ,
User avatar
mikeyww
Posts: 26602
Joined: 09 Sep 2014, 18:38

Re: Gaming Profile

05 Dec 2021, 09:10

Here is a way to display what is in the group.

Code: Select all

text = ab.exe, cd.exe1,ef.exe1
For each, game in StrSplit(text, ",")
{
 game := Trim(game), lastChar := SubStr(game, 0), thisGame := lastChar = "e" ? game : SubStr(game, 1, -1)
 MsgBox, 64, Status, %thisGame%`n`nLast: last%lastChar%
 GroupAdd, fun           , ahk_exe %thisGame%
 GroupAdd, last%lastChar%, ahk_exe %thisGame%
}
TrebleTA
Posts: 134
Joined: 20 Nov 2021, 06:44

Re: Gaming Profile

05 Dec 2021, 09:16

Thank you Mikeyww for helping me with this.
I used the %thisgame% in my Original script and all its was showing was the last exe in the text file. why i was trying to see what was in the ahk_group Fun, But I will mess around with what you have linked and get back to you as see you have added more to your script above.
User avatar
mikeyww
Posts: 26602
Joined: 09 Sep 2014, 18:38

Re: Gaming Profile

05 Dec 2021, 09:20

Every element is added to the fun group. Every element is then added to a group whose name reflects the element's last character. That allows you to work with both groups as needed.
TrebleTA
Posts: 134
Joined: 20 Nov 2021, 06:44

Re: Gaming Profile

05 Dec 2021, 09:52

I see so say if notepad.exe1 was in the game.txt its in both ahk_group's.
The reading of the game.txt seems to be correct now and the scripted seems to be working super, But have 1 more question.
Is there a way to detect the game that is running so I can put in the message box like notepad detected profile activated in the lower part of the script. if its too much then its ok as this is just want I was after. Its more for my kids as I don't like them messing with system stuff, so they can get better performance on there older pc.
User avatar
mikeyww
Posts: 26602
Joined: 09 Sep 2014, 18:38

Re: Gaming Profile

05 Dec 2021, 10:38

You already know how to use WinExist and Loop, so you can use WinExist inside your loop.

Code: Select all

For each, game in StrSplit(text, ",")
{
 lastChar := SubStr(game, 0), thisGame := lastChar = "e" ? game : SubStr(game, 1, -1)
 If WinExist("ahk_exe " thisGame)
  MsgBox, 64, Game is running, %thisGame%
}
TrebleTA
Posts: 134
Joined: 20 Nov 2021, 06:44

Re: Gaming Profile

05 Dec 2021, 11:56

Thanks i added it to my script but have noticed there is a chance it will miss the

Code: Select all

If WinExist("ahk_group last1")
command so I changed it to

Code: Select all

 Else If WinExist("ahk_group fun"), !WinExist("ahk_group last1")
Hope its correct, else this is my finished script.

Code: Select all

; First, we're calling Window's GetCommandLine() function
; This function retrieves the command-line string for the current process
; We need this string to see if the script is running with the /restart switch
full_command_line := DllCall("GetCommandLine", "str")

; This if-check fires if either of the 2 evaluations are true
; Note the 'not' prefix. This if check fires when 'not' true (false)
; 1) If the script is 'not' running as admin (A_IsAdmin stores whether a script has admin rights)
; OR
; 2) If the full_command_line from above does 'not' contain /restart
;	/Restart is a command line switch that tells the script "this is a restart, not a normal load"
;	This affects some internal things as well as prevents #SingleInstance notifications
; This if-check makes sure that every script is forced to restart with the *RunAs verb
; This ensures the script is always given a chance to launch with elevated rights

if not (A_IsAdmin or RegExMatch(full_command_line, " /restart(?!\S)"))
{
	; Try is used so that any runtime errors are suppressed
	try
	{
		; The next if check makes sure that .ahk and .exe scripts are restarted correctly

		; Check if the current script is compiled (.exe) or a script (.ahk)
		if A_IsCompiled
			; If compiled, restart using the exe method:
			; CompiledScript.exe [Switches] [Script Parameters]
			; This is covered in the script docs. Link below code.
			Run *RunAs "%A_ScriptFullPath%" /restart
		else
			; If not compiled, restart using the script method:
			; AutoHotkey.exe [Switches] [Script Filename] [Script Parameters]
			Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%"
	}
	; ExitApp to close this script because we're restarting it with a request for admin rights
	ExitApp
}
; At this point, the script HAS been restarted and is running with admin rights if it can
; MsgBox A_IsAdmin: %A_IsAdmin%`nCommand line: %full_command_line%

#SingleInstance Force		; Forces a Single instance
#Warn 				; Enable warnings to assist with detecting common errors.
#NoEnv				; Recommended for performance and compatibility with future AutoHotkey releases.
; #NoTrayIcon 			; Disable the tray icon of the script
; SendMode Input		; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%	; Ensures a consistent starting directory.
; SetBatchLines, -1		; Run script at maximum speed
SetCapsLockState, AlwaysOff 	; Disables the caps lock key and defaults off

games = Games.txt 		; Name of my Input file

Process, Exist, HWiNFO64.exe ; check to see if HWiNFO64.exe is running
{
	If ! errorLevel
	{
		IfExist, C:\Program Files (x86)\My Tool's\HWinfo\HWiNFO64.exe
		Run,C:\Program Files (x86)\My Tool's\HWinfo\HWiNFO64.exe
	}
}

Goto, Str

Hi: 
	Run, powercfg.exe /setactive 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c
	RunWait, C:\Program Files (x86)\My Tool's\NV Inspector\nvidiaInspector.exe -setBaseClockOffset:0`,0`,22 -setMemoryClockOffset:0`,0`,200 -setPowerTarget:0`,114 -setTempTarget:0`,0`,80
Return

Bal:
	Run, powercfg.exe /setactive 381b4222-f694-41f0-9685-ff5bb260df2e
	RunWait, C:\Program Files (x86)\My Tool's\NV Inspector\nvidiaInspector.exe -setBaseClockOffset:0`,0`,-200 -setMemoryClockOffset:0`,0`,-400 -setPowerTarget:0`,70 -setTempTarget:0`,0`,70
Return

Low:
	Run, powercfg.exe /setactive a1841308-3541-4fab-bc81-f71556f20b4a
	RunWait, C:\Program Files (x86)\My Tool's\NV Inspector\nvidiaInspector.exe -setBaseClockOffset:0`,0`,0 -setMemoryClockOffset:0`,0`,0 -setPowerTarget:0`,100 -setTempTarget:0`,0`,80
Return

SvcSt:									; Start System services
	; Acronis Nonstop Backup Service
	Run,sc config "afcdpsrv" start= Auto,,hide 			; auto start
	Run,net Start "afcdpsrv",,hide					; Start service

	; Acronis Scheduler2 Service
	Run,sc config "AcrSch2Svc" start= Auto,,hide 			; auto start
	Run,net Start "AcrSch2Svc",,hide				; start service	

	; Connected Devices Platform Service
	Run,sc config "CDPSvc" start= Delayed-Auto,,hide 		; delayed auto start
	Run,net Start "CDPSvc",,hide					; Start service

	; Connected User Experiences and Telemetry
	Run,sc config "DiagTrack" start= Auto,,hide 			; auto start
	Run,net Start "DiagTrack",,hide					; Start service

	; Distributed Link Tracking Client
	Run,sc config "TrkWks" start= Auto,,hide 			; auto start
	Run,net Start "TrkWks",,hide					; Start service

	; Geolocation Service
	Run,sc config "lfsvc" start= Demand,,hide 			; Manual start
	; Run,net Start "lfsvc",,hide					; Dont need to Start the service
	
	; LGHUB Updater Service
	Run,sc config "LGHUBUpdaterService" start= Delayed-Auto,,hide 	; Auto start Changed to delayed
	Run,net Start "LGHUBUpdaterService",,hide			; Start service

	; Microsoft Office Click-to-Run Service
	; Run,sc config "ClickToRunSvc" start= Delayed-Auto,,hide 	; auto delay start
	; Run,net Start "ClickToRunSvc",,hide				; Start service

	; Network Connected Devices Auto-Setup
	Run,sc config "NcdAutoSetup" start= Demand,,hide 		; Manual start
	Run,net Start "NcdAutoSetup",,hide				; Start service

	; Portable Device Enumerator Service
	Run,sc config "WPDBusEnum" start= Demand,,hide 			; Manual auto start
	;Run,net Start "WPDBusEnum",,hide				; Dont need to Start the service

	; Print Spooler
	Run,sc config "Spooler" start= Auto,,hide 			; auto start
	Run,net Start "Spooler",,hide					; Start service

	; Program Compatibility Assistant Service
	Run,sc config "PcaSvc" start= Delayed-Auto,,hide 		; auto Delay start
	Run,net Start "PcaSvc",,hide					; Start service

	; Simple TCP/IP Services
	; Run,sc config "simptcp" start= Auto,,hide 			; auto start
	; Run,net Start "simptcp",,hide					; Start service

	; Server
	Run,sc config "LanmanServer" start= Delayed-Auto,,hide 		; auto start
	Run,net Start "LanmanServer",,hide				; Start service

	; SysMain
	Run,sc config "SysMain" start= Auto,,hide 			; auto start
	Run,net Start "SysMain",,hide					; Start service

	; Windows Image Acquisition (WIA)
	Run,sc config "StiSvc" start= Demand,,hide 			; Manual start
	Run,net Start "StiSvc",,hide					; Start service

	; Windows Media Player Network Sharing Service
	Run,sc config "WMPNetworkSvc" start= Delayed-Auto,,hide 	; Stopped auto start
	Run,net Start "WMPNetworkSvc",,hide				; Stopped the service

	; Windows Search
	Run,sc config "WSearch" start= Delayed-Auto,,hide 		; auto Delay start
	Run,net Start "WSearch",,hide					; Start service

	; Windows Update
	Run,sc config "wuauserv" start= Demand,,hide 			; auto start
	; Run,net Start "wuauserv",,hide				; Dont need to Start the service

	; WLAN AutoConfig
	Run,sc config "WlanSvc" start= Auto,,hide 			; Auto start
	Run,net Start "WlanSvc",,hide					; Start service	
Return

SvcSP: 									; Stop Syetem services
	; Acronis Nonstop Backup Service
	Run,sc config "afcdpsrv" start= Disabled,,hide 			; Stopped auto start
	Run,net Stop "afcdpsrv",,hide					; Stopped the service

	; Acronis Scheduler2 Service
	Run,sc config "AcrSch2Svc" start= Disabled,,hide 		; Stopped auto start
	Run,net Stop "AcrSch2Svc",,hide					; Stopped the service	

	; Connected Devices Platform Service
	Run,sc config "CDPSvc" start= Disabled,,hide 			; Stopped auto start
	Run,net Stop "CDPSvc",,hide					; Stopped the service
		
	; Connected User Experiences and Telemetry
	Run,sc config "DiagTrack" start= Disabled,,hide 		; Stopped auto start
	Run,net Stop "DiagTrack",,hide					; Stopped the service


	; Distributed Link Tracking Client
	Run,sc config "TrkWks" start= Disabled,,hide 			; Stopped auto start
	Run,net Stop "TrkWks",,hide					; Stopped the service

	; Geolocation Service
	Run,sc config "lfsvc" start= Disabled,,hide 			; Stopped auto start
	Run,net Stop "lfsvc",,hide					; Stopped the service

	; LGHUB Updater Service
	Run,sc config "LGHUBUpdaterService" start= Disabled,,hide 	; Stopped auto start
	Run,net Stop "LGHUBUpdaterService",,hide			; Stopped the service
	
	; Microsoft Office Click-to-Run Service
	; Run,sc config "ClickToRunSvc" start= Disabled,,hide 		; Stopped auto start
	; Run,net Stop "ClickToRunSvc",,hide				; Stopped the service
		
	; Network Connected Devices Auto-Setup
	Run,sc config "NcdAutoSetup" start= Disabled,,hide 		; Stopped auto start
	Run,net Stop "NcdAutoSetup",,hide				; Stopped the service

	; Portable Device Enumerator Service
	Run,sc config "WPDBusEnum" start= Disabled,,hide 		; Stopped auto start
	Run,net Stop "WPDBusEnum",,hide					; Stopped the service

	; Print Spooler
	Run,sc config "Spooler" start= Disabled,,hide 			; Stopped auto start
	Run,net Stop "Spooler",,hide					; Stopped the service

	; Program Compatibility Assistant Service
	Run,sc config "PcaSvc" start= Disabled,,hide 			; Stopped auto start
	Run,net Stop "PcaSvc",,hide					; Stopped the service
		
	; Simple TCP/IP Services
	; Run,sc config "simptcp" start= Disabled,,hide 		; Stopped auto start
	; Run,net Stop "simptcp",,hide					; Stopped the service

	; Server
	Run,sc config "LanmanServer" start= Disabled,,hide 		; Stopped auto start
	Run,net Stop "LanmanServer",,hide				; Stopped the service

	; SysMain
	Run,sc config "SysMain" start= Disabled,,hide 			; Stopped auto start
	Run,net Stop "SysMain",,hide					; Stopped the service

	; Windows Image Acquisition (WIA)
	Run,sc config "StiSvc" start= Disabled,,hide 			; Stopped auto start
	Run,net Stop "StiSvc",,hide					; Stopped the service

	; Windows Media Player Network Sharing Service
	Run,sc config "WMPNetworkSvc" start= Disabled,,hide 		; Stopped auto start
	Run,net Stop "WMPNetworkSvc",,hide				; Stopped the service

	; Windows Search
	Run,sc config "WSearch" start= Disabled,,hide 			; Stopped auto start
	Run,net Stop "WSearch",,hide					; Stopped the service

	; Windows Update
	Run,sc config "wuauserv" start= Disabled,,hide 			; Stopped auto start
	Run,net Stop "wuauserv",,hide					; Stopped the service

	; WLAN AutoConfig
	Run,sc config "WlanSvc" start= Disabled,,hide 			; Stopped auto start
	Run,net Stop "WlanSvc",,hide					; Stopped the service
Return

Str:

If !FileExist(games) 
{
	MsgBox, 48, Error, File not found.`n`n%games%
	Return
} 

Else
FileRead, text, %games%
For each, game in StrSplit(text, ",") 
{
	; MsgBox, 64, Status, %thisGame%`n`nLast Char: %lastChar%
	game := Trim(game), lastChar := SubStr(game, 0), thisGame := lastChar = "e" ? game : SubStr(game, 1, -1)
	GroupAdd, fun           , ahk_exe %thisGame%
	GroupAdd, last%lastChar%, ahk_exe %thisGame%
}

loop
{
	If WinExist("ahk_group last1")
	{
		GoSub, Hi									; Calls High Power Profile and OC GPU
		GoSub, SvcSP									; Calls Stop Services
		For each, game in StrSplit(text, ",")
		{
 			lastChar := SubStr(game, 0), thisGame := lastChar = "e" ? game : SubStr(game, 1, -1)
 			If WinExist("ahk_exe " thisGame)
  			MsgBox, 64, %thisGame% Detected, High Performance Power Profile.`nGPU Overclock`nActivated, 
		}
		WinWaitClose, ahk_group last1                              			; Wait for all matching windows to close
		GoSub, Low									; Calls Power saving profile , Default GPU
		GoSub, SvcST									; Calls Start Services
		MsgBox, 64, Game Closed, Power Saving Profile.`nDefault GPU`nActivated, 
	}

	Else If WinExist("ahk_group fun"), !WinExist("ahk_group last1")
	{ 
		GoSub, Bal									; Balance power profile, GPU Underclocked
		GoSub, SvcSP									; Stop Services
		For each, game in StrSplit(text, ",")
		{
 			lastChar := SubStr(game, 0), thisGame := lastChar = "e" ? game : SubStr(game, 1, -1)
 			If WinExist("ahk_exe " thisGame)
  			MsgBox, 64, %thisGame% Detected, Balance Power Profile.`nGPU Underclock`nActivated, 
		}
		WinWaitClose, ahk_group fun                        				; Wait for all matching windows to close
		GoSub, Low									; Power saving profile , Default GPU
		GoSub, SvcST									; Start Services
  		MsgBox, 64, Game Closed, Power Saving Profile.`nDefault GPU`nActivated, 
	}
}

#IfWinActive ahk_group last1	; Check if this group is running (High Performance profile)
; LWin::Return 			; Disables Left windows Key
!Tab::Return			; Disables Alt Tab

#IfWinActive ahk_group fun	; will do the below always
; CapsLock::Return		; Disables capslock, Not used as I use caps state always off above while this app is running.

#IfWinActive

User avatar
mikeyww
Posts: 26602
Joined: 09 Sep 2014, 18:38

Re: Gaming Profile

05 Dec 2021, 12:07

If , means AND, then use AND or && instead.
TrebleTA
Posts: 134
Joined: 20 Nov 2021, 06:44

Re: Gaming Profile

05 Dec 2021, 22:01

I just want to say, Thank you for all the help and putting up with all my questions, Yes the , was for a and.
For now this is done I hope, Once again thank you Mikeyww

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: zemplarius and 49 guests