It is currently March 29th, 2024, 2:55 pm

Run Rainmeter as a Service

Get help with installing and using Rainmeter.
rafael.pitanga
Posts: 1
Joined: August 10th, 2020, 6:09 pm

Run Rainmeter as a Service

Post by rafael.pitanga »

Hello everybody,

I'd like to know if Rainmeter can run as a service in Windows. I am trying to configure Rainmeter as a screen watermark and needed that Rainmeter runs as a service, using admin logon so the regular users could not be able to close it, or if they do, I am going to use another program that reopens Rainmeter automatically.

I tried to create a service using this command at Powershell, but it did not work when I try to start the service:

Code: Select all

New-Service -Name "Rainmeter" -DisplayName "Rainmeter" -Description "Rainmeter Service" -StartupType Automatic -BinaryPathName "C:\Program Files\Rainmeter\Rainmeter.exe"
I tried to find something related to that subject at the Forum, but did not find.

Thanks!
User avatar
SilverAzide
Rainmeter Sage
Posts: 2588
Joined: March 23rd, 2015, 5:26 pm

Re: Run Rainmeter as a Service

Post by SilverAzide »

rafael.pitanga wrote: August 10th, 2020, 6:24 pm I'd like to know if Rainmeter can run as a service in Windows.
No, it cannot. A Windows Service is a special type of executable, which is why you can't start it. Windows services also don't run like a normal user session, so it wouldn't work even if you could start it.
Gadgets Wiki GitHub More Gadgets...
User avatar
Yincognito
Rainmeter Sage
Posts: 7031
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Run Rainmeter as a Service

Post by Yincognito »

Yep. Tried the command, it created the service. However, I could not start it, for the reasons I already read and that were stated by SilverAzide. A word of caution though: if you use the posted command and you do not have PowerShell 6.0 on your PC, you might have trouble deleting the service. If so, delete it through WMI.

That being said, I also read one can create a service from "any executable" using some other software, but I'm not sure the created service would be able to start if it doesn't implement the Windows Services API / ServiceMain. I say this because the creation of the service wasn't a problem, but starting the resulting "service" was.

I would also like to advice folks who pose this kind of questions to post a "rollback method" for other users trying what they post. Personally, I can deal with these situations, but other users might have difficulties doing so.

EDIT: The error I got when trying to start the newly created serice (i.e. Error 1053: The service did not respond to the start or control request in a timely fashion) was precisely because it appears that Rainmeter doesn't implement the Windows Services API / ServiceMain, so even another software might not be of much help in such a case.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
Active Colors
Moderator
Posts: 1251
Joined: February 16th, 2012, 3:32 am
Location: Berlin, Germany

Re: Run Rainmeter as a Service

Post by Active Colors »

Well, since it is not possible to run it as a service, how about trying to hide the process itself from the eyes of task manager?
I have read about the ways to do that.
For example here is one of them https://kaimi.io/2012/09/process-hide-tool/
it is by a russian developer but you can use google translate, there are download buttons on the bottom for exe file and source.
What you need is the frost driver, you can find it as well by searching "frost sys driver" or some similar variation and load it into this tool.
User avatar
Yincognito
Rainmeter Sage
Posts: 7031
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Run Rainmeter as a Service

Post by Yincognito »

