IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage Java Discussion :

Récupérer/modifier une clé de la base de registre Windows ?


Sujet :

Langage Java

  1. #1
    Membre régulier
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Avril 2008
    Messages
    197
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2008
    Messages : 197
    Points : 117
    Points
    117
    Par défaut Récupérer/modifier une clé de la base de registre Windows ?
    Bonjours,

    Je veux accéder à un key dans la base de registre windows avec un programme java, sans passer par l'api JNI, comment je procède ?

    Et merci d'avance.

  2. #2
    Expert éminent sénior
    Avatar de sinok
    Profil pro
    Inscrit en
    Août 2004
    Messages
    8 765
    Détails du profil
    Informations personnelles :
    Âge : 43
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Août 2004
    Messages : 8 765
    Points : 12 977
    Points
    12 977
    Par défaut
    En construisant la ligne de commande appropriée (à bas e de reg query) via un ProcessBuilder, en exécutant le Process récupéré tout en traitant bien sur le flux de retour.

    Cf http://blog.developpez.com/adiguba/p...s-plus-simple/
    Hey, this is mine. That's mine. All this is mine. I'm claiming all this as mine. Except that bit. I don't want that bit. But all the rest of this is mine. Hey, this has been a really good day. I've eaten five times, I've slept six times, and I've made a lot of things mine. Tomorrow, I'm gonna see if I can't have sex with something.

  3. #3
    Membre régulier
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Avril 2008
    Messages
    197
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2008
    Messages : 197
    Points : 117
    Points
    117
    Par défaut
    Merci pour l'aide ça m'a aidé beaucoup,
    Mais j'ai un pb lorsque je fait l'appel de reg query voila la méthode que j'ai fait :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    try {
    Process p = new ProcessBuilder("reg query \"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\" /v proxyserver").start();
    				
                    BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
                    String inputLine;
                    while ((inputLine = in.readLine()) != null) System.out.println(inputLine);
    				
    			} catch (IOException e) {
    				System.out.println(e);
    				e.printStackTrace();
    			}
    la console affiche l'erreur suivante :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    java.io.IOException: Cannot run program "reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v proxyserver": CreateProcess error=2, The system cannot find the file specified
    	at java.lang.ProcessBuilder.start(Unknown Source)
    	at testProxy.main(testProxy.java:27)
    Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
    	at java.lang.ProcessImpl.create(Native Method)
    	at java.lang.ProcessImpl.<init>(Unknown Source)
    	at java.lang.ProcessImpl.start(Unknown Source)java.io.IOException: Cannot run program "reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v proxyserver": CreateProcess error=2, The system cannot find the file specified
     
    	... 2 more
    Ce que j'ai pas compris c'est que lorsque je prends la chaine : "reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v proxyserver" et je le met dans la console de windows il affiche bien le résultat ip proxy et port, la chaine de reg query est correcte.
    Aussi lorsque je la remplace par ipconfig dans le code java ça marche, la commande est exécuté !!

    C'est quoi l'erreur avec reg query ?? et merci.

  4. #4
    Expert éminent sénior
    Avatar de sinok
    Profil pro
    Inscrit en
    Août 2004
    Messages
    8 765
    Détails du profil
    Informations personnelles :
    Âge : 43
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Août 2004
    Messages : 8 765
    Points : 12 977
    Points
    12 977
    Par défaut
    Dans la déclaration du ProcessBuilder il faut séparer les divers éléments de la ligne de commande.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    try {
                Process p = new ProcessBuilder(
                        "reg",
                        "query",
                        "\"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\"",
                        "/v", "proxyserver").start();
                BufferedReader in = new BufferedReader(new InputStreamReader(p
                        .getInputStream()));
                String inputLine;
                while ((inputLine = in.readLine()) != null) {
                    System.out.println(inputLine);
                }
     
            } catch (IOException e) {
                // TODO Bloc catch auto-généré
                e.printStackTrace();
            }
    Hey, this is mine. That's mine. All this is mine. I'm claiming all this as mine. Except that bit. I don't want that bit. But all the rest of this is mine. Hey, this has been a really good day. I've eaten five times, I've slept six times, and I've made a lot of things mine. Tomorrow, I'm gonna see if I can't have sex with something.

  5. #5
    Expert éminent sénior
    Avatar de sinok
    Profil pro
    Inscrit en
    Août 2004
    Messages
    8 765
    Détails du profil
    Informations personnelles :
    Âge : 43
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Août 2004
    Messages : 8 765
    Points : 12 977
    Points
    12 977
    Par défaut
    Enfin si c'est la config du proxy que tu cherches, il est parfaitement possible de la récupérer en pur java:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    package proxy;
     
    import java.util.List;
    import java.net.InetSocketAddress;
    import java.net.Proxy;
    import java.net.ProxySelector;
    import java.net.URI;
    import java.util.Iterator;
     
    public class testProxy {
     
        public static void main(String[] args) {
            try {
     
                System.setProperty("java.net.useSystemProxies","true");
                List<Proxy> l = ProxySelector.getDefault().select(
                            new URI("http://www.yahoo.com/"));
     
                for (Iterator<Proxy> iter = l.iterator(); iter.hasNext(); ) {
     
                    Proxy proxy = iter.next();
     
                    System.out.println("proxy hostname : " + proxy.type());
     
                    InetSocketAddress addr = (InetSocketAddress)
                        proxy.address();
     
                    if(addr == null) {
     
                        System.out.println("No Proxy");
     
                    } else {
     
                        System.out.println("proxy hostname : " + 
                                addr.getHostName());
     
                        System.out.println("proxy port : " + 
                                addr.getPort());
     
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    Hey, this is mine. That's mine. All this is mine. I'm claiming all this as mine. Except that bit. I don't want that bit. But all the rest of this is mine. Hey, this has been a really good day. I've eaten five times, I've slept six times, and I've made a lot of things mine. Tomorrow, I'm gonna see if I can't have sex with something.

  6. #6
    Membre régulier
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Avril 2008
    Messages
    197
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2008
    Messages : 197
    Points : 117
    Points
    117
    Par défaut
    Parfait pour les deux solutions, et merci ça me permet d'économiser beaucoup de temps perdu dans les recherches

    Juste une remarque pour la deuxième solution, je pense que ça fonctionne que sur Windows, car j'ai testé la même méthode dans un poste client linux où un proxy distant est configuré et ça donne pas de résultats, il m'affiche DIRECT No Proxy !

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [Batch] Comment rechercher une valeur dans la base de registre et la modifier
    Par elminio75 dans le forum Scripts/Batch
    Réponses: 14
    Dernier message: 13/03/2018, 09h16
  2. [AC-2003] Modifier une zone de texte basée sur column
    Par maringot dans le forum IHM
    Réponses: 3
    Dernier message: 22/10/2009, 15h23
  3. [vb6]modifier une valeur dans la base de registre
    Par bailamos dans le forum VB 6 et antérieur
    Réponses: 1
    Dernier message: 29/11/2007, 22h04
  4. [vbs] récupérer une valeur dans la base de registre
    Par PiuPiu dans le forum VBScript
    Réponses: 2
    Dernier message: 22/12/2006, 18h04
  5. [IE] Modifier une option dans la base de registre
    Par Oberown dans le forum Windows XP
    Réponses: 2
    Dernier message: 16/06/2006, 08h53

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo