Menu

Virtual Geek

Tales from real IT system administrators world and non-production environment

Microsoft Powershell GUI: Change Internet Options connections Lan settings proxy server grayed out

Powershell winform wpf mix gui, graphical interface, change registry proxy settings hack internet option connections tab enable proxy

One of my friend wanted a small proxy settings hack tool which I created using Powershell script, it is very small tool and helps to change proxy server settings, It can changed when Internet Options >> Connections tab is either missing or Lan settings button is disabled, and you still want to change proxy settings. Basically this graphical powershell script make changes in the Registry. So registry modification must be enabled for this.

microsoft windows Powershell Internet Options Connections tab, Lab Settings, Proxy Server, VPN connection, lan proxy address.png

After launching script looks like below. It shows the current proxy configuration, Settings can be changed via typing new proxy server and proxy port and pressing Change Proxy button. Once Setting is refreshed, you can see the results. To build this GUI, I have used Powershell Studio.

microsoft powershell wpf forms change internet proxy settings, connection tab enable hack, powershell hack, registry

Basically this script Enable or Disable and changes proxy server dword values under registry path  HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings. Below dword values need to change the behavior of Lan settings >> proxy.

ProxyEnable = 1  #1 = enabled & 0 = Disabled
ProxyServer = 'OldProxyServer:808'

This script can be downloaded from here, It is also available on github.com.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<#
    .NOTES
    --------------------------------------------------------------------------------
     Code generated by:  Visual Studio 2015
     Created on:         4/19/2018 4:57 AM
     Generated by:       http://vcloud-lab.com
     Written by:         Kunal Udapi
     Tested on:          Windows 10
                         Windows 2016 Server
    --------------------------------------------------------------------------------
    .DESCRIPTION
        GUI script generated using Visual Studio 2015
#>

Add-Type -AssemblyName PresentationFramework

$RawXamlForm = @"
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        Title="Configure Proxy Server" Height="201" Width="525" ResizeMode="NoResize" Topmost="True" WindowStyle="none">
    <Window.Background>
        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
            <GradientStop Color="Black" Offset="0"/>
            <GradientStop Color="#FF4E7645" Offset="1"/>
        </LinearGradientBrush>
    </Window.Background>
    <Grid>
        <Label x:Name="CurrentProxyLabel" Content="Current Internet Proxy configuration" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="225" Foreground="White" FontStyle="Italic" FontWeight="Bold"/>
        <Label x:Name="CProxyStatusLabel" HorizontalAlignment="Left" Margin="235,10,0,0" VerticalAlignment="Top" Width="140" Foreground="#FFFF0C00" HorizontalContentAlignment="Right" Height="26"/>
        <Label x:Name="UrlLabel" Content="http://vcloud-lab.com" HorizontalAlignment="Left" Margin="248,159,0,0" VerticalAlignment="Top" Width="127" Foreground="White"/>
        <TextBox x:Name="CProxyServerBox" HorizontalAlignment="Left" Height="23" Margin="10,36,0,0" TextWrapping="Wrap" Text="Current Proxy Server" VerticalAlignment="Top" Width="270" Background="#FF3C4632" Foreground="White" IsReadOnly="True"/>
        <TextBox x:Name="CProxyPortBox" HorizontalAlignment="Left" Height="23" Margin="285,36,0,0" TextWrapping="Wrap" Text="Port" VerticalAlignment="Top" Width="90" Background="#FF3C4632" Foreground="White" IsReadOnly="True"/>
        <Button x:Name="RefreshB" Content="Refresh" HorizontalAlignment="Left" Margin="285,64,0,0" VerticalAlignment="Top" Width="90" Height="24"/>
        <Label x:Name="NewProxyLabel" Content="Change new Internet Proxy server and port below" HorizontalAlignment="Left" Margin="10,82,0,0" VerticalAlignment="Top" Width="440" Foreground="White" FontWeight="Bold" FontSize="14"/>
        <Label x:Name="NewProxyServerlabel" Content="New Proxy Server" HorizontalAlignment="Left" Margin="10,105,0,0" VerticalAlignment="Top" Width="125" Foreground="White" FontStyle="Italic"/>
        <Label x:Name="NewProxyPortlabel" Content="New Proxy Port" HorizontalAlignment="Left" Margin="280,105,0,0" VerticalAlignment="Top" Width="95" Foreground="White" FontStyle="Italic"/>
        <TextBox x:Name="ChangeProxyServer" Text='Type Valid Proxy server and Port no' HorizontalAlignment="Left" Height="23" Margin="10,131,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="270" Background="#FFB4DC5A" Foreground="Black" IsReadOnly="True"/>
        <TextBox x:Name="ChangeProxyPort" Text='808' HorizontalAlignment="Left" Height="23" Margin="285,131,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="90" Background="#FFB4DC5A" Foreground="Black" IsReadOnly="True"/>
        <Button x:Name="ChangeProxyB" Content="Change Proxy" HorizontalAlignment="Left" Margin="380,131,0,0" VerticalAlignment="Top" Width="127" Height="24" IsEnabled="False"/>
        <Image x:Name="LogoImage" HorizontalAlignment="Left" Height="101" Margin="388,15,0,0" VerticalAlignment="Top" Width="119"/>
        <CheckBox x:Name="EnableProxy" Content="Enable or Disable Proxy" HorizontalAlignment="Left" Margin="15,164,0,0" VerticalAlignment="Top" Width="150" Foreground="White" IsChecked="True"/>
        <Button x:Name="CloseB" Content="Close Utility" HorizontalAlignment="Left" Margin="380,161,0,0" VerticalAlignment="Top" Width="127" Height="24"/>
    </Grid>