Normally, if Rainmeter worked as expected (yeah, I have some uncomfortable things to say about this scenario, in particular, but I'll abstain), this should work every time:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1
BackgroundMode=2
SolidColor=47,47,47,255
OnCloseAction=[!CommandMeasure MeasureRun "Run"]

---Measures---

[MeasureRun]
Measure=Plugin
Plugin=RunCommand
Program="C:\Program Files\Rainmeter\Rainmeter.exe"
Parameter=!LoadLayout "Test"

---Meters---

[MeterTest]
Meter=STRING
X=0
Y=0
FontFace=Consolas
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
FontSize=16
AntiAlias=1
Text="Test"
This assumes the above code is a "Test\Test.ini" skin in your skins folder and that you also saved the layout (called "Test" as well) with this skin loaded in your layouts folder. What this does is reload the "Test" layout every time the skin or Rainmeter is closed. The thing is, while this works no problem when unloading the skin, it should work every time when exiting Rainmeter, but it doesn't: in my case I must first unload the skin (and let it reload) 3 times and only then it will also reload when exiting Rainmeter from the skin's context menu. Even so, it seems that when exiting Rainmeter from the system tray, the process doesn't reload Rainmeter and the layout containing this skin again - although it should. Maybe it's about the delays involved in running the measure, I don't know.

Why I didn't use ["C:\Program Files\Rainmeter\Rainmeter.exe" !ActivateConfig "Test" "Test.ini"], you may ask? Simple: because they don't work. I thought it was the placement of quotes in the parameters at fault, so I tried various combinations. I don't recommend trying that yourself, as you might unwantedly create some folders in your Rainmeter installation folder, or have an error about writing to the Rainmeter folder, or even have 2 Rainmeters in system tray, LOL. I might be missing something here, but in my attempts I never managed to make this direct bang work when exiting Rainmeter. To make it work when unloading the skin is trivial, so it doesn't count.

Maybe others can get to the bottom of this, because I couldn't - and frnkly I became a bit annoyed by the fact that things that should work don't, i this case. :confused:

Bottom line is, assuming the above code is made to work in every test case scenario, the only thing required would be to protect the .INI file and the layout file, along with Rainmeter itself from unauthorized modification. There would be no need to run Rainmeter as a service at all, as Rainmeter and the skin would reload every time the user attemps to unload it or close Rainmeter.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
Yincognito
Rainmeter Sage
Posts: 7031
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Run Rainmeter as a Service

Post by Yincognito »

Ok, I'll take back some of the things I said, but while I found a way to make the code work in every test case scenario, it still feels it could have been done in a single bang (must have missed something in those attempts):

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1
BackgroundMode=2
SolidColor=47,47,47,255
OnCloseAction=["C:\Program Files\Rainmeter\Rainmeter.exe"][!LoadLayout "Test"]

---Meters---

[MeterTest]
Meter=STRING
X=0
Y=0
FontFace=Consolas
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
FontSize=16
AntiAlias=1
Text="Test"
So, it reloads Rainmeter and the desired layout every time the user attempts to unload either Rainmeter or the skin. If one can configure the Windows adminstrative policies to prevent the modification of the involved files and access to Task Manager or any other application that can kill Rainmeter "from outside", all good.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Run Rainmeter as a Service

Post by jsmorley »

I don't really follow.

This certainly works in a running skin:

LeftMouseUpAction=["C:\Program Files\Rainmeter\Rainmeter.exe" !ActivateConfig "Test" "Test.ini"]

or from a cmd.exe console:

"C:\Program Files\Rainmeter\Rainmeter.exe" !ActivateConfig "@Working" "Test.ini"

or from the Windows Run dialog:

"C:\Program Files\Rainmeter\Rainmeter.exe" !ActivateConfig "@Working" "Test.ini"

It won't work if Rainmeter is not already running. It's not intended to "start" Rainmeter.

Anyway, I'll step back out, since I disagree with the principle here. Rainmeter is envisioned and designed as an application that is under the complete control of the person sitting in front of the computer. There is no reasonable way, nor do we ever intend to support, any way of "locking down" Rainmeter, so it can be distributed by a company to its employees, in a way where each and every individual workstation doesn't have the ability to change anything and everything about the application.
User avatar
Yincognito
Rainmeter Sage
Posts: 7031
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Run Rainmeter as a Service

Post by Yincognito »

jsmorley wrote: August 11th, 2020, 12:27 pmIt won't work if Rainmeter is not already running. It's not intended to "start" Rainmeter.
Yeah, I thought it would though. :confused: Especially since the path to Rainmeter was a part of the bang. I guess this was the thing I was missing when trying the above - it makes sense now.
jsmorley wrote: August 11th, 2020, 12:27 pmAnyway, I'll step back out, since I disagree with the principle here. Rainmeter is envisioned and designed as an application that is under the complete control of the person sitting in front of the computer. There is no reasonable way, nor do we ever intend to support, any way of "locking down" Rainmeter, so it can be distributed by a company to its employees, in a way where each and every individual workstation doesn't have the ability to change anything and everything about the application.
I too disagree with it - giving control to the user is key. I was just trying to make the process work, and I didn't know why it didn't.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Run Rainmeter as a Service

Post by jsmorley »

Yincognito wrote: August 11th, 2020, 12:37 pm Yeah, I thought it would though. :confused: Especially since the path to Rainmeter was a part of the bang.
Rainmeter has the ability, put in back in the EARLIEST days, to be started with a defined, alternative location and name of "Rainmeter.ini", the file that controls pretty much everything. So when Rainmeter is started, it isn't looking for bangs on the command line. If there are ANY parameters at all on the command line when it is first started, those are treated as a location of that alternative Rainmeter.ini, and yeah, you can get some very strange behavior, since it will not only "look for" that alternative Rainmeter.ini, but if it isn't found, it will treat that as an order to start Rainmeter with a brand-new, user defined Rainmeter.ini, and that file, with a vanilla setup, will be created.

It gets particularly ugly, since that is going to create that file in the same folder as Rainmeter.exe, and when you have a "standard" installation, there won't be any Skins folder, and Rainmeter is just going to pitch a fit.

It's all a bit murky to me, since it hasn't really been used in like forever, it was originally designed back in the dawn of time when Rainmeter was closely integrated with Samurize. I recommend that command line parameters never be used unless Rainmeter is running, when the parameters will be passed to the running application, parsed, and executed.

At some point we should revisit this. I tend to agree that when command line parameters are passed to Rainmeter.exe, it should behave the same if Rainmeter is running, or not running. That entire "alternative" Rainmeter.ini deal is a pointless prehensile-tail, and only complicates that. At the most generous, this thing could perhaps be justified when there wasn't any concept of Layout, and you might want to load a different setup depending on some external factor. I can't see any point for it now.
User avatar
Yincognito
Rainmeter Sage
Posts: 7031
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Run Rainmeter as a Service

Post by Yincognito »

jsmorley wrote: August 11th, 2020, 12:44 pm Rainmeter has the ability, put in back in the EARLIEST days, to be started with a defined, alternative location and name of "Rainmeter.ini", the file that controls pretty much everything. So when Rainmeter is started, it isn't looking for bangs on the command line. If there are ANY parameters at all on the command line when it is first started, those are treated as a location of that alternative Rainmeter.ini, and yeah, you can get some very strange behavior, since it will not only "look for" that alternative Rainmeter.ini, but if it isn't found, it will treat that as an order to start Rainmeter with a brand-new, user defined Rainmeter.ini, and that file, with a vanilla setup, will be created.

It gets particularly ugly, since that is going to create that file in the same folder as Rainmeter.exe, and when you have a "standard" installation, there won't be any Skins folder, and Rainmeter is just going to pitch a fit.

It's all a bit murky to me, since it hasn't really been used in like forever, it was originally designed back in the dawn of time when Rainmeter was closely integrated with Samurize. I recommend that command line parameters never be used unless Rainmeter is running, when the parameters will be passed to the running application, parsed, and executed.

At some point we should revisit this. I tend to agree that when command line parameters are passed to Rainmeter.exe, it should behave the same if Rainmeter is running, or not running. That entire "alternative" Rainmeter.ini deal is a pointless prehensile-tail, and only complicates that. At the most generous, this thing could perhaps be justified when there wasn't any concept of Layout, and you might want to load a different setup depending on some external factor. I can't see any point for it now.
Yes, that was what probably happened. I was not in any way bothered by the fact that there were folders created in the Rainmeter installation folder by that, as that most likely was my fault placing the quotes in a certain way, when trying to make the thing work. In the end, I probably expected Rainmeter to behave just like any other program when a ["Program" "Parameter"] bang is executed, that is run the program itself, even if it wasn't already started. But then I realized there is no other way to instruct Rainmeter to do something from the command line other than placing the full path of it along with the bang parameters.

Just a bit of misunderstanding of the command line syntax vs Rainmeter's own bang syntax - it was easy to have that happening since the manual didn't imply that these bangs only work if Rainmeter is running (or I didn't look in the right places, maybe, having checked only the first paragraphs here and here). To further perpetuate this confusion, commands such as ["C:\Program Files\Rainmeter\Rainmeter.exe" !LoadLayout "Test"] that are explained here appeared to work even if Rainmeter isn't running, so I assumed the other such commands / bangs / whatever (like ["C:\Program Files\Rainmeter\Rainmeter.exe" !ActivateConfig "Test" "Test.ini"]) will too. :confused:
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth