1
2
3
4 package net.sf.ovanttasks.ovnative.demos;
5
6 import java.io.IOException;
7 import javax.swing.JOptionPane;
8 import net.sf.ovanttasks.ovnative.win32.Registry;
9
10
11
12
13
14
15
16 public class RegistryInstallUninstall {
17
18 public RegistryInstallUninstall(String[] args) throws IOException {
19 if (args.length == 0) {
20 Object answer = JOptionPane.showInputDialog(null,
21 "Install or uninstall?", "Title",
22 JOptionPane.QUESTION_MESSAGE, null, new Object[]{"install",
23 "uninstall"
24 }, "install");
25 if ("install".equals(answer)) {
26 install();
27 } else if ("uninstall".equals(answer)) {
28 uninstall();
29 }
30 }
31 if (args.length != 1) {
32 System.out.println(getClass().getName() + "(-install|-uninstall)");
33 System.out.println("show how to add/remove entries in windows software setup");
34 return;
35 }
36
37 if (args[0].equals("-install")) {
38 install();
39 } else if (args[0].equals("-uninstall")) {
40 uninstall();
41 } else {
42 System.out.println(getClass().getName() + "(-install|-uninstall)");
43 }
44 }
45
46 void install() {
47 Registry reg = new Registry(
48 Registry.HKEY_LOCAL_MACHINE,
49 "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\ROXES Technologies InstallUninstall Example");
50
51 if (!reg.canOpenWith(Registry.KEY_ALL_ACCESS)) {
52 reg.create();
53 } else {
54 return;
55 }
56 reg.setValue("DisplayName",
57 "ROXES Technologies InstallUninstall Example");
58 reg.setValue("UninstallString", "javaw -cp \"" + System.getProperty("java.class.path") + System.getProperty("java.class.path") + System.getProperty("path.separator") + System.getProperty("user.dir") + "\" InstallUninstall -uninstall");
59
60 reg.setValue("DisplayIcon", System.getProperty("user.dir") + System.getProperty("file.separator") + "roxes.ico");
61 reg.setValue("Comments",
62 "ROXES Technologes provides Next Generation Web Technologies.");
63 reg.setValue("DisplayVersion", "1.0");
64 reg.setValue("HelpLink", "http://www.roxes.com/produkte/win32forjava");
65 reg.setValue("Publisher", "ROXES Technologies");
66 reg.setValue("URLInfoAbout", "http://www.roxes.com");
67 reg.setValue("URLUpdateInfo",
68 "http://www.roxes.com/produkte/win32forjava");
69
70 msgBox("Installation successful");
71 }
72
73 void uninstall() {
74 Registry reg = new Registry(
75 Registry.HKEY_LOCAL_MACHINE,
76 "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\ROXES Technologies InstallUninstall Example");
77
78 if (reg.canOpenWith(Registry.KEY_ALL_ACCESS)) {
79 reg.delete();
80 msgBox("Deinstallation successful");
81 } else {
82 msgBox("Already uninstalled");
83 return;
84 }
85 }
86
87 static void msgBox(String msg) {
88 JOptionPane.showMessageDialog(null, msg);
89 }
90
91 public static void main(String[] args) throws IOException {
92 new RegistryInstallUninstall(args);
93 System.exit(0);
94 }
95 }