It is currently March 29th, 2024, 12:09 pm

When you think you really need to learn how to use Powershell

Get help with creating, editing & fixing problems with skins
User avatar
LGP123
Posts: 60
Joined: November 5th, 2016, 12:15 pm

When you think you really need to learn how to use Powershell

Post by LGP123 »

Ok so I ran into an issue (again) with encoding.
SO basically I want for a skin to be able to retrieve Recycle bin's total size (so how much can the bin contain). To do this, I run reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\BitBucket\Volume" /s.
The problem is that there are issues with the encoding (still in random applocales :3). So to fix it I tried to use powershell (as SilverAzide told me for a similar issue). So I came up with this :

Code: Select all

[MeaRunCommand]
Measure=Plugin
Plugin=RunCommand
Program=powershell.exe
Parameter=[Console]::OutputEncoding = [System.Text.Encoding]::Unicode; reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\BitBucket\Volume" /s
FinishAction=!log [MeaRunCommand]
The issue here is that even If I try to change the [System.Text.Encoding]::Unicode to other encodings like UTF8, It still output nonsense. I'm really, really bad at working with powershell but I really think that that should work.
I even tried to output the encoding info right after assigning unicode (so by doing this [Console]::OutputEncoding = [System.Text.Encoding]::Unicode;[Console]::OutputEncoding>output.txt; reg query [...] and it is encoded like I want, so it should be encoded like I want for the reg query. (and yes outputing the reg query in a file by doing so reg query [...] /s > Output.txt does output it correctly).

So I'd like a fix that would output my reg query correctly as the string value, that wouldn't be a mess like this :
1.png
and yeah, I really need to learn how to use powershell since microsoft is slowly making cmd dissapear :(
You do not have the required permissions to view the files attached to this post.
User avatar
SilverAzide
Rainmeter Sage
Posts: 2588
Joined: March 23rd, 2015, 5:26 pm

Re: When you think you really need to learn how to use Powershell

Post by SilverAzide »

Your PowerShell parameters are incorrect. You need to do this:

Code: Select all

Parameter="-NoProfile -ExecutionPolicy Bypass -NonInteractive -Command "...your stuff goes in here...""
Pay close attention to the quotes, as well.

You can test your command first by simply opening a command prompt and entering:
C:\> powershell -NoProfile -ExecutionPolicy Bypass -NonInteractive -Command "...your stuff goes in here..."
Gadgets Wiki GitHub More Gadgets...
User avatar
LGP123
Posts: 60
Joined: November 5th, 2016, 12:15 pm

Re: When you think you really need to learn how to use Powershell

Post by LGP123 »

SilverAzide wrote:Your PowerShell parameters are incorrect. You need to do this:

Code: Select all

Parameter="-NoProfile -ExecutionPolicy Bypass -NonInteractive -Command "...your stuff goes in here...""
Pay close attention to the quotes, as well.
Parameter="-NoProfile -ExecutionPolicy Bypass -NonInteractive -Command "[Console]::OutputEncoding = [System.Text.Encoding]::Unicode; reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\BitBucket\Volume" /s"" still doesn't work.
SilverAzide wrote:You can test your command first by simply opening a command prompt and entering:
C:\> powershell -NoProfile -ExecutionPolicy Bypass -NonInteractive -Command "...your stuff goes in here..."
I did and it worked :
Powershell
1.png
Cmd
2.PNG
You do not have the required permissions to view the files attached to this post.
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: When you think you really need to learn how to use Powershell

Post by balala »

LGP123 wrote:I did and it worked :
I'm surprised, because in addition to SilverAzide's reply, I think there an OutputType=ANSI option would also be needed to be add to the [MeaRunCommand] plugin measure.
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: When you think you really need to learn how to use Powershell

Post by balala »

LGP123 wrote:Parameter="-NoProfile -ExecutionPolicy Bypass -NonInteractive -Command "[Console]::OutputEncoding = [System.Text.Encoding]::Unicode; reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\BitBucket\Volume" /s"" still doesn't work.
Sorry, I misunderstood you. Here is the fix:

Code: Select all

[MeaRunCommand]
Measure=Plugin
Plugin=RunCommand
Program=powershell.exe
Parameter=-NoProfile -ExecutionPolicy Bypass -NonInteractive -Command "reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\BitBucket\Volume" /s
OutputType=ANSI
FinishAction=!log [MeaRunCommand]
Two further comments:
User avatar
LGP123
Posts: 60
Joined: November 5th, 2016, 12:15 pm

Re: When you think you really need to learn how to use Powershell

Post by LGP123 »

balala wrote:I'm surprised, because in addition to SilverAzide's reply, I think there an OutputType=ANSI option would also be needed to be add to the [MeaRunCommand] plugin measure.
Omg it finally worked (using UTF8 instead of ANSI). I totaly forgot that there was the OutputType option.

Thanks really much both of you :)
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: When you think you really need to learn how to use Powershell

Post by balala »

LGP123 wrote:Omg it finally worked (using UTF8 instead of ANSI).
If you're talking here about the encoding of the skin's file, well ANSI also works. I have it encoded so and perfectly works.
User avatar
LGP123
Posts: 60
Joined: November 5th, 2016, 12:15 pm

Re: When you think you really need to learn how to use Powershell

Post by LGP123 »

balala wrote:If you're talking here about the encoding of the skin's file, well ANSI also works. I have it encoded so and perfectly works.
No i used OutputType=UTF8 instead of OutputType=ANSI ;-)
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: When you think you really need to learn how to use Powershell

Post by balala »

LGP123 wrote:No i used OutputType=UTF8 instead of OutputType=ANSI ;-)
Oh, understood.
Ok, I'm glad if you got it working as wanted.