Results 1 to 2 of 2

Thread: enable/disable proxy thru application

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2003
    Posts
    2

    enable/disable proxy thru application

    Hi,

    I am able to enable the proxy and feed my provided IP address and port no for the proxy.This works fine but when i try to disable it and go to the tools->Internet Options->connections->LAN settings i dont see it disabled.
    Even rebooting the machine didnt help.
    The the probelem is that i am able to enable and feed the value but am not able to disable the proxy thru my application.
    I am using VB 6.0.
    Here is the code :


    VB Code:
    1. Private Const HKEY_CURRENT_USER = &H80000001
    2. Private Const REG_SZ = 1
    3. Private Const REG_SZ1 = 0
    4. Private Const REG_BINARY = 3
    5. Private Const REG_DWORD = 4
    6. Private Const ERROR_SUCCESS = 0&
    7. Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal Hkey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, ByVal lpData As String, ByVal cbData As Long) As Long
    8. Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal Hkey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
    9. Private Declare Function RegOpenKey Lib "advapi32.dll" _
    10. Alias "RegOpenKeyA" (ByVal Hkey As Long, ByVal lpSubKey _
    11. As String, phkResult As Long) As Long
    12. Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal
    13. Hkey As Long) As Long
    14.  
    15. 'this function enables the proxy and the value i have hardcoded
    16. Private Sub Command1_Click()
    17. proxy = "1.1.1.1:80"
    18. Dim WshShell As Object
    19. Set WshShell = CreateObject("WScript.Shell")
    20.  
    21. Call savestring(HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyEnable", 1)
    22. 'Call savestring(HKEY_CURRENT_USER, "\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyServer", proxy)
    23. WshShell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyServer", "1.1.1.1:80", "REG_SZ"
    24. Form1.Label1.Visible = True
    25. Form1.Label2.Visible = True
    26. Form1.Label3.Caption = "The Proxy Is Enabled On This Machine"
    27. 'MsgBox ("Enabled")
    28.  
    29.  
    30. End Sub
    31.  
    32.  
    33. 'this function disables the proxy (it has a problem i guess)
    34. Private Sub Command2_Click()
    35. Dim WshShell As Object
    36. Set WshShell = CreateObject("WScript.Shell")
    37. Call savestring(HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyEnable", 0)
    38. WshShell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyServer", "", "REG_SZ"
    39. 'MsgBox ("Disabled")
    40. Form1.Label1.Visible = False
    41. Form1.Label2.Visible = False
    42. Form1.Label3.Caption = "The Proxy Is Disabled On This Machine"
    43.  
    44. End Sub
    45.  
    46.  
    47. 'just to exit
    48. Private Sub Command3_Click()
    49. End
    50. End Sub
    51.  
    52.  
    53. 'the form load function
    54. Private Sub Form_Load()
    55. Form1.Label1.Visible = False
    56. Form1.Label2.Visible = False
    57. Form1.Label3.Caption = "Please Click To Enable Or Disable The Proxy"
    58. End Sub
    59.  
    60. 'this function is called from above to enable/disable  proxy Setting
    61. Public Sub savestring(Hkey As Long, strPath As String, strValue As String, strdata As String)
    62.     On Error Resume Next
    63.     Dim keyhand As Long
    64.     Dim r As Long
    65.     r = RegCreateKey(Hkey, strPath, keyhand)
    66.     r = RegSetValueEx(keyhand, strValue, 0, REG_SZ, strdata, Len(strdata))
    67.     r = RegCloseKey(keyhand)
    68.    
    69. End Sub

    regds,
    SK

  2. #2

    Thread Starter
    New Member
    Join Date
    Sep 2003
    Posts
    2
    hi,
    where have all the gurus gone. I need serious help on this on an urgent basis ....pliss help me urgently on this regard.
    Regards,
    SK

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width