Gaming Profile Topic is solved
Re: Gaming Profile
At a Windows command prompt, you can type sc query to see the names of all Windows services. You can then update line 1 with your service's name.
Re: Gaming Profile
Can I not just put that in the runwait, command and start?
Code: Select all
RunWait, % "net " (start) fxssvc.exe
Re: Gaming Profile
Code: Select all
If !A_IsAdmin && !RegExMatch(DllCall("GetCommandLine", "str"), " /restart(?!\S)") {
Try Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%"
ExitApp
}
proc = fxssvc
svcName := svcName(proc)
F3::service(svcName) ; Start service
F4::service(svcName, False) ; Stop service
service(name, start := True) {
RunWait, % "net " (start ? "start " : "stop ") name,, Hide
}
svcName(proc) {
Clipboard =
RunWait, %ComSpec% /c "wmic service where "pathname like '`%%proc%.exe`%'" get name`,pathname| clip",, Hide
ClipWait, 0
If !ErrorLevel {
RegExMatch(Clipboard, "(.+?) +?.*" proc, m)
Return m1
} Else MsgBox, 48, Error, An error occurred while waiting for the clipboard.
}
Re: Gaming Profile
I was hoping to start or stop each service as a run command. As I have many services to disable or start on the fly, so will just call a batch file if that is easyer. But will try you script when I get back on my pc as see to a point what your linking.
Like runwait, % "net" is like to call a service?
And this will depend on the file in game.txt
Like runwait, % "net" is like to call a service?
And this will depend on the file in game.txt
Re: Gaming Profile
My hunch is that AHK will save you the hassle of writing a Windows batch file to identify the service name.
NET is used to manage Windows services.
NET is used to manage Windows services.
Re: Gaming Profile
Code: Select all
RunWait,Powershell Stop-service -name wuauserv,,hide ; first way, this stops the windows update service using powershell
RunWait,SC Stop "wuauserv",,hide ; this will stop the service via command line.
RunWait,net Stop "wuauserv",,hide
Update will use the sc and net way i think.
So will be like below
Code: Select all
;RunWait,sc config "wuauserv" start= Disabled,,hide ; stoped auto start
;RunWait,net Stop "wuauserv",,hide ; Stoped the service
RunWait,sc config "wuauserv" start= Auto,,hide ; Set to auto start
RunWait,net Start "wuauserv",,hide ; started the service
Re: Gaming Profile
It makes no difference. All of the commands work.
Re: Gaming Profile
With net I dont think I can set the start state of the service, why I used sc
Re: Gaming Profile
Is this correct what i am tryig to do with the goto and the gosub?
Code: Select all
#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%
}
Goto, Str
Hi:
Run, powercfg.exe /setactive 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c
Return
Bal:
Runwait, powercfg.exe /setactive 381b4222-f694-41f0-9685-ff5bb260df2e
Return
Low:
RunWait, powercfg.exe /setactive a1841308-3541-4fab-bc81-f71556f20b4a
Return
Str:
loop
{
If WinExist("ahk_group last1")
{
Gosub, Hi
MsgBox, High Performance Power Profile.`n *GPU Overclock*`n Activated
WinWaitClose, ahk_group last1 ; Wait for all matching windows to close
GoSub, Low
MsgBox, Power Saving Profile.`n GPU Normal`n Activated
}
Else If WinExist("ahk_group fun")
{
Gosub, Bal
MsgBox, Balance Power Profile.`n *GPU Underclock* `n Activated
WinWaitClose, ahk_group fun ; Wait for all matching windows to close
GoSub, Low
MsgBox, Power Saving Profile.`n GPU Normal`n 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
Last edited by TrebleTA on 29 Nov 2021, 08:59, edited 3 times in total.
Re: Gaming Profile
Running the script will answer the question, but I would not think so. You can move your subroutines below your loop. You can then eliminate your Goto.
Re: Gaming Profile
it works fine, reason I put that there is I wanted the AHK script to miss the commands unless called apon
Re: Gaming Profile
It probably works better since you changed the script. To avoid confusion, I recommend avoiding such editing in the forum. Instead, you can create a reply with the revised script. That makes it easier for other readers to follow the conversation.
Re: Gaming Profile
Yes sorry I posted it to quickly.
Re: Gaming Profile
Ok below is my updated code, Problem i have is say windows search service fails to stop, say to another service my loop with get stuck as it's waiting for a service to stop that can not. How would I go about sorting that. Thanks.
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%
}
Goto, Str
Hi:
RunWait, 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:
RunWait, powercfg.exe /setactive 381b4222-f694-41f0-9685-ff5bb260df2e
RunWait, C:\Program Files (x86)\My Tool's\NV Inspector\nvidiaInspector.exe -setBaseClockOffset:0`,0`,-300 -setMemoryClockOffset:0`,0`,-400 -setPowerTarget:0`,80 -setTempTarget:0`,0`,80
Return
Low:
RunWait, 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 services
; Acronis Nonstop Backup Service
Run,sc config "afcdpsrv" start= Auto,,hide ; auto start
RunWait,net Start "afcdpsrv",,hide ; Start service
; Acronis Scheduler2 Service
Run,sc config "AcrSch2Svc" start= Auto,,hide ; auto start
RunWait,net Start "AcrSch2Svc",,hide ; start service
; Connected Devices Platform Service
Run,sc config "CDPSvc" start= Delayed-Auto,,hide ; delayed auto start
RunWait,net Start "CDPSvc",,hide ; Start service
; Connected User Experiences and Telemetry
Run,sc config "DiagTrack" start= Auto,,hide ; auto start
RunWait,net Start "DiagTrack",,hide ; Start service
; Distributed Link Tracking Client
Run,sc config "TrkWks" start= Auto,,hide ; auto start
RunWait,net Start "TrkWks",,hide ; Start service
; Geolocation Service
Run,sc config "lfsvc" start= Demand,,hide ; Manual start
; RunWait,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
RunWait,net Start "LGHUBUpdaterService",,hide ; Start service
; Microsoft Office Click-to-Run Service
; Run,sc config "ClickToRunSvc" start= Delayed-Auto,,hide ; auto delay start
; RunWait,net Start "ClickToRunSvc",,hide ; Start service
; Network Connected Devices Auto-Setup
Run,sc config "NcdAutoSetup" start= Demand,,hide ; Manual start
RunWait,net Start "NcdAutoSetup",,hide ; Start service
; Portable Device Enumerator Service
Run,sc config "WPDBusEnum" start= Demand,,hide ; Manual auto start
;RunWait,net Start "WPDBusEnum",,hide ; Dont need to Start the service
; Print Spooler
Run,sc config "Spooler" start= Auto,,hide ; auto start
RunWait,net Start "Spooler",,hide ; Start service
; Program Compatibility Assistant Service
Run,sc config "PcaSvc" start= Delayed-Auto,,hide ; auto Delay start
RunWait,net Start "PcaSvc",,hide ; Start service
; Simple TCP/IP Services
; Run,sc config "simptcp" start= Auto,,hide ; auto start
; RunWait,net Start "simptcp",,hide ; Start service
; Server
Run,sc config "LanmanServer" start= Delayed-Auto,,hide ; auto start
RunWait,net Start "LanmanServer",,hide ; Start service
; SysMain
Run,sc config "SysMain" start= Auto,,hide ; auto start
RunWait,net Start "SysMain",,hide ; Start service
; Windows Image Acquisition (WIA)
Run,sc config "StiSvc" start= Demand,,hide ; Manual start
RunWait,net Start "StiSvc",,hide ; Start service
; Windows Media Player Network Sharing Service
Run,sc config "WMPNetworkSvc" start= Delayed-Auto,,hide ; Stopped auto start
RunWait,net Start "WMPNetworkSvc",,hide ; Stopped the service
; Windows Search
Run,sc config "WSearch" start= Delayed-Auto,,hide ; auto Delay start
RunWait,net Start "WSearch",,hide ; Start service
; Windows Update
Run,sc config "wuauserv" start= Demand,,hide ; auto start
; RunWait,net Start "wuauserv",,hide ; Dont need to Start the service
; WLAN AutoConfig
Run,sc config "WlanSvc" start= Auto,,hide ; Auto start
RunWait,net Start "WlanSvc",,hide ; Start service
Return
SvcSP: ; Stop services
; Acronis Nonstop Backup Service
Run,sc config "afcdpsrv" start= Disabled,,hide ; Stopped auto start
RunWait,net Stop "afcdpsrv",,hide ; Stopped the service
; Acronis Scheduler2 Service
Run,sc config "AcrSch2Svc" start= Disabled,,hide ; Stopped auto start
RunWait,net Stop "AcrSch2Svc",,hide ; Stopped the service
; Connected Devices Platform Service
Run,sc config "CDPSvc" start= Disabled,,hide ; Stopped auto start
RunWait,net Stop "CDPSvc",,hide ; Stopped the service
; Connected User Experiences and Telemetry
Run,sc config "DiagTrack" start= Disabled,,hide ; Stopped auto start
RunWait,net Stop "DiagTrack",,hide ; Stopped the service
; Distributed Link Tracking Client
Run,sc config "TrkWks" start= Disabled,,hide ; Stopped auto start
RunWait,net Stop "TrkWks",,hide ; Stopped the service
; Geolocation Service
Run,sc config "lfsvc" start= Disabled,,hide ; Stopped auto start
RunWait,net Stop "lfsvc",,hide ; Stopped the service
; LGHUB Updater Service
Run,sc config "LGHUBUpdaterService" start= Disabled,,hide ; Stopped auto start
RunWait,net Stop "LGHUBUpdaterService",,hide ; Stopped the service
; Microsoft Office Click-to-Run Service
; Run,sc config "ClickToRunSvc" start= Disabled,,hide ; Stopped auto start
; RunWait,net Stop "ClickToRunSvc",,hide ; Stopped the service
; Network Connected Devices Auto-Setup
Run,sc config "NcdAutoSetup" start= Disabled,,hide ; Stopped auto start
RunWait,net Stop "NcdAutoSetup",,hide ; Stopped the service
; Portable Device Enumerator Service
Run,sc config "WPDBusEnum" start= Disabled,,hide ; Stopped auto start
RunWait,net Stop "WPDBusEnum",,hide ; Stopped the service
; Print Spooler
Run,sc config "Spooler" start= Disabled,,hide ; Stopped auto start
RunWait,net Stop "Spooler",,hide ; Stopped the service
; Program Compatibility Assistant Service
Run,sc config "PcaSvc" start= Disabled,,hide ; Stopped auto start
RunWait,net Stop "PcaSvc",,hide ; Stopped the service
; Simple TCP/IP Services
; Run,sc config "simptcp" start= Disabled,,hide ; Stopped auto start
; RunWait,net Stop "simptcp",,hide ; Stopped the service
; Server
Run,sc config "LanmanServer" start= Disabled,,hide ; Stopped auto start
RunWait,net Stop "LanmanServer",,hide ; Stopped the service
; SysMain
Run,sc config "SysMain" start= Disabled,,hide ; Stopped auto start
RunWait,net Stop "SysMain",,hide ; Stopped the service
; Windows Image Acquisition (WIA)
Run,sc config "StiSvc" start= Disabled,,hide ; Stopped auto start
RunWait,net Stop "StiSvc",,hide ; Stopped the service
; Windows Media Player Network Sharing Service
Run,sc config "WMPNetworkSvc" start= Disabled,,hide ; Stopped auto start
RunWait,net Stop "WMPNetworkSvc",,hide ; Stopped the service
; Windows Search
Run,sc config "WSearch" start= Disabled,,hide ; Stopped auto start
RunWait,net Stop "WSearch",,hide ; Stopped the service
; Windows Update
Run,sc config "wuauserv" start= Disabled,,hide ; Stopped auto start
RunWait,net Stop "wuauserv",,hide ; Stopped the service
; WLAN AutoConfig
Run,sc config "WlanSvc" start= Disabled,,hide ; Stopped auto start
RunWait,net Stop "WlanSvc",,hide ; Stopped the service
Return
Str:
loop
{
If WinExist("ahk_group last1")
{
GoSub, Hi ; High Power Profile and OC GPU
GoSub, SvcSP ; Stop Services
MsgBox, High Performance Power Profile.`n GPU Overclock`n Activated
WinWaitClose, ahk_group last1 ; Wait for all matching windows to close
GoSub, Low ; Power saving profile , Default GPU
GoSub, SvcST ; Start Services
MsgBox, Power Saving Profile.`n Default GPU`n Activated
}
Else If WinExist("ahk_group fun")
{
GoSub, Bal ; Balance power profile, GPU Underclocked
GoSub, SvcSP ; Stop Services
MsgBox, Balance Power Profile.`n GPU Underclock`n Activated
WinWaitClose, ahk_group fun ; Wait for all matching windows to close
GoSub, Low ; Power saving profile , Default GPU
GoSub, SvcST ; Start Services
MsgBox, Power Saving Profile.`n Default GPU`n Activated
}
}
#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
Re: Gaming Profile
If needed, you can use Run instead of RunWait. That will enable you to wait for some amount of time, and then check to see whether the service has stopped, whether the process is still running, etc.
Re: Gaming Profile
there seems to be something wrong with how its reading the games.txt
If I run es2-win64-shipping it runs ahk_group fun
yet if I do it like this it runs ahk_group last1
Code: Select all
Anno1800.exe, ES2-Win64-Shipping.exe1, Notepad.exe
yet if I do it like this it runs ahk_group last1
Code: Select all
Anno1800.exe, ES2-Win64-Shipping.exe1, Notepad.exe1
Re: Gaming Profile
You can debug your script by finding out what is in each of the two window groups-- you can display the values as they are added-- and by displaying the value of each conditional statement in the script.
Re: Gaming Profile
yes its putting ES2-Win64-Shipping.exe1 in the wrong group so its something with the file reading?
Re: Gaming Profile
How do you know that, and which group is it?
Re: Gaming Profile
If I run notepad.exe1 it then reads ES2-Win64-Shipping.exe1TrebleTA wrote: ↑04 Dec 2021, 11:55there seems to be something wrong with how its reading the games.txtIf I run es2-win64-shipping it runs ahk_group funCode: Select all
Anno1800.exe, ES2-Win64-Shipping.exe1, Notepad.exe
yet if I do it like this it runs ahk_group last1Code: Select all
Anno1800.exe, ES2-Win64-Shipping.exe1, Notepad.exe1
Who is online
Users browsing this forum: No registered users and 54 guests