It is currently September 18th, 2021, 7:47 pm

Switching Game Mode on/off with a single desktop shortcut

Tips and Tricks from the Rainmeter Community
User avatar
konkeranto
Posts: 2
Joined: May 26th, 2021, 4:13 pm

Switching Game Mode on/off with a single desktop shortcut

Post by konkeranto »

I really wanted a button on my desktop that would turn the game mode of Rainmeter on/of. I had a sudden inspiration about how I could do it, so I decided to open an account and share this with other people that might need it.

First, you need Microsoft Visual Studio. From it you need to create a dummy exe file that does nothing.
You can do this by creating a new C# command line project, pasting this code in it, changing it to a windows application from its settings then compiling it. I named mine Noop.exe

Code: Select all

using System;
using System.Threading;

class Program {
    static void Main() {
        while(true) {
            Thread.Sleep(100); // So we don't spam the CPU too much
        }
    }
}
Source: https://stackoverflow.com/questions/19973473/i-need-an-executable-that-does-nothing

After this in Rainmeter game mode's settings activate Additional process list and write Noop.exe or the name of your exe file.
This will start the game mode when Noop.exe is launched and turn it off again when Noop.exe is closed. At the moment, you can only close it from task manager.

To make the desktop shortcut open notepad and paste this code, replace Noop.exe with the name of your own file and save it as GameMode.bat in the same folder with Noop.exe

Code: Select all

SETLOCAL EnableExtensions
set EXE=Noop.exe
FOR /F %%x IN ('tasklist /NH /FI "IMAGENAME eq %EXE%"') DO IF %%x == %EXE% goto FOUND
echo Not running
start Noop.exe
goto FIN
:FOUND
echo Running
TASKKILL /im Noop.exe /f /t
:FIN
Source: https://stackoverflow.com/questions/162291/how-to-check-if-a-process-is-running-via-a-batch-script

You can just make a desktop shortcut of GameMode.bat and use it, but it shows a cmd window for a second when you use it. If you don't want to see that you can open notepad again, paste this code and save it as GameMode.vbs

Code: Select all

Set WshShell = CreateObject("WScript.Shell") 
WshShell.Run chr(34) & "GameMode.bat" & Chr(34), 0
Set WshShell = Nothing
Source:https://www.winhelponline.com/blog/run-bat-files-invisibly-without-displaying-command-prompt/

Make a desktop shortcut of GameMode.vbs and change its icon to something you want. You can now use that to turn the game mode on/off.
User avatar
Brian
Developer
Posts: 2254
Joined: November 24th, 2011, 1:42 am
Location: Utah

Re: Switching Game Mode on/off with a single desktop shortcut

Post by Brian »

Ugg. I really hate this. Not because of the intention of the post or the process to achieve this (which is fairly clever). The main reason I dislike this is because it can potentially be exploited by skin authors to trigger game mode without user interaction.

Some things should be left to the end user. I know I personally won't use this, nor any skin that attempts to "force" game mode.

-Brian