Wednesday, 10 August 2011

Script to enable or disable proxy with GUI

[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null
[System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") | Out-Null

Function ProxyEnable{

set-itemproperty -path "HKLM:\software\microsoft\windows\currentversion\internet settings" -name proxyenable -value 1 -type dword
}

Function ProxyDisable{

set-itemproperty -path "HKLM:\software\microsoft\windows\currentversion\internet settings" -name proxyenable -value 0 -type dword
}

$Form = New-Object System.Windows.Forms.Form
$Form.width = 170
$Form.height = 100
$Form.Text = "Proxy Settings"
$Form.maximumsize = New-Object System.Drawing.Size(170,100)
$Form.startposition = "centerscreen"
$Form.KeyPreview = $True
$Form.Add_KeyDown({if ($_.KeyCode -eq "Enter") {}})
$Form.Add_KeyDown({if ($_.KeyCode -eq "Escape")
    {$Form.Close()}})
   
$EnableButton = new-object System.Windows.Forms.Button
$EnableButton.Location = new-object System.Drawing.Size(1,1)
$EnableButton.Size = new-object System.Drawing.Size(80,74)
$EnableButton.Text = "Enable"
$EnableButton.Add_Click({ProxyEnable})

$DisableButton = new-object System.Windows.Forms.Button
$DisableButton.Location = new-object System.Drawing.Size(82,1)
$DisableButton.Size = new-object System.Drawing.Size(80,74)
$DisableButton.Text = "Disable"
$DisableButton.Add_Click({ProxyDisable})
   


$Form.Controls.Add($EnableButton)
$Form.Controls.Add($DisableButton)
$Form.Add_Shown({$Form.Activate()})
$Form.ShowDialog()

No comments:

Post a Comment