Bonjour à toutes et à tous !
Je suis actuellement en train de développer un script VBS afin d'accéder aux couches bas niveau en Java, le script est généré et exécuté par le code Java.
Script VBS (Son but est de chercher la version d'un logiciel dans le registre) :
(Le nom de la clef a rechercher est volontairement caché)
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 const HKEY_LOCAL_MACHINE = &H80000002 strComputer = "." Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\"&_ strComputer & "\root\default:StdRegProv") strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products" Set objFSO=CreateObject("Scripting.FileSystemObject") outFile="C:\Users\######\AppData\Local\Temp\GetVersionSoftware.txt" Set objFile = objFSO.CreateTextFile(outFile,True) strName = "######################" strValueName = "DisplayName" strValueVersion = "DisplayVersion" strValueSubKey = "InstallProperties" If oReg.EnumKey(HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys) = 0 Then For Each subkey In arrSubKeys strKeyPath2 = strKeyPath & "\" & subkey If oReg.EnumKey(HKEY_LOCAL_MACHINE, strKeyPath2, arrSubKeys2) = 0 Then For Each subkey2 In arrSubKeys2 If subkey2 = strValueSubKey Then strKeyPathInstallProp = strKeyPath2 & "\" & subkey2 oReg.EnumValues HKEY_LOCAL_MACHINE, strKeyPathInstallProp, arrValueNames, arrValueTypes If Not IsNull(arrValueNames) Then For I = 0 To UBound(arrValueNames) If arrValueNames(I) = strValueName Then oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPathInstallProp,strValueName,strValue If strValue = strName Then oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPathInstallProp,strValueVersion,strVersion objFile.Write strVersion & vbCrLf objFile.close End if End if Next End if End if Next End if Next End if
Pour l'instant, le résultat est écrit dans un fichier texte pour être lu ensuite, c'est un essai infructueux pour tenter de résoudre le problème que voici :
Lorsque j'exécute mon programme dans Eclipse, tout se passe bien, les valeurs sont récupérées dans problèmes.
Par contre, dès que je demande la création du jar (via Maven), celui ci n’exécute pas correctement le script car le fichier de sortie texte reste vide.
Je n'arrive pas a déterminer la provenance de ce problème...
Le code d'exécution :
Si vous avez des questions ou des demandes d'infos, n'hésitez pas !
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; class StreamGobbler extends Thread { InputStream is; String type; StreamGobbler(InputStream is, String type) { this.is = is; this.type = type; } @Override public void run() { try { InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); String line=null; while ( (line = br.readLine()) != null) System.out.println(type + ">" + line); } catch (IOException ioe) { ioe.printStackTrace(); } } } public class VBSReader { public static void launchVBS(String vbsDir) { try { String[] cmd = new String[3]; cmd[0] = "cscript"; cmd[1] = vbsDir; cmd[2] = " //logo"; Runtime rt = Runtime.getRuntime(); System.out.println("Execing " + cmd[0] + " " + cmd[1] + " " + cmd[2]); Process proc = rt.exec(cmd); try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } StreamGobbler errorGobbler = new StreamGobbler(proc.getErrorStream(), "ERROR"); StreamGobbler outputGobbler = new StreamGobbler(proc.getInputStream(), "OUTPUT"); errorGobbler.start(); outputGobbler.start(); int exitVal = proc.waitFor(); System.out.println("ExitValue: " + exitVal); } catch (Throwable t) { t.printStackTrace(); } } }
En espérant une quelconque aide de votre part, je ne sais plus vraiment quoi faire....
Cordialement, et avec tout l'amour du monde![]()
Partager