It is currently February 29th, 2024, 3:02 pm

RainWake 1.1 - WakeOnLan Skin

Skins that control functions in Windows or Rainmeter
User avatar
KreAch3R
Posts: 608
Joined: February 7th, 2011, 7:27 pm
Location: Thessaloniki, GR

RainWake 1.1 - WakeOnLan Skin

Post by KreAch3R »

RainWake 1.1
Please check DeviantArt page for details. In short, RainWake is a WakeOnLan single click skin. It can be used to remotely open a computer, given that it has been configured correctly. On the Rainmeter developing side, it is my first time I write a .lua script. :) It is used to create the necessary wol .bat files. Also, the skin uses a .vbs file to completely hide the short appearance of the cmd window (making it a way to run an invisible cmd command). Lastly, you can insert the necessary information with InputText plugin, without messing with the skin's files.

PLEASE comment on my first try in .lua & critique my code.

Last but not least, this is an example skin; I don't like the look of it very much either. But I would love to see prettier skins.:D

Changelog:
v1.1: Implemented smurfier's code; added multiple hosts (up to 3)
v1.0: Initial Release
Last edited by KreAch3R on February 25th, 2012, 9:29 pm, edited 1 time in total.
Inactive, due to life changes. Send me a PM for any question.

Desktop DeviartArt
Image
User avatar
smurfier
Moderator
Posts: 1931
Joined: January 29th, 2010, 1:43 am
Location: Willmar, MN

Re: RainWake 1.0 - WakeOnLan Skin

Post by smurfier »

Here is my take on your lua file.

BTW: You retrieve but do not use the variables Bat and WoL.
GitHub | DeviantArt | Tumblr
This is the song that never ends. It just goes on and on my friends. Some people started singing it not knowing what it was, and they'll continue singing it forever just because . . .
User avatar
KreAch3R
Posts: 608
Joined: February 7th, 2011, 7:27 pm
Location: Thessaloniki, GR

Re: RainWake 1.0 - WakeOnLan Skin

Post by KreAch3R »

Oh! O.O I already found some ground breaking breathroughs for my infant .lua mind. Multiple "variable data" in one variable (Vars)? Ηow did you manage to narrow this down to a single line code? :)

Code: Select all

sMAC, _ = string.gsub(Vars[2],(string.find(Vars[2],'-') and '-' or ':'), '')
I understand that this:

Code: Select all

(string.find(Vars[2],'-')
searches Vars[2] for "-", but then why do we have to rewrite it as

Code: Select all

 and '-' or ':'
And what does this do?

Code: Select all

'')
As for the variables WoL and Bat, you are right. I used them in a previous version of the script but I forgot to scratch them out. Leaving them out will make the code look like this, I guess:

Code: Select all

function Initialize()
	Vars={'CURRENTPATH';'MAC';'IP';'Port'}
	for i=1,#Vars do Vars[i]=SKIN:GetVariable(Vars[i]) end

	if Vars[2]~='XX-XX-XX-XX-XX-XX' and Vars[3]~='0.0.0.0' and Vars[4]~='0' then

		sMAC, _ = string.gsub(Vars[2],(string.find(Vars[2],'-') and '-' or ':'), '')

		MyFile = io.open(Vars[1]..'Resources/Wolcmd/wol.bat' ,'w+')
		if MyFile then
			MyFile:write ('wolcmd '..sMAC..' '..Vars[3]..' 255.255.255.255 '..Vars[4])
		else
			print('Can\'t create file: wol.bat')
			return 'File Error'
		end
		MyFile:close()

		MyFile2 = io.open(Vars[1]..'Resources/Wolcmd/invisible.vbs' ,'w+')
		if MyFile2 then
			MyFile2:write ('Set WshShell = CreateObject("WScript.Shell") \n cmds=WshShell.RUN("""'..Vars[1]..'Resources/Wolcmd/wol.bat'..'""", 0, True) \n Set WshShell = Nothing')
		else
			print('Can\'t create file: invisible.vbs')
			return 'File Error'
		end
		MyFile2:close()
	else
		print("You should edit all RainWake fields")
	end

end
Inactive, due to life changes. Send me a PM for any question.

Desktop DeviartArt
Image
User avatar
smurfier
Moderator
Posts: 1931
Joined: January 29th, 2010, 1:43 am
Location: Willmar, MN

Re: RainWake 1.0 - WakeOnLan Skin

Post by smurfier »

string.find(Vars[2],'-') and '-' or ':'
This is basically the same as conditional?true:false
If the string contains '-' then use '-' else ':'
That was the difference you used in your original code.

Now, I believe we can actually skip this test altogether by using:
string.gsub(Vars[2],'[-:]', '')
What this should do is remove all instances of '-' or ':'

In your original code you had it substituting for "" which is the same as '', which I prefer.

