proxy ein-/ ausschalten

Dieses Thema im Forum "Programmieren" wurde erstellt von Beatcounter, 19. Mai 2005.

Status des Themas:
Es sind keine weiteren Antworten möglich.
  1. Beatcounter

    Beatcounter Guest

    Registriert seit:
    25. Januar 2003
    Beiträge:
    313
    hallo ich suche einen vb programm, mit dem man den Proxy ein- bzw. ausschalten kann. hat jemand da eine lösung bzw eine idee?
     
  2. Angel-HRO

    Angel-HRO Megabyte

    Registriert seit:
    31. August 2000
    Beiträge:
    2.524
    Wie meisnt du das?
    Die Proxyeinstellungen des Internet Explorers?
    Allgemein ist ein Proxy nicht in Windows angegeben, nur in seinen Programmen (z.B. IE, Firefox...)
     
  3. Beatcounter

    Beatcounter Guest

    Registriert seit:
    25. Januar 2003
    Beiträge:
    313
    fallse s jm interessiert das Modul - ansonsten erfolgreich überlesen:

    Code:
    ption Explicit
    
    Private Const FORMAT_MESSAGE_FROM_SYSTEM As Long = &H1000
    
    Private Enum ErrorCodeEnum
        ERROR_SUCCESS = 0
        ERROR_FILE_NOT_FOUND = 2
        ERROR_PATH_NOT_FOUND = 3
        ERROR_ACCESS_DENIED = 5
        ERROR_INVALID_PARAMETER = 87
        ERROR_NO_MORE_ITEMS = 259
    End Enum
    
    Private Enum KeyAccessEnum
        KEY_QUERY_VALUE = &H1&
        KEY_SET_VALUE = &H2&
        KEY_CREATE_SUB_KEY = &H4&
        KEY_ENUMERATE_SUB_KEYS = &H8&
        KEY_NOTIFY = &H10&
        KEY_CREATE_LINK = &H20&
        KEY_READ = &H19&        '   KEY_QUERY_VALUE Or
                                '   KEY_ENUMERATE_SUB_KEYS Or
                                '   KEY_NOTIFY
        KEY_EXECUTE = KEY_READ
        KEY_WRITE = &H6&        '   KEY_SET_VALUE Or
                                '   KEY_CREATE_SUB_KEY
        KEY_ALL_ACCESS = &H3F&  '   KEY_QUERY_VALUE Or
                                '   KEY_SET_VALUE Or
                                '   KEY_CREATE_SUB_KEY Or
                                '   KEY_ENUMERATE_SUB_KEYS Or
                                '   KEY_NOTIFY Or
                                '   KEY_CREATE_LINK
    End Enum
    
    Public Enum HKeyEnum
        HKEY_CLASSES_ROOT = &H80000000
        hKey_CURRENT_USER = &H80000001
        hKey_local_machine = &H80000002
        HKEY_USERS = &H80000003
        HKEY_PERFORMANCE_DATA = &H80000004
        HKEY_CURRENT_CONFIG = &H80000005
        HKEY_DYN_DATA = &H80000006
    End Enum
    
    Public Enum KeyTypeEnum
        REG_NONE = 0
        REG_SZ = 1
        REG_EXPAND_SZ = 2
        REG_BINARY = 3
        reg_dword = 4
        REG_DWORD_BIG_ENDIAN = 5
        REG_LINK = 6
        REG_MULTI_SZ = 7
    End Enum
    
    Private Declare Function FormatMessage Lib "kernel32" _
                    Alias "FormatMessageA" ( _
                    ByVal dwFlags As Long, _
                    ByRef lpSource As Any, _
                    ByVal dwMessageId As Long, _
                    ByVal dwLanguageId As Long, _
                    ByVal lpBuffer As String, _
                    ByVal nSize As Long, _
                    ByRef Arguments As Long) As Long
    
    Private Declare Function RegCloseKey Lib "advapi32.dll" ( _
                    ByVal hKey As Long) As Long
                    
    Private Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" ( _
                    ByVal hKey As Long, _
                    ByVal lpValueName As String) As Long
    
    Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" ( _
                    ByVal hKey As Long, _
                    ByVal lpSubKey As String, _
                    ByVal ulOptions As Long, _
                    ByVal samDesired As Long, _
                    ByRef phkResult As Long) As Long
    
    Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" ( _
                    ByVal hKey As Long, _
                    ByVal lpValueName As String, _
                    ByVal lpReserved As Long, _
                    ByRef lpType As Long, _
                    lpData As Any, _
                    lpcbData As Any) As Long
                    
    Private Declare Function RegSetValueEx_DWORD Lib "advapi32.dll" Alias "RegSetValueExA" ( _
                    ByVal hKey As Long, _
                    ByVal lpValueName As String, _
                    ByVal Reserved As Long, _
                    ByVal dwType As Long, _
                    ByRef lpData As Long, _
                    ByVal cbData As Long) As Long
                    
    Private Const ProxyRoot As Long = HKeyEnum.hKey_local_machine
    Private Const Proxykey As String = "SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings"
    Private Const ProxyField As String = "ProxyEnable"
    
    Private Function GetErrorMessage(ByVal ErrorCode As Long) As String
        Dim lngBufLen As Long
        Dim strBuffer As String
        Dim lngResult As Long
        
        '   Ausreichend Speicher bereitstellen
        lngBufLen = 256
        strBuffer = Space$(lngBufLen)
        
        '   Fehlermeldung holen
        lngResult = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, ErrorCode, _
                                  0&, strBuffer, lngBufLen, ByVal 0)
        
        '   Alles ab dem ersten NullCHar wegschneiden
        lngResult = InStr(1, strBuffer, vbNullChar)
        If (lngResult <> 0) Then
            strBuffer = Left$(strBuffer, lngResult)
        End If
        
        '   Fehlermeldung zurückgeben
        GetErrorMessage = strBuffer
    End Function
    
    'Proxy Starten
    Public Function SetRun() As Boolean
        Dim lResult, hKey, lPath As Long
      
        lPath = 1
      
        lResult = RegOpenKeyEx(ProxyRoot, Proxykey, 0, KEY_ALL_ACCESS, hKey)
        If lResult <> ERROR_SUCCESS Then
            SetRun = False
            Exit Function
        End If
        lResult = RegSetValueEx_DWORD(hKey, ProxyField, 0, reg_dword, lPath, 4)
        RegCloseKey hKey
        SetRun = (lResult = ERROR_SUCCESS)
    End Function
    
    'Proxy Löschen
    Public Function DeleteRun() As Boolean
        Dim lResult, hKey, lPath As Long
      
        lPath = 0
      
        lResult = RegOpenKeyEx(ProxyRoot, Proxykey, 0, KEY_ALL_ACCESS, hKey)
        If lResult <> ERROR_SUCCESS Then
            DeleteRun = False
            Exit Function
        End If
        lResult = RegSetValueEx_DWORD(hKey, ProxyField, 0, reg_dword, lPath, 4)
        RegCloseKey hKey
        DeleteRun = (lResult = ERROR_SUCCESS)
    End Function
    
    Public Function IsRun() As Boolean
        Dim lBuffer As Long
        Dim lResult As Long
        Dim hKey As Long
        Dim dwType As Long
        Dim lBufferSize As Long
      
        '   Schlüssel öffnen
        lResult = RegOpenKeyEx(ProxyRoot, Proxykey, 0&, KEY_ALL_ACCESS, hKey)
        Select Case lResult
            Case ERROR_SUCCESS
                
                lResult = RegQueryValueEx(hKey, ProxyField, 0&, dwType, ByVal 0&, lBufferSize)
                
                Select Case lResult
                    Case ERROR_SUCCESS
                        
                        If dwType = reg_dword Then
                            lBuffer = 0
                            lBufferSize = Len(lBuffer)
                            
                            lResult = RegQueryValueEx(hKey, ProxyField, 0&, dwType, lBuffer, lBufferSize)
                            
                            If lResult <> ERROR_SUCCESS Then
                                lBuffer = 0
                                MsgBox GetErrorMessage(CStr(lResult))
                            End If
                        End If
                        
                        IsRun = (lBuffer = 1)
                        
                    Case Else
                        MsgBox GetErrorMessage(CStr(lResult))
                        
                End Select
                
            Case Else
                IsRun = False
                MsgBox GetErrorMessage(CStr(lResult))
                
        End Select
        
        If hKey <> 0 Then
            Call RegCloseKey(hKey)
        End If
    End Function
    
    
     
  4. Beatcounter

    Beatcounter Guest

    Registriert seit:
    25. Januar 2003
    Beiträge:
    313
    Leider falsch!
    Der Proxy für den IE ist in der Registry abgelegt
    wenn du's nicht glaubst ein blick in
    hKeyEnum.hKey_local_machine -> SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings -> ProxyEnable (0/1)
    was sit dass dann?

    Für den Firefox ist deine aussage leider richtig - ich fänd es besser wenn der proxy für alle browser gleich geregelt werden würde - so muss ich immer in allen browsern den proxy manuell eintragen.
     
Status des Themas:
Es sind keine weiteren Antworten möglich.

Diese Seite empfehlen