| Auteur | 
Message | 
deco76 
Forumeur occasionnel 
 
 
 
 
  
Messages: 36 
 
 
 | 
 Posté le:
Jeu 06 Oct 2011 - 21:10 | 
   | 
 
 
 
Bonjour
 
 
Je souhaite activer ou désactiver mon proxy via mon programme.
 
Malheureusement, cela ne marche qu'une seule fois, c'est à dire qu'il va doit activer ou désactiver le proxy selon le choix 1 première fois.
 
 
Mais si l'on souhaite faire le contraire, cela ne marche pas.
 
J'ai déjà consulté toutes la 1ère page de google, mais aucun lien ne résout mon problème.
 
 
je suis obligé de redemarrer mon programme.
 
 
Si vous pouviez m'aidez, je vous en remercie d'avance.
 
 
http://social.msdn.microsoft.com/Forums/en/csharpgeneral/thread/19517edf-8348-438a-a3da-5fbe7a46b61a
 
http://www.codeproject.com/KB/dotnet/proxyViolater.aspx#_comments
 
http://sturla.simnet.is/post/2008/09/22/Enable-proxy-in-IE.aspx
 
http://androidyou.blogspot.com/2010/05/disable-ie-proxy-via-c-code-or-java.html
 
 
 
 
| Code: | 
 
private void EnableProxy(bool p)
 
      {
 
          string k = @"Software\Microsoft\Windows\CurrentVersion\Internet Settings";
 
          Microsoft.Win32.RegistryKey regk = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(k, true);
 
          if (p)
 
              regk.SetValue("ProxyEnable", 1, Microsoft.Win32.RegistryValueKind.DWord);
 
          else
 
              regk.SetValue("ProxyEnable", 0, Microsoft.Win32.RegistryValueKind.DWord);
 
          regk.Close();
 
      } | 
 
 
 
 
Pour l'activer :
 
 
| Code: | 
 
            //string key = "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
 
            //string proxy = "127.0.0.1:8020";
 
            //RegistryKey RegKey = Registry.CurrentUser.OpenSubKey(key, true);
 
            //RegKey.SetValue("ProxyServer", proxy);
 
            //RegKey.SetValue("ProxyEnable", 1); | 
 
 
 
 
Pour l'annuler :
 
 
| Code: | 
 
            //string key = "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
 
            //string proxy = "127.0.0.1:8020";
 
            //RegistryKey RegKey = Registry.CurrentUser.OpenSubKey(key, true);
 
            //RegKey.SetValue("ProxyServer", proxy);
 
            //RegKey.SetValue("ProxyEnable", 0); | 
 
 
 
 
   | 
 
  Dernière édition par deco76 le Dim 09 Oct 2011 - 19:27; édité 3 fois | 
 
 
 | 
   | 
 | 
 N'oubliez pas de vous inscrire à la communauté pour participer. Si vous êtes déjà membre, connectez-vous pour faire disparaître ce bandeau publicitaire. | 
deco76 
Forumeur occasionnel 
 
 
 
 
  
Messages: 36 
 
 
 | 
 Posté le:
Ven 07 Oct 2011 - 22:04 | 
   | 
 
 
 
Bonsoir
 
 
Après de nombreuses recherche, voici le résultat :
 
 
Code pour lancer un processus :
 
 
| Code: | 
 
   Process proc = new Process();
 
            ProcessStartInfo processStarInf = new ProcessStartInfo();
 
            processStarInf.FileName = "iexplore.exe";
 
            processStarInf.Arguments = argument;          // /!\ .Hidden peu créer des erreurs. /!\
 
            processStarInf.WindowStyle = ProcessWindowStyle.Minimized;
 
 // processStarInf.WindowStyle = ProcessWindowStyle.Maximized; // aux choix
 
            proc = Process.Start(processStarInf);  | 
 
 
 
 
fonction :
 
 
| Code: | 
 
 
 
   private static void KillProcess(object processName)
 
        {
 
            // Liste des processus ayant ce nom
 
            Process[] processes =  Process.GetProcessesByName(processName.ToString());
 
            foreach (Process process in processes)
 
            {
 
                 //process.Kill();   Tue le processus, mais crée un message d'erreur après redemarrage de IE
 
                //process.WaitForExit();
 
 
                  process.CloseMainWindow();
 
                  process.Close();
 
            }
 
        } | 
 
 
 
 
