Hello Rainmeter Community ,
In early 2020, I spent a few months preparing or upgrading existing skins for a suit according to my need, so I have only low and basic rainmeter skills. Now, after almost a year off, I want to finish my suit.
I would like to have a button that can be used to connect / disconnect to my specific WiFi. I don't have administrator rights on this PC account.
At the moment I found two command scripts (* .bat files) which I can use without Admin rights, but I need two buttons to run the commands.
Is it possible to toggle between these two CMD scripts with a Rainmeter button? Every time I push the button it should change (execute) between CMD1 and CMD2. Is there a better solution available?
CMD script 1: netsh wlan connect name=myWLAN
CMD script 2: netsh wlan disconnect
Thanks for helping!
It is currently April 26th, 2024, 10:19 am
Toggle spezific WIFI Netwerk (on/off)
-
- Posts: 3
- Joined: April 30th, 2021, 7:07 pm
-
- Rainmeter Sage
- Posts: 2610
- Joined: March 23rd, 2015, 5:26 pm
Re: Toggle spezific WIFI Netwerk (on/off)
All you need to run the two commands you want are two RunCommand measures, and two String meters (for the buttons). Actually, any meter you can click on will work for the buttons (Image, Shape, etc.), but for this example we will stick with the basics.xxxLIONartxxx wrote: ↑April 30th, 2021, 7:54 pm Hello Rainmeter Community ,
In early 2020, I spent a few months preparing or upgrading existing skins for a suit according to my need, so I have only low and basic rainmeter skills. Now, after almost a year off, I want to finish my suit.
I would like to have a button that can be used to connect / disconnect to my specific WiFi. I don't have administrator rights on this PC account.
At the moment I found two command scripts (* .bat files) which I can use without Admin rights, but I need two buttons to run the commands.
Is it possible to toggle between these two CMD scripts with a Rainmeter button? Every time I push the button it should change (execute) between CMD1 and CMD2. Is there a better solution available?
CMD script 1: netsh wlan connect name=myWLAN
CMD script 2: netsh wlan disconnect
Thanks for helping!
Code: Select all
[Rainmeter]
AccurateText=1
DefaultWindowX=300R
DefaultWindowY=300
DynamicWindowSize=1
Update=1000
; ---------- measures ----------
[MeasureRunConnect]
Measure=Plugin
Plugin=RunCommand
Parameter="netsh wlan connect name=myWLAN"
OutputType=ANSI
State=Hide
Timeout=5000
[MeasureRunDisconnect]
Measure=Plugin
Plugin=RunCommand
Parameter="netsh wlan disconnect"
OutputType=ANSI
State=Hide
Timeout=5000
; ---------- meters ----------
[MeterConnect]
Meter=String
AntiAlias=1
FontColor=255,255,255
FontFace=Segoe UI
FontSize=12
StringAlign=CenterCenter
SolidColor=255,0,0
Text="Connect"
X=50
Y=10
W=100
H=24
LeftMouseUpAction=[!CommandMeasure MeasureRunConnect "Run"]
MouseOverAction=[!SetOption #CURRENTSECTION# InlineSetting "Weight | 700"][!UpdateMeter "#CURRENTSECTION#"][!Redraw]
MouseLeaveAction=[!SetOption #CURRENTSECTION# InlineSetting "Weight | 400"][!UpdateMeter "#CURRENTSECTION#"][!Redraw]
UpdateDivider=-1
[MeterDisconnect]
Meter=String
AntiAlias=1
FontColor=255,255,255
FontFace=Segoe UI
FontSize=12
StringAlign=CenterCenter
SolidColor=255,0,0
Text="Disconnect"
X=0r
Y=40r
W=100
H=24
LeftMouseUpAction=[!CommandMeasure MeasureRunDisconnect "Run"]
MouseOverAction=[!SetOption #CURRENTSECTION# InlineSetting "Weight | 700"][!UpdateMeter "#CURRENTSECTION#"][!Redraw]
MouseLeaveAction=[!SetOption #CURRENTSECTION# InlineSetting "Weight | 400"][!UpdateMeter "#CURRENTSECTION#"][!Redraw]
UpdateDivider=-1
-
- Posts: 1366
- Joined: September 7th, 2020, 2:24 pm
- Location: QLD, Australia
Re: Toggle spezific WIFI Netwerk (on/off)
You can also control the whole she-bang, with these-like Commands:
Code: Select all
[Variables]
State=1
[MeasureTurnOff]
Measure=Plugin
Plugin=RunCommand
Parameter=ipconfig /release
State=Hide
[MeasureTurnOn]
Measure=Plugin
Plugin=RunCommand
Parameter=ipconfig /renew
State=Hide
[MeasureInternet]
Measure=Plugin
Plugin=SysInfo
SysInfoType=INTERNET_CONNECTIVITY
Disabled=0
Substitute="^1$":"CONNECTED","^-1$":"OFF LINE"
RegExpSubstitute=1
[MeterConnectivity]
Meter=String
MeasureName=MeasureInternet
Fontsize=19
FontFace=Calibri
FontColor=220,220,220,255
AntiAlias=1
StringAlign=CenterCenter
x=20
y=20
Text=%1
RightMouseUpAction=[!CommandMeasure MeasureTurnOff "Run"][!UpdateMeter *][!Redraw]
LeftMouseUpAction=[!CommandMeasure MeasureTurnOn "Run"][!UpdateMeter *][!Redraw]
DynamicVariables=1
[MeasureToggle]
Measure=Calc
Formula=#State#
IfCondition=MeasureToggle=0
IfTrueAction=[!CommandMeasure MeasureTurnOff "Run"]
IfFalseAction=[!CommandMeasure MeasureTurnOn "Run"]
Disabled=1
UpdateDivider=-1
DynamicVariables=1
ƈǟռ'ȶ ʄɨӼ ɨȶ ɨʄ ɨȶ ǟɨռ'ȶ ɮʀօӄɛ - ʊռʟɛֆֆ ɨȶ ɨֆ ɨռ ƈօɖɛ.
-
- Posts: 3
- Joined: April 30th, 2021, 7:07 pm
Re: Toggle spezific WIFI Netwerk (on/off)
@ SilverAzide
Thanks for the quick answer and thanks for the tip with the RunCommand plugin. It's easier and looks better than running the * .bat file .
With the code from @CodeCode I now know how to make the internet status visible.
Like you said, I prefer the more complicated skin with a single button that toggles the connection on/off. But I still have no idea how to do it.
My idea was to do this with the IF condition as shown in the code from @CodeCode. But no success .
Since I've already wasted a couple of hours, I ask again for help. Many Thanks!
@CodeCode: Thanks for helping too. With your code I can apparently only toggle with the left and right mouse button (connect / disconnect Internet).
If possible, I want to toggle with the left mouse button only.
Thanks for the quick answer and thanks for the tip with the RunCommand plugin. It's easier and looks better than running the * .bat file .
With the code from @CodeCode I now know how to make the internet status visible.
Like you said, I prefer the more complicated skin with a single button that toggles the connection on/off. But I still have no idea how to do it.
My idea was to do this with the IF condition as shown in the code from @CodeCode. But no success .
Since I've already wasted a couple of hours, I ask again for help. Many Thanks!
@CodeCode: Thanks for helping too. With your code I can apparently only toggle with the left and right mouse button (connect / disconnect Internet).
If possible, I want to toggle with the left mouse button only.
-
- Rainmeter Sage
- Posts: 2610
- Joined: March 23rd, 2015, 5:26 pm
Re: Toggle spezific WIFI Netwerk (on/off)
It would help if you posted your code to show what you have so far, but I can extend the example I gave you.
There are many ways to handle the button that toggles the connection. You can have one button and write some fancy code to switch its functionality depending on your network state, or you can create two buttons that LOOK like one button. You then will just show whichever button you want and to the user it will appear as one toggle button. The second way is easier.
In this example, the [MeasureLAN] is testing for LAN connectivity and showing whichever button is needed depending on your network state. (There are fancier ways to do this without using IfCondition, but this is hopefully easier to understand.)
I should point out here that this example makes a lot of assumptions and won't even work in some cases, but you were asking about simply toggling one network connection on and off (your WiFi in this case). If your PC is plugged into a wired network, then this example code will probably not work. What you really need to do is determine which of your adapters is active, determine what type of adapter it is (ethernet or wifi), and then configure the skin accordingly. You can use the SysInfo plugin for doing all this.
There are many ways to handle the button that toggles the connection. You can have one button and write some fancy code to switch its functionality depending on your network state, or you can create two buttons that LOOK like one button. You then will just show whichever button you want and to the user it will appear as one toggle button. The second way is easier.
Code: Select all
[Rainmeter]
AccurateText=1
DefaultWindowX=300R
DefaultWindowY=300
DynamicWindowSize=1
Update=1000
; ---------- measures ----------
[MeasureRunConnect]
Measure=Plugin
Plugin=RunCommand
Parameter="netsh wlan connect name=myWLAN"
OutputType=ANSI
State=Hide
Timeout=5000
[MeasureRunDisconnect]
Measure=Plugin
Plugin=RunCommand
Parameter="netsh wlan disconnect"
OutputType=ANSI
State=Hide
Timeout=5000
[MeasureLAN]
Measure=Plugin
Plugin=SysInfo
SysInfoType=LAN_CONNECTIVITY
IfCondition=(MeasureLAN = 1)
IfTrueAction=[!HideMeter "MeterConnect"][!ShowMeter "MeterDisconnect"][!Redraw]
IfFalseAction=[!ShowMeter "MeterConnect"][!HideMeter "MeterDisconnect"][!Redraw]
; ---------- meters ----------
[MeterConnect]
Meter=String
AntiAlias=1
FontColor=255,255,255
FontFace=Segoe UI
FontSize=12
StringAlign=CenterCenter
SolidColor=255,0,0
Text="Connect"
X=50
Y=10
W=100
H=24
LeftMouseUpAction=[!CommandMeasure MeasureRunConnect "Run"]
MouseOverAction=[!SetOption #CURRENTSECTION# InlineSetting "Weight | 700"][!UpdateMeter "#CURRENTSECTION#"][!Redraw]
MouseLeaveAction=[!SetOption #CURRENTSECTION# InlineSetting "Weight | 400"][!UpdateMeter "#CURRENTSECTION#"][!Redraw]
Hidden=1
UpdateDivider=-1
[MeterDisconnect]
Meter=String
AntiAlias=1
FontColor=255,255,255
FontFace=Segoe UI
FontSize=12
StringAlign=CenterCenter
SolidColor=255,0,0
Text="Disconnect"
X=0r
Y=0r
W=100
H=24
LeftMouseUpAction=[!CommandMeasure MeasureRunDisconnect "Run"]
MouseOverAction=[!SetOption #CURRENTSECTION# InlineSetting "Weight | 700"][!UpdateMeter "#CURRENTSECTION#"][!Redraw]
MouseLeaveAction=[!SetOption #CURRENTSECTION# InlineSetting "Weight | 400"][!UpdateMeter "#CURRENTSECTION#"][!Redraw]
Hidden=1
UpdateDivider=-1
I should point out here that this example makes a lot of assumptions and won't even work in some cases, but you were asking about simply toggling one network connection on and off (your WiFi in this case). If your PC is plugged into a wired network, then this example code will probably not work. What you really need to do is determine which of your adapters is active, determine what type of adapter it is (ethernet or wifi), and then configure the skin accordingly. You can use the SysInfo plugin for doing all this.
-
- Posts: 3
- Joined: April 30th, 2021, 7:07 pm
Re: Toggle spezific WIFI Netwerk (on/off)
Many Thanks! It is now how I want it to be.
I don't use "wired connection" so it works perfectly as it is. The code looks simple, but I couldn't create this with my skills.
I can now proceed to design the button and when I'm done I'll upload the final version. Thanks again for preparing the code!
I don't use "wired connection" so it works perfectly as it is. The code looks simple, but I couldn't create this with my skills.
I can now proceed to design the button and when I'm done I'll upload the final version. Thanks again for preparing the code!