Change IE Proxy on Remote Machine

Private Sub ChangeProxy(ByVal IP As String, ByVal Proxy As Boolean, ByVal strAddress As String, ByVal ByPass As Boolean)

        Dim strComputer
        Dim strUserName
        Dim strPassword
        Dim objLocator
        Dim objService
        Dim objRegistry

        Dim strKeyPath, strValueName, strValue As String
        Dim dwValue As Integer

        Const HKEY_CURRENT_USER = &H80000001
        strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings"



        strComputer = IP
        strUserName = UserName
        strPassword = Password

        Try

            objLocator = CreateObject("WbemScripting.SWbemLocator")

            If (IP = System.Environment.MachineName) Then
                objService = objLocator.ConnectServer(strComputer, "Root\Default")
            Else
                objService = objLocator.ConnectServer(strComputer, "Root\Default", strUserName, strPassword)
            End If

            objService.Security_.impersonationlevel = 3

            objRegistry = objService.Get("StdRegProv")

            strValueName = "ProxyEnable"

            If (Proxy) Then

                dwValue = 1
                objRegistry.SetDWORDValue(HKEY_CURRENT_USER, strKeyPath, strValueName, dwValue)

                strValueName = "ProxyServer"
                strValue = strAddress
                objRegistry.SetStringValue(HKEY_CURRENT_USER, strKeyPath, strValueName, strValue)

                If (ByPass) Then

                    strValueName = "ProxyOverride"
                    strValue = txtByPass.Text
                    objRegistry.SetStringValue(HKEY_CURRENT_USER, strKeyPath, strValueName, strValue)
                    'Else

                    '    strValueName = "ProxyOverride"
                    '    strValue = "127.0.0.1"
                    '    objRegistry.SetStringValue(HKEY_CURRENT_USER, strKeyPath, strValueName, strValue)
                End If

            Else

                dwValue = 0
                objRegistry.SetDWORDValue(HKEY_CURRENT_USER, strKeyPath, strValueName, dwValue)

            End If

            CreateLog("Proxy Setting for IE", IP, "Proxy Address " & strValue & " Executed.", "Success")

        Catch ex As Exception

            CreateLog("Proxy Setting for IE", IP, "Proxy Address " & strValue & " Executed.", "Failed")

        End Try

End Sub

Related Posts by Categories



Stumble This Fav This With Technorati Add To Del.icio.us Digg This Add To Reddit Add To Facebook Add To Yahoo

0 comments:

Post a Comment