Code pour killer un processus dans un button :
 
 
| Code: | 
 
 Preview("http://www.monip.org");
 
            Thread.Sleep(5000);
 
            System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(KillProcess));
 
            thread.Start("iexplore"); // <---- le nom du process | 
 
 
 
 
Elle va lancer l'internet explorer pour qu'il prenne les nouveaux paramètre, attendre 5 seconde, puis fermer iexplorer.
 
 
Cette méthode me donne satisfaction, même si elle n'est pas parfaite, elle a le mérite de ne pas me refaire redémarrer le programme.
 
 
Cordialement.
 
   | 
 
  Dernière édition par deco76 le Dim 09 Oct 2011 - 21:36; édité 3 fois | 
 
 
 | 
   | 
 | 
 
deco76 
Forumeur occasionnel 
 
 
 
 
  
Messages: 36 
 
 
 | 
 Posté le:
Dim 09 Oct 2011 - 19:17 | 
   | 
 
 
 
Ne pas oublier de faire un refresh à partir de internet explorer 8-9
 
 
Je viens de le constater.
 
 
Ajouter en début de code, après le nom de votre class :
 
 
| Code: | 
 
        [DllImport("wininet.dll")]
 
        public static extern bool InternetSetOption(IntPtr hInternet, int dwOption, IntPtr lpBuffer, int dwBufferLength);
 
        public const int INTERNET_OPTION_SETTINGS_CHANGED = 39;
 
        public const int INTERNET_OPTION_REFRESH = 37;
 
        bool settingsReturn, refreshReturn; | 
 
 
 
 
Puis dans votre code : 
 
 
| Code: | 
 
                // These lines implement the Interface in the beginning of program 
 
                // They cause the OS to refresh the settings, causing IP to realy update
 
                settingsReturn = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_SETTINGS_CHANGED, IntPtr.Zero, 0);
 
                refreshReturn = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_REFRESH, IntPtr.Zero, 0); | 
 
 
 
 
Ce qui donne pour l'activation d'un proxy :
 
 
| Code: | 
 
 
                string key = "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
 
                string proxy = "127.0.0.1:8020";
 
                RegistryKey RegKey = Registry.CurrentUser.OpenSubKey(key, true);
 
                RegKey.SetValue("ProxyServer", proxy);
 
                RegKey.SetValue("ProxyEnable", 1);
 
 
                // These lines implement the Interface in the beginning of program 
 
                // They cause the OS to refresh the settings, causing IP to realy update
 
                settingsReturn = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_SETTINGS_CHANGED, IntPtr.Zero, 0);
 
                refreshReturn = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_REFRESH, IntPtr.Zero, 0);
 
 
                Preview("http://www.monip.org");
 
                Cursor.Current = Cursors.WaitCursor;
 
 
                Thread.Sleep(10000);
 
 
                System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(KillProcess));
 
                thread.Start("iexplore"); // <---- le nom du process
 
                Cursor.Current = Cursors.Default;
 
 | 
 
 
 
 
Si vous avez un petit soucis, il est préférable d'ajouter un .exe au registre  --> EXECUTER/Recherche--> "regedit" :
 
 
| Code: | 
 
HKEY_LOCAL_MACHINE (or HKEY_CURRENT_USER)
 
     SOFTWARE
 
          Microsoft
 
               Internet Explorer
 
                    Main
 
                         FeatureControl
 
                              FEATURE_BROWSER_EMULATION
 
                                   "NomDeVotreProgramme".exe = (DWORD) 000090000
 
 | 
 
 
 
 
    9999 (0x270F) - Internet Explorer 9. Webpages are displayed in IE9 Standards mode, regardless of the !DOCTYPE directive.
 
    9000 (0x2328) - Internet Explorer 9. Webpages containing standards-based !DOCTYPE directives are displayed in IE9 mode.
 
    8888 (0x22B8) -Webpages are displayed in IE8 Standards mode, regardless of the !DOCTYPE directive.
 
    8000 (0x1F40) - Webpages containing standards-based !DOCTYPE directives are displayed in IE8 mode.
 
    7000 (0x1B58) - Webpages containing standards-based !DOCTYPE directives are displayed in IE7 Standards mode.
 
 
http://stackoverflow.com/questions/4612255/regarding-ie9-webbrowser-control
 
 
   | 
 
 | 
 
 
 | 
   | 
 | 
 
| 
 |