It is a good GUI script which checks if the new WINS IP is the same as the previous, and checks if the IP is kosher. You can't use 1.2.3.4.5.6 or 900.900.900.900 or 10.10, for example.
cls
# Load necessary assemblies for GUI
Add-Type -AssemblyName System.Windows.Forms
# Function to get current WINS IP
Function GetCurrentWINS {
$currentWinsInfo = netsh interface ip show config "Ethernet" | Select-String "WINS"
$currentWinsIP = if ($currentWinsInfo) { ($currentWinsInfo -split ":")[1].Trim() } else { "Not Set" }
return $currentWinsIP
}
# Function to validate IP address
Function Validate-IPAddress {
param (
[string]$IPAddress
)
return ([System.Net.IPAddress]::TryParse($IPAddress, [ref]0))
}
# Initial Old WINS IP
$oldWINS = GetCurrentWINS
# Create the main form
$form = New-Object System.Windows.Forms.Form
$form.Text = "Set WINS IP Address"
$form.Size = New-Object System.Drawing.Size(400, 250)
$form.StartPosition = "CenterScreen"
$form.BackColor = [System.Drawing.Color]::LightBlue
# Create a GroupBox for Old WINS IP
$groupOld = New-Object System.Windows.Forms.GroupBox
$groupOld.Text = "Old WINS IP for adapter `Ethernet`:"
$groupOld.Location = New-Object System.Drawing.Point(10, 10)
$groupOld.Size = New-Object System.Drawing.Size(370, 50)
$form.Controls.Add($groupOld)
# Create a label for Old WINS IP address
$labelOldWINS = New-Object System.Windows.Forms.Label
$labelOldWINS.Text = $oldWINS
$labelOldWINS.AutoSize = $true
$labelOldWINS.Location = New-Object System.Drawing.Point(10, 20)
$groupOld.Controls.Add($labelOldWINS)
# Create a text box for WINS IP address input
$textBoxWINS = New-Object System.Windows.Forms.TextBox
$textBoxWINS.Location = New-Object System.Drawing.Point(10, 70)
$textBoxWINS.Size = New-Object System.Drawing.Size(260, 20)
$textBoxWINS.Text = GetCurrentWINS
$textBoxWINS.Add_KeyDown({
if ($_.KeyCode -eq 'Enter') {
$buttonSet.PerformClick()
}
})
$form.Controls.Add($textBoxWINS)
# Create a GroupBox for New WINS IP
$groupNew = New-Object System.Windows.Forms.GroupBox
$groupNew.Text = "New WINS IP for adapter `Ethernet`:"
$groupNew.Location = New-Object System.Drawing.Point(10, 100)
$groupNew.Size = New-Object System.Drawing.Size(370, 50)
$form.Controls.Add($groupNew)
# Create a label for displaying the new WINS IP
$labelNewWINS = New-Object System.Windows.Forms.Label
$labelNewWINS.AutoSize = $true
$labelNewWINS.Location = New-Object System.Drawing.Point(10, 20)
$groupNew.Controls.Add($labelNewWINS)
# Create a button to set the WINS IP address
$buttonSet = New-Object System.Windows.Forms.Button
$buttonSet.Text = "Set WINS IP"
$buttonSet.Location = New-Object System.Drawing.Point(280, 70)
$buttonSet.Add_Click({
$newWINS = $textBoxWINS.Text
if (Validate-IPAddress $newWINS) {
if ($newWINS -eq $oldWINS) {
$labelNewWINS.Text = "IP is the same as Old WINS. No changes made."
} else {
netsh interface ip set wins "Ethernet" static $newWINS
$labelNewWINS.Text = $newWINS
$oldWINS = $newWINS
}
} else {
$labelNewWINS.Text = "Invalid IP address. No changes made."
}
})
$form.Controls.Add($buttonSet)
# Create an Exit button
$buttonExit = New-Object System.Windows.Forms.Button
$buttonExit.Text = "Exit"
$buttonExit.Location = New-Object System.Drawing.Point(280, 160)
$buttonExit.Add_Click({
$form.Close()
})
$form.Controls.Add($buttonExit)
# Show the form
$form.ShowDialog()