パーソナルスキルレベルのために働いていない)(トリムクリップボード。はPSとのライセンスキーツール
問題: 私の出力は常に、文字列の先頭と末尾にスペースが入ります。私はtrim()、trimstart()などを試しています。それまでのところ何も働いていません。スペースはクリップボードのキーで保存されるので、あまり気にならないでしょう。機能が役に立たない、または少なくとも面倒です。
問題を特定するためのコードにいくつかの表記を示しました。
コード(結果は同様以下である):
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
[void][reflection.assembly]::Load("System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
#Obtain Windows 10 Key
$License = wmic path SoftwareLicensingService get OA3xOriginalProductKey
# FAULT - Used to trim key
$Result = $License.Trim("OA3xOriginalProductKey")
#Used to isolate the spaces in the result. Attempt to see if the spaces occur after the trim, or during the trim.
#The spaces are within the "|" rather than outside of the "|" - meaning that the Trim() is not working properly.
#PLEASE HELP!
$Result = "|" + $Result.Trim() + "|"
#Used to copy key to clipboard
$Result | clip.exe
$form = New-Object System.Windows.Forms.Form
$form.Text = "KeySniffer 1.0"
$form.Size = New-Object System.Drawing.Size(280,140)
$form.StartPosition = "CenterScreen"
$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Point(30,70)
$OKButton.Size = New-Object System.Drawing.Size(60,23)
$OKButton.Text = "OK"
$OKButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
$form.AcceptButton = $OKButton
$form.Controls.Add($OKButton)
$label = New-Object System.Windows.Forms.Label
$label.Location = New-Object System.Drawing.Point(10,20)
$label.Size = New-Object System.Drawing.Size(280,20)
$label.Text = "Key has been copied to clipboard"
$form.Controls.Add($label)
$textBox = New-Object System.Windows.Forms.TextBox
#Put a trim here as a desperate swing in the dark
#The "-" indicate that the spaces occur within the "$Result"
$textBox.Text = "-" + $Result.Trim() + "-"
$textBox.Location = New-Object System.Drawing.Point(10,40)
$textBox.Size = New-Object System.Drawing.Size(200,20)
$form.Controls.Add($textBox)
$form.Topmost = $True
$form.Add_Shown({$textBox.Select()})
$result = $form.ShowDialog()
if ($result -eq [System.Windows.Forms.DialogResult]::OK)
{
$x = $textBox.Text
$x
}
結果:
-| ****-*****-*****-*****-***** |-
を行ってする必要があります
は、あなたは彼らがスペース文字であることを確認していますか? '-'や' | 'を実際の文字に追加する代わりに' $ Result.ToCharArray()| %{"'$ _' = $([System.Convert] :: ToUInt32($ _))"} ' – xXhRQ8sD2L7Z