It is currently April 19th, 2024, 9:29 am

Focus-stealing problem launching VBS

Get help with creating, editing & fixing problems with skins
User avatar
Nightblade
Posts: 20
Joined: August 21st, 2012, 5:17 am

Focus-stealing problem launching VBS

Post by Nightblade »

For approximately the last 3 months a skin has been "focus stealing" when it does its data fetch every 20 minutes, causing games running in full-screen mode to "alt-tab" to the desktop for seemingly no reason.

I suspect the problem is related to this line that calls a VB script with two arguments:

Code: Select all

IfEqualAction=[ "#@#Scripts\ABB-Usage.vbs" "#CURRENTCONFIG#" "#CURRENTFILE#" ]
The skin can be found here https://github.com/DavidFW1960/Aussie-Broadband-Usage-Meter but as it's designed for users of Aussie Broadband (ABB) I'm unsure if it's possible to reproduce the problem for non-customers.

I thought I had found a fix (enclosing the script and arguments in triple-double-quotes), but as it turned out I simply wasn't testing correctly. The recent activity on this GitHub repo reflects this.

Rainmeter 4.3.1.3321 (64-bit).
Last edited by Nightblade on August 6th, 2020, 2:39 am, edited 1 time in total.
mak_kawa
Posts: 908
Joined: December 30th, 2015, 9:47 am

Re: Focus "stealing"

Post by mak_kawa »

Hi Nightblade

I too have a skin which calls a VBS, but I haven't noticed any "focus stealing". I am not sure why, but... what if you call the VBS via RunCommand plugin? Like as;

Code: Select all

IfEqualAction=[!CommandMeasure RunVBS "Run"]

[RunVBS]
Measure=Plugin
Plugin=RunCommand
Parameter="#@#Scripts\ABB-Usage.vbs" "#CURRENTCONFIG#" "#CURRENTFILE#"
User avatar
Nightblade
Posts: 20
Joined: August 21st, 2012, 5:17 am

Re: Focus "stealing"

Post by Nightblade »

Hi mak_kawa,

Thanks for the suggestion. I tried with your code, however it doesn't seem to launch the VBS at all.

Nighty
mak_kawa
Posts: 908
Joined: December 30th, 2015, 9:47 am

Re: Focus "stealing"

Post by mak_kawa »

Hi Nightblade

Ah... how about Parameter="#@#Scripts\ABB-Usage.vbs #CURRENTCONFIG# #CURRENTFILE#"?

Or... if your skin path doesn't include spaces, how about Parameter=#@#Scripts\ABB-Usage.vbs #CURRENTCONFIG# #CURRENTFILE#??

BTW, my VBS works with this;

Code: Select all

[Variables]
Drive=G:
VbsPath="#CurrentPath#DriveInfo_BdDvd.vbs #Drive# #CurrentPath#Total_Space_BdDvd.txt"

[CommandVBS]
Measure=Plugin
Plugin=RunCommand
Parameter=#VbsPath#
Of course, my #CurrentPath# does not include spaces.

Sorry, if I am wrong at all...
User avatar
Yincognito
Rainmeter Sage
Posts: 7125
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Focus "stealing"

Post by Yincognito »

Nightblade wrote: August 5th, 2020, 6:17 am For approximately the last 3 months a skin has been "focus stealing" when it does its data fetch every 20 minutes, causing games running in full-screen mode to "alt-tab" to the desktop for seemingly no reason.

I suspect the problem is related to this line that calls a VB script with two arguments:

Code: Select all

IfEqualAction=[ "#@#Scripts\ABB-Usage.vbs" "#CURRENTCONFIG#" "#CURRENTFILE#" ]
The skin can be found here https://github.com/DavidFW1960/Aussie-Broadband-Usage-Meter but as it's designed for users of Aussie Broadband (ABB) I'm unsure if it's possible to reproduce the problem for non-customers.

I thought I had found a fix (enclosing the script and arguments in triple-double-quotes), but as it turned out I simply wasn't testing correctly. The recent activity on this GitHub repo reflects this.

Rainmeter 4.3.1.3321 (64-bit).
Maybe you could try running that script through RunCommand instead of doing it directly, while setting the RunCommand measure's State option to Hide and see if it helps...

If it's the script itself that's stealing focus, this should solve it, in theory. If there's something else in the script code that does that... well, it depends on what that thing is.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
Yincognito
Rainmeter Sage
Posts: 7125
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Focus "stealing"

