r9754: Upgrading with the command line utility now works, at least partially (-:
[kai/samba.git] / source4 / scripting / bin / winreg
1 #!/bin/sh
2 exec smbscript "$0" ${1+"$@"}
3 /*
4   tool to manipulate a remote registry
5   Copyright Andrew Tridgell 2005
6   Released under the GNU GPL v2 or later
7 */      
8
9 var options = GetOptions(ARGV,
10                          "POPT_AUTOHELP",
11                          "POPT_COMMON_SAMBA",
12                          "POPT_COMMON_CREDENTIALS",
13                          "createkey=s");
14 if (options == undefined) {
15         println("Failed to parse options");
16         return -1;
17 }
18
19 libinclude("base.js");
20 libinclude("winreg.js");
21
22 if (options.ARGV.length < 1) {
23         println("Usage: winreg.js <BINDING> [path]");
24         return -1;
25 }
26 var binding = options.ARGV[0];
27 reg = winregObj();
28
29 print("Connecting to " + binding + "\n");
30 status = reg.connect(binding);
31 if (status.is_ok != true) {
32         print("Failed to connect to " + binding + " - " + status.errstr + "\n");
33         return -1;
34 }
35
36 function list_values(path) {
37         var list = reg.enum_values(path);
38         var i;
39         if (list == undefined) {
40                 return;
41         }
42         for (i=0;i<list.length;i++) {
43                 var v = list[i];
44                 printf("\ttype=%-30s size=%4d  '%s'\n", reg.typestring(v.type), v.size, v.name);
45                 if (v.type == reg.REG_SZ || v.type == reg.REG_EXPAND_SZ) {
46                         printf("\t\t'%s'\n", v.value);
47                 }
48                 if (v.type == reg.REG_MULTI_SZ) {
49                         var j;
50                         for (j in v.value) {
51                                 printf("\t\t'%s'\n", v.value[j]);
52                         }
53                 }
54                 if (v.type == reg.REG_DWORD || v.type == reg.REG_DWORD_BIG_ENDIAN) {
55                         printf("\t\t0x%08x (%d)\n", v.value, v.value);
56                 }
57                 if (v.type == reg.REG_QWORD) {
58                         printf("\t\t0x%llx (%lld)\n", v.value, v.value);
59                 }
60         }
61 }
62
63 function list_path(path) {
64         var list = reg.enum_path(path);
65         if (list == undefined) {
66                 println("Unable to list " + path);
67                 return;
68         }
69         var i;
70         list_values(path);
71         for (i=0;i<list.length;i++) {
72                 var npath;
73                 if (path) {
74                         npath = path + "\\" + list[i];
75                 } else {
76                         npath = list[i];
77                 }
78                 println(npath);
79                 list_path(npath);
80         }
81 }
82
83 var root;
84
85 if (options.ARGV.length > 1) {
86         root = options.ARGV[1];
87 } else {
88         root = '';
89 }
90
91 if (options.createkey) {
92         var ok = reg.create_key("HKLM\\SOFTWARE", options.createkey);
93         if (!ok) {
94                 println("Failed to create key");
95         }
96 } else {
97         printf("Listing registry tree '%s'\n", root);
98         list_path(root);
99 }
100 return 0;