Hi @Mikeyww thank you for all the support I would not of got this far with out you, I have almost finished the code with your help as your see below I have taken the admin check from someone else, but is there anything I have done worng, or should not of done?
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
If !FileExist(games)
{
MsgBox, 48, Error, File not found.`n`n%games%
Return
}
Else
FileRead, text, %games%
For each, game in StrSplit(text, ",")
{
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")
{
Run, powercfg.exe /setactive 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c
MsgBox, High Performance Power Profile.`n GPU Overclock`n Activated
WinWaitClose, ahk_group last1 ; Wait for all matching windows to close
Run, powercfg.exe /setactive 381b4222-f694-41f0-9685-ff5bb260df2e
MsgBox, Balance Power Profile.`n`n GPU Default Activated
}
If WinExist("ahk_group fun")
{
Run, powercfg.exe /setactive 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c
MsgBox, High Performance Power Profile.`n GPU Underclocked `n Activated
WinWaitClose, ahk_group fun ; Wait for all matching windows to close
Run, powercfg.exe /setactive 381b4222-f694-41f0-9685-ff5bb260df2e
MsgBox, Balance Power Profile.`n`n GPU Normal Activated
}
}
#IfWinActive ahk_group last1 ; Check if this group is running (High Performance Games)
; 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
Big thanks