Post by Yincognito »

Nightblade wrote: August 5th, 2020, 6:17 am

Code: Select all

IfEqualAction=[ "#@#Scripts\ABB-Usage.vbs" "#CURRENTCONFIG#" "#CURRENTFILE#" ]
mak_kawa wrote: August 5th, 2020, 12:37 pm Hi Nightblade

Ah... how about Parameter="#@#Scripts\ABB-Usage.vbs #CURRENTCONFIG# #CURRENTFILE#"?
The skin appears to be running the script directly, without RunCommand.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
Yincognito
Rainmeter Sage
Posts: 7125
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Focus "stealing"

Post by Yincognito »

For example, try this skin to understand the difference in code and expected behavior:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

---Measures---

[MeasureRunHidden]
Measure=Plugin
Plugin=RunCommand
Parameter=cscript.exe #@#Scripts\HelloWorld.vbs
State=Hide
OutputType=ANSI

---Meters---

[MeterRunHidden]
Meter=String
FontSize=16
FontFace=Consolas
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
Y=0R
AntiAlias=1
Text=Click to Run using RunCommand - hidden
LeftMouseUpAction=[!CommandMeasure MeasureRunHidden "Run"]

[MeterRunDirectly]
Meter=String
FontSize=16
FontFace=Consolas
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
Y=0R
AntiAlias=1
Text=Click to Run directly - briefly visible
LeftMouseUpAction=["cscript.exe" "#@#Scripts\HelloWorld.vbs"]
This assumes you have a HelloWorld.vbs file the above skin's Resources folder, with the following contents:

Code: Select all

Wscript.Echo "Hello, World!"
So, basicaly, what you have now is a measure that does what [MeterRunDirectly] does in the LeftMouseUpAction option (albeit based on a condition and such). You'd need to create a RunCommand measure (see the link in my previous reply for details) like the above [MeasureRunHidden] that does pretty much the same thing but hidden (while taking care to use the same arguments in the Parameter option, as in the original code), and of course to replace the line that calls the VB script with something similar to what the LeftMouseUpAction option from [MeasureRunHidden] contains. Then, try the new code and hope it would work (which it will, if the focus issue is because of the script execution itself, and not because of some other thing hidden in the script code).

P.S. I used cscript.exe in this scenario only to force a console / STDOUT output instead of a Windows message box when using the default wscript.exe handler for the .vbs extension. It is there for demonstration purposes only, probably not required in your scenario.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
Nightblade
Posts: 20
Joined: August 21st, 2012, 5:17 am

Re: Focus "stealing"

Post by Nightblade »

Hi mak_kawa ,
mak_kawa wrote: August 5th, 2020, 12:37 pm Ah... how about Parameter="#@#Scripts\ABB-Usage.vbs #CURRENTCONFIG# #CURRENTFILE#"?

Or... if your skin path doesn't include spaces, how about Parameter=#@#Scripts\ABB-Usage.vbs #CURRENTCONFIG# #CURRENTFILE#??
Both of those combined with your code further up do indeed run the VBS, but sadly don't fix the focus-stealing issue.
User avatar
Nightblade
Posts: 20
Joined: August 21st, 2012, 5:17 am

Re: Focus "stealing"

Post by Nightblade »

Yincognito wrote: August 5th, 2020, 12:50 pm State=Hide
Doesn't help with focus-stealing sadly.

Code: Select all

[RunVBS]
Measure=Plugin
Plugin=RunCommand
State=Hide
Parameter=#@#Scripts\ABB-Usage.vbs #CURRENTCONFIG# #CURRENTFILE#
Edit: The VBS has no output other than MsgBox for errors. Running it via Task Scheduler does not steal focus.
User avatar
deflore08
Posts: 209
Joined: July 12th, 2020, 7:47 am
Location: Ada, Garden City

Re: Focus-stealing problem launching VBS

Post by deflore08 »

I checked RunCommand with hidden state, and yes, fullscreen app loses focus. I think it is not important what we exactly call, vbs script or just .bat, if they have any output or maybe even not.. I think first Windows tries to create a window with for stdout, then plugin "kils" this window. It happens fast, but happens. Sure, i may be wrong, but i feel it as i wrote. I quess, we should ask Brian how do it really works. Year ago i tried to find solution for a thing like this , but i didn't.. if you will, let us know please. =)
Image * Image * Image * Image