Couple more changes:

Code: Select all

function Initialize()
	Vars={'CURRENTPATH';'MAC';'IP';'Port'}
	for i=1,#Vars do Vars[i]=SKIN:GetVariable(Vars[i]) end

	if Vars[2]~='XX-XX-XX-XX-XX-XX' and Vars[3]~='0.0.0.0' and Vars[6]~='0' then
		MyFile=io.open(Vars[1]..'Resources/Wolcmd/wol.bat','w+')
		if MyFile then
			MyFile:write('wolcmd '..string.gsub(Vars[2],'[-:]','')..' '..Vars[3]..' 255.255.255.255 '..Vars[4])
		else
			print('Can\'t create file: wol.bat')
			return 'File Error'
		end
		MyFile:close()

		MyFile2=io.open(Vars[1]..'Resources/Wolcmd/invisible.vbs','w+')
		if MyFile2 then
			MyFile2:write('Set WshShell = CreateObject("WScript.Shell") \n cmds=WshShell.RUN("""'..Vars[1]..'Resources/Wolcmd/wol.bat'..'""", 0, True) \n Set WshShell = Nothing')
		else
			print('Can\'t create file: invisible.vbs')
			return 'File Error'
		end
		MyFile2:close()
	else
		print('You should edit all RainWake fields')
	end

end
GitHub | DeviantArt | Tumblr
This is the song that never ends. It just goes on and on my friends. Some people started singing it not knowing what it was, and they'll continue singing it forever just because . . .
User avatar
KreAch3R
Posts: 608
Joined: February 7th, 2011, 7:27 pm
Location: Thessaloniki, GR

Re: RainWake 1.1 - WakeOnLan Skin

Post by KreAch3R »

Thanks for the latest code, smurfier, it's fully used into my skin now :) (note to other users: there's a small typo in the above code, Vars[6]~='0' should be Vars[4]~='0')

Other than that, I three skin variants and linked one to the other, so that I could create an easy way of "multiple" remote PC configurations. Given that I didn't want to spend any more time on this skin, it does it's job.
Inactive, due to life changes. Send me a PM for any question.

Desktop DeviartArt
Image
User avatar
Mordasius
Posts: 1165
Joined: January 22nd, 2011, 4:23 pm
Location: GMT +8

Re: RainWake 1.1 - WakeOnLan Skin

Post by Mordasius »

I found it was easier to input the PC Name, MAC, etc. if you change to FontSize=7 in [InputName], [InputMAC], etc.

Of course what I'd really like is to have something like this to switch off a remote computer so I can steal all the bandwidth on our LAN. :x
User avatar
KreAch3R
Posts: 608
Joined: February 7th, 2011, 7:27 pm
Location: Thessaloniki, GR

Re: RainWake 1.1 - WakeOnLan Skin

Post by KreAch3R »

Mordasius wrote:I found it was easier to input the PC Name, MAC, etc. if you change to FontSize=7 in [InputName], [InputMAC], etc.
Really? This is how mine looks with fontsize=7:


Perhaps I have made a mistake while creating the .rmskin file and the font didn't installed correctly? Roboto was installed on your machine?
Mordasius wrote:Of course what I'd really like is to have something like this to switch off a remote computer so I can steal all the bandwidth on our LAN. :x
Heh, I would like that, too. The cmd way of shutting down a remote PC requires authentication, as I understand. So an ugly cmd window will appear, I think. If anyone wants to tackle that, feel free.:) I mainly use PC Monitor or Teamviewer to shutdown my remote machines. :D
Inactive, due to life changes. Send me a PM for any question.

Desktop DeviartArt
Image
User avatar
Mordasius
Posts: 1165
Joined: January 22nd, 2011, 4:23 pm
Location: GMT +8

Re: RainWake 1.1 - WakeOnLan Skin

Post by Mordasius »

KreAch3R wrote:Really? This is how mine looks with fontsize=7:
Sorry, my bad. I had a custom DPI setting of 125% which affects the font size displayed when using the InputText plugin.
:oops:

Thanks for the tip about authentication. I'll have to sneak around when they're out to open TCP port 445 and check the 'Allow users to connect remotely to this computer' box. Mind you, I don't think it will be very long before they become suspicious.
User avatar
KreAch3R
Posts: 608
Joined: February 7th, 2011, 7:27 pm
Location: Thessaloniki, GR

Re: RainWake 1.1 - WakeOnLan Skin

Post by KreAch3R »

I didn't know custom DPI can do that. I would thought that it affects all font sizes. Good to know :)

If their PCs shutdown in the middle of their work, I believe they will be more than suspicious :p Good luck with LAN bandwidth dominating. :lol:
Inactive, due to life changes. Send me a PM for any question.

Desktop DeviartArt
Image