@@ -17,7 +17,7 @@ var api = {
17
17
18
18
var pHkey = ref . alloc ( types . PHKEY , new Buffer ( ref . sizeof . pointer ) ) ;
19
19
debug ( 'PHKEY LENGTH: ' + pHkey . deref ( ) . length ) ;
20
- var result = advApi . RegOpenKeyExA ( preDefinedKey , subKeyName , 0 , accessLevel , pHkey ) ;
20
+ var result = advApi . RegOpenKeyExW ( preDefinedKey , subKeyName , 0 , accessLevel , pHkey ) ;
21
21
debug ( 'result:' + result ) ;
22
22
if ( result !== 0 ) {
23
23
throw 'Failed to open key error: ' + error [ result ] ;
@@ -30,9 +30,9 @@ var api = {
30
30
31
31
// RegOpenKeyEx can also take an HKEY in addition to a predefined value
32
32
var advApi2 = ffi . Library ( 'Advapi32' , {
33
- RegOpenKeyExA : [ 'long' , [ types . HKEY , 'string' , types . DWORD , types . REGSAM , types . PHKEY ] ]
33
+ RegOpenKeyExW : [ 'long' , [ types . HKEY , types . LPCWSTR , types . DWORD , types . REGSAM , types . PHKEY ] ]
34
34
} ) ;
35
- var result = advApi2 . RegOpenKeyExA ( keyObject . handle . deref ( ) , subKeyName , 0 , accessLevel , pHkey ) ;
35
+ var result = advApi2 . RegOpenKeyExW ( keyObject . handle . deref ( ) , subKeyName , 0 , accessLevel , pHkey ) ;
36
36
37
37
if ( result !== 0 ) {
38
38
throw 'Failed to open key error: ' + error [ result ] ;
@@ -44,15 +44,15 @@ var api = {
44
44
var pKeyDataLength = ref . alloc ( types . LPDWORD , new Buffer ( ref . sizeof . pointer ) ) ,
45
45
pKeyType = ref . alloc ( types . LPDWORD , new Buffer ( ref . sizeof . pointer ) ) ;
46
46
// QUERY FOR VALUE SIZE & TYPE
47
- var result = advApi . RegQueryValueExA ( key . handle . deref ( ) , valueName , null , pKeyType , null , pKeyDataLength ) ;
47
+ var result = advApi . RegQueryValueExW ( key . handle . deref ( ) , valueName , null , pKeyType , null , pKeyDataLength ) ;
48
48
// READ VALUE
49
49
var value = new Buffer ( pKeyDataLength . readUInt32LE ( ) ) ,
50
50
valueType = pKeyType . readUInt32LE ( ) ;
51
51
switch ( valueType ) {
52
52
case windef . REG_VALUE_TYPE . REG_SZ :
53
53
case windef . REG_VALUE_TYPE . REG_EXPAND_SZ :
54
54
case windef . REG_VALUE_TYPE . REG_LINK :
55
- value . type = types . LPCTSR ;
55
+ value . type = types . LPCWSTR ;
56
56
break ;
57
57
case windef . REG_VALUE_TYPE . REG_BINARY :
58
58
value . type = types . PVOID ;
@@ -67,16 +67,14 @@ var api = {
67
67
}
68
68
69
69
// READ VALUE
70
- result = advApi . RegQueryValueExA ( key . handle . deref ( ) , valueName , null , pKeyType , value , pKeyDataLength ) ;
70
+ result = advApi . RegQueryValueExW ( key . handle . deref ( ) , valueName , null , pKeyType , value , pKeyDataLength ) ;
71
71
72
72
if ( result !== 0 ) {
73
73
throw 'Failed to open key error: ' + error [ result ] ;
74
74
}
75
75
76
- if ( value . type === types . LPTSR ) {
77
- // TODO not sure why buffer's utf8 parsing leaves in the unicode null
78
- // escape sequence. This is a work-around (at least on node 4.1)
79
- value = value . toString ( ) . replace ( '\u0000' , '' ) ;
76
+ if ( value . type === types . LPCWSTR ) {
77
+ value = types . LPCWSTR . toString ( value ) ;
80
78
}
81
79
82
80
return value ;
@@ -93,24 +91,21 @@ var api = {
93
91
case windef . REG_VALUE_TYPE . REG_SZ :
94
92
case windef . REG_VALUE_TYPE . REG_EXPAND_SZ :
95
93
case windef . REG_VALUE_TYPE . REG_LINK :
96
- buffer = new Buffer ( value , 'utf8' ) ;
94
+ buffer = types . LPCWSTR . fromString ( value ) ;
97
95
byte = ref . alloc ( types . LPBYTE , buffer ) ;
98
- debug ( 'content length:' + Buffer . byteLength ( value , 'utf8' ) ) ;
99
- debug ( value ) ;
100
- debug ( buffer . length ) ;
101
- result = advApi . RegSetValueExA ( key . handle . deref ( ) , valueName , null , valueType , byte . deref ( ) , Buffer . byteLength ( value , 'utf8' ) ) ;
96
+ result = advApi . RegSetValueExW ( key . handle . deref ( ) , valueName , null , valueType , byte . deref ( ) , buffer . length ) ;
102
97
break ;
103
98
case windef . REG_VALUE_TYPE . REG_BINARY :
104
99
// we assume that the value is a buffer since it should be binary data
105
100
buffer = value ;
106
101
byte = ref . alloc ( types . LPBYTE , buffer ) ;
107
- result = advApi . RegSetValueExA ( key . handle . deref ( ) , valueName , null , valueType , byte . deref ( ) , buffer . length ) ;
102
+ result = advApi . RegSetValueExW ( key . handle . deref ( ) , valueName , null , valueType , byte . deref ( ) , buffer . length ) ;
108
103
break ;
109
104
case windef . REG_VALUE_TYPE . REG_DWORD :
110
105
case windef . REG_VALUE_TYPE . REG_DWORD_BIG_ENDIAN :
111
106
case windef . REG_VALUE_TYPE . REG_DWORD_LITTLE_ENDIAN :
112
107
buffer = new Buffer ( 4 , value ) ;
113
- result = advApi . RegSetValueExA ( key . handle . deref ( ) , valueName , null , valueType , byte . deref ( ) , buffer . length ) ;
108
+ result = advApi . RegSetValueExW ( key . handle . deref ( ) , valueName , null , valueType , byte . deref ( ) , buffer . length ) ;
114
109
break ;
115
110
default :
116
111
throw 'The type ' + valueType + ' is currently unsupported' ;
@@ -123,21 +118,21 @@ var api = {
123
118
createKey : function ( key , subKeyName , accessLevel ) {
124
119
var pHkey = ref . alloc ( types . PHKEY , new Buffer ( ref . sizeof . pointer ) ) ;
125
120
126
- var result = advApi . RegCreateKeyExA ( key . handle . deref ( ) , subKeyName , null , null , windef . REG_OPTION_NON_VOLATILE , accessLevel , null , pHkey , null ) ;
121
+ var result = advApi . RegCreateKeyExW ( key . handle . deref ( ) , subKeyName , null , null , windef . REG_OPTION_NON_VOLATILE , accessLevel , null , pHkey , null ) ;
127
122
128
123
if ( result !== 0 ) {
129
124
throw 'Failed to open key error: ' + error [ result ] ;
130
125
}
131
126
} ,
132
127
deleteKey : function ( key , subKeyName ) {
133
- var result = advApi . RegDeleteTreeA ( key . handle . deref ( ) , subKeyName ) ;
128
+ var result = advApi . RegDeleteTreeW ( key . handle . deref ( ) , subKeyName ) ;
134
129
135
130
if ( result !== 0 ) {
136
- throw 'Failed to open key error ' + result + ':' + error [ result ] ;
131
+ throw 'Failed to delete key error ' + result + ':' + error [ result ] ;
137
132
}
138
133
} ,
139
134
deleteValue : function ( key , value ) {
140
- var result = advApi . RegDeleteValueA ( key . handle . deref ( ) , value ) ;
135
+ var result = advApi . RegDeleteValueW ( key . handle . deref ( ) , value ) ;
141
136
142
137
if ( result !== 0 ) {
143
138
throw 'Failed to delete value error ' + result + ':' + error [ result ] ;
0 commit comments