Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
$file = "$PWD\desktop.ini"
$TestFile = Test-Path $file -PathType leaf
if (!($TestFile))
{
$Shell = New-Object -ComObject "WScript.Shell"
$Button = $Shell.Popup("First you have to add a tag", 0, "Warning", 0)
exit
}
$form = New-object Windows.Forms.Form
$label = New-Object Windows.Forms.Label
$textbox = New-Object Windows.Forms.TextBox
$ok_button = New-Object Windows.Forms.Button
# $untag_button = New-Object Windows.Forms.Button
$form.StartPosition = 'CenterScreen'
$form.Size = New-Object Drawing.Size(240,150)
$form.Text = "Test"
$form.FormBorderStyle = "FixedDialog"
$form.MaximizeBox = $false
$form.MinimizeBox = $false
$form.AcceptButton = $ok_button
$label.Location = New-Object Drawing.Point(20,20)
$label.Size = New-Object Drawing.Size(180,23)
$label.Text = "Write something"
$textbox.Location = New-Object Drawing.Point(20,43)
$textbox.Size = New-Object Drawing.Size(180,23)
$ok_button.Location = New-Object Drawing.Point(160,76)
$ok_button.Size = New-Object Drawing.Size(50,23)
$ok_button.Text = "OK"
$ok_button.DialogResult = "OK"
$ok_button.Add_Click({$form.Close()})
# $untag_button.Location = New-Object Drawing.Point(90,76)
# $untag_button.Size = New-Object Drawing.Size(60,23)
# $untag_button.Text = "UNTAG"
# $untag_button.Add_Click({$textbox.Text = " "; $form.Close()})
$form.Controls.Add($label)
$form.Controls.Add($textbox)
$form.Controls.Add($ok_button)
# $form.Controls.Add($untag_button)
$result = $form.ShowDialog()
if ($result -eq [System.Windows.Forms.DialogResult]::OK)
{
$x = $textBox.Text
$checkline = (Get-Content $file)[2]
if ($x)
{
# ESCRIBIÓ ALGO
$line3 = (Get-Content $file)[2]
$comment = "InfoTip=$x"
if ($line3) {
# NO ESTÁ VACIA LA LINEA 3
$content = Get-Content -Path $file
$content[3] = $comment
$content | Set-Content -Path $file
$Shell = New-Object -ComObject "WScript.Shell"
$Button = $Shell.Popup("AQUI 1", 0, "Warning", 0)
}else {
# SI ESTÁ VACIA LA LINEA 3
'[.ShellClassInfo]' | Add-Content $file
$comment | Add-Content $file
$Shell = New-Object -ComObject "WScript.Shell"
$Button = $Shell.Popup("AQUI 3", 0, "Warning", 0)
}
}
else
{
# NO ESCRIBIÓ NADA
$Shell = New-Object -ComObject "WScript.Shell"
$Button = $Shell.Popup("Nothing was typed", 0, "Warning", 0)
}
}