</Window>
"@

$RawXamlForm = $RawXamlForm -replace 'x:', ''
[xml]$XamlForm = $RawXamlForm
$XMLReader = (New-Object System.Xml.XmlNodeReader $XamlForm)
$ChangeProxyForm = [Windows.Markup.XamlReader]::Load($XMLReader)
$XamlForm.SelectNodes("//*[@Name]") | Foreach-Object {Set-Variable -Name ($_.Name) -Value $ChangeProxyForm.FindName($_.Name)}

#'HKEY_USERS\S-1-5-21-3215338630-3058045017-314744653-1000\Software\Microsoft\Windows\CurrentVersion\Internet Settings'
#'HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings'
#'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings'

function Disable-Change {
    $ChangeProxyServer.IsReadOnly = $true
    $ChangeProxyPort.IsReadOnly = $true
    $ChangeProxyB.IsEnabled = $false
    $EnableProxy.IsEnabled = $false
}
function Enable-Change {
    $ChangeProxyServer.IsReadOnly = $false
    $ChangeProxyPort.IsReadOnly = $false
    $ChangeProxyB.IsEnabled = $true
    $EnableProxy.IsEnabled = $true
}

function Get-CurrentProxyInfo {
    try {
        $Script:CurrentInternetProxyInfo = Get-ItemProperty -Path $RegKey -ErrorAction Stop
        $CurrentProxyInfo = $Script:CurrentInternetProxyInfo.ProxyServer -split ':'
        Switch ($Script:CurrentInternetProxyInfo.ProxyEnable) {
           0 {$CProxyStatusLabel.Content = 'Proxy is Disabled'}
           1 {$CProxyStatusLabel.Content = 'Proxy is Enabled'}
           default {$CProxyStatusLabel.Content = 'Unknown Setting'}
        }
        $CProxyServerBox.Text = $CurrentProxyInfo[0]
        $CProxyPortBox.Text = $CurrentProxyInfo[1]
        Enable-Change
    }
    catch {
        $CProxyServerBox.Text = "You don't have permissions to read registry"
        Disable-Change
    }
}
Function Set-NewProxyConfiguration {
    if ($ChangeProxyPort.Text -match '\d' -and $ChangeProxyServer.Text -ne 'Type Valid Proxy server and Port no') {
        try {
            Switch ($EnableProxy.IsChecked) {
                True {Set-ItemProperty -Path $RegKey -Name ProxyEnable -Value 1 -ErrorAction Stop}
                False {Set-ItemProperty -Path $RegKey -Name ProxyEnable -Value 0 -ErrorAction Stop}
            }
            $NewProxy = "{0}:{1}" -f $ChangeProxyServer.Text, $ChangeProxyPort.Text
            Set-ItemProperty -Path $RegKey -Name ProxyServer -Value $NewProxy -ErrorAction Stop
        }
        catch {
            $ChangeProxyServer.Text = "You don't have permissions to read registry"
            Disable-Change
        }
    }
    Get-CurrentProxyInfo
}

Try {
    $Path = Split-Path $MyInvocation.MyCommand.Path -Parent -ErrorAction Stop
    $LogoImage.Source = "$Path\Proxy_Change.png"
}
Catch {
    
}
$RegKey = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings'
$UrlLabel.Add_MouseDoubleClick({[system.Diagnostics.Process]::start('http://vcloud-lab.com')})
$CloseB.Add_Click({$ChangeProxyForm.Close()})
$RefreshB.Add_Click({Get-CurrentProxyInfo})
Get-CurrentProxyInfo
$ChangeProxyB.Add_Click({Set-NewProxyConfiguration})

$ChangeProxyForm.Add_MouseDown({$ChangeProxyForm.DragMove()}) 
[void]$ChangeProxyForm.ShowDialog()
#ProxyEnable = 1  #1 = enabled & 0 = Disabled
#ProxyServer = 'OldProxyServer:808'

Useful Tools
COOL POWERSHELL FREE ONLINE GUI GENERATOR TOOL, POSHGUI
Generate random password GUI using powershell
Part 1: Create WPF XAML powershell GUI form with Visual studio
Powershell PoshGUI: Convert user to SID and vice versa using

Go Back

Comment

Blog Search

Page Views

1381460

Follow me on Blogarama