14594 ! |
14594 ! |
14595 |
14595 |
14596 key:aKeyNamePath createIfAbsent:createIfAbsent |
14596 key:aKeyNamePath createIfAbsent:createIfAbsent |
14597 "retrieve an entry by full path name (starting at a root)" |
14597 "retrieve an entry by full path name (starting at a root)" |
14598 |
14598 |
14599 |idx first rest root| |
14599 ^ self key:aKeyNamePath flags:flags createIfAbsent:createIfAbsent |
14600 |
|
14601 HKEY_CLASSES_ROOT isNil ifTrue:[self initialize]. |
|
14602 |
|
14603 idx := aKeyNamePath indexOf:(self separator). |
|
14604 idx == 0 ifTrue:[ |
|
14605 first := aKeyNamePath. |
|
14606 rest := nil. |
|
14607 ] ifFalse:[ |
|
14608 first := aKeyNamePath copyTo:idx-1. |
|
14609 rest := aKeyNamePath copyFrom:idx+1 |
|
14610 ]. |
|
14611 |
|
14612 first := first asUppercase. |
|
14613 |
|
14614 "/ the first is a pseudo name |
|
14615 root := self rootKey:first. |
|
14616 root isNil ifTrue:[ |
|
14617 ^ nil |
|
14618 ]. |
|
14619 |
|
14620 rest size == 0 ifTrue:[ |
|
14621 ^ root |
|
14622 ]. |
|
14623 |
|
14624 Error handle:[:ex | |
|
14625 ^ nil |
|
14626 ] do:[ |
|
14627 ^ root subKeyNamed:rest createIfAbsent:createIfAbsent. |
|
14628 ]. |
|
14629 |
14600 |
14630 " |
14601 " |
14631 self key:'HKEY_LOCAL_MACHINE' |
14602 self key:'HKEY_LOCAL_MACHINE' |
14632 self key:'HKEY_LOCAL_MACHINE\Software' |
14603 self key:'HKEY_LOCAL_MACHINE\Software' |
14633 self key:'HKEY_LOCAL_MACHINE\Software\Borland\' |
14604 self key:'HKEY_LOCAL_MACHINE\Software\Borland\' |
14634 self key:'HKEY_LOCAL_MACHINE\Software\eXept\Smalltalk/X\3.2.5\Directory' |
14605 self key:'HKEY_LOCAL_MACHINE\Software\eXept\Smalltalk/X\3.2.5\Directory' |
14635 (self key:'HKEY_CLASSES_ROOT\MicrosoftWorks.WordProcessor\CLSID') valueNamed:'' |
14606 (self key:'HKEY_CLASSES_ROOT\MicrosoftWorks.WordProcessor\CLSID') valueNamed:'' |
|
14607 " |
|
14608 |
|
14609 "Created: / 19-01-2011 / 15:59:21 / cg" |
|
14610 ! |
|
14611 |
|
14612 key:aKeyNamePath flags:flags |
|
14613 "retrieve an entry by full path name (starting at a root). |
|
14614 flags may be one of: |
|
14615 #KEY_WOW64_64KEY to force access to the 64Bit Windows key, |
|
14616 #KEY_WOW64_32KEY to force access to the 32Bit Windows key, |
|
14617 or nil, to access the key (32/64) for the current application" |
|
14618 |
|
14619 ^ self key:aKeyNamePath flags:flags createIfAbsent:false |
|
14620 |
|
14621 " |
|
14622 self key:'HKEY_LOCAL_MACHINE' |
|
14623 self key:'HKEY_LOCAL_MACHINE\Software' |
|
14624 self key:'HKEY_LOCAL_MACHINE\Software\Borland\' |
|
14625 self key:'HKEY_LOCAL_MACHINE\Software\eXept\Smalltalk/X\3.2.5\Directory' |
|
14626 (self key:'HKEY_CURRENT_USER\Console' flags:#KEY_WOW64_64KEY) subKeys |
|
14627 (self key:'HKEY_CURRENT_USER\Console' flags:#KEY_WOW64_32KEY) subKeys |
|
14628 " |
|
14629 |
|
14630 "Modified: / 19-01-2011 / 15:59:36 / cg" |
|
14631 ! |
|
14632 |
|
14633 key:aKeyNamePath flags:flags createIfAbsent:createIfAbsent |
|
14634 "retrieve an entry by full path name (starting at a root). |
|
14635 flags may be one of: |
|
14636 #KEY_WOW64_64KEY to force access to the 64Bit Windows key, |
|
14637 #KEY_WOW64_32KEY to force access to the 32Bit Windows key, |
|
14638 or nil, to access the key (32/64) for the current application" |
|
14639 |
|
14640 |idx first rest root| |
|
14641 |
|
14642 HKEY_CLASSES_ROOT isNil ifTrue:[self initialize]. |
|
14643 |
|
14644 idx := aKeyNamePath indexOf:(self separator). |
|
14645 idx == 0 ifTrue:[ |
|
14646 first := aKeyNamePath. |
|
14647 rest := nil. |
|
14648 ] ifFalse:[ |
|
14649 first := aKeyNamePath copyTo:idx-1. |
|
14650 rest := aKeyNamePath copyFrom:idx+1 |
|
14651 ]. |
|
14652 |
|
14653 first := first asUppercase. |
|
14654 |
|
14655 "/ the first is a pseudo name |
|
14656 root := self rootKey:first. |
|
14657 root isNil ifTrue:[ |
|
14658 ^ nil |
|
14659 ]. |
|
14660 |
|
14661 rest size == 0 ifTrue:[ |
|
14662 ^ root |
|
14663 ]. |
|
14664 |
|
14665 Error handle:[:ex | |
|
14666 ^ nil |
|
14667 ] do:[ |
|
14668 ^ root subKeyNamed:rest flags:flags createIfAbsent:createIfAbsent. |
|
14669 ]. |
|
14670 |
|
14671 " |
|
14672 self key:'HKEY_LOCAL_MACHINE' |
|
14673 self key:'HKEY_LOCAL_MACHINE\Software' |
|
14674 self key:'HKEY_LOCAL_MACHINE\Software\Borland\' |
|
14675 self key:'HKEY_LOCAL_MACHINE\Software\eXept\Smalltalk/X\3.2.5\Directory' |
|
14676 (self key:'HKEY_CLASSES_ROOT\MicrosoftWorks.WordProcessor\CLSID' flags:#KEY_WOW64_64KEY) valueNamed:'' |
14636 " |
14677 " |
14637 |
14678 |
14638 "Created: / 19-01-2011 / 15:59:21 / cg" |
14679 "Created: / 19-01-2011 / 15:59:21 / cg" |
14639 ! |
14680 ! |
14640 |
14681 |
14861 createSubKeyNamed:subKeyString |
14902 createSubKeyNamed:subKeyString |
14862 "create a new key below mySelf and return a new registry entry for it. |
14903 "create a new key below mySelf and return a new registry entry for it. |
14863 If it already exists, return it. |
14904 If it already exists, return it. |
14864 Return nil if the new key cannot be created." |
14905 Return nil if the new key cannot be created." |
14865 |
14906 |
14866 |newEntry subHandle errorNumber| |
14907 ^ self subKeyNamed:subKeyString flags:nil createIfAbsent:true |
14867 |
|
14868 %{ |
|
14869 HKEY myKey, subKey = 0; |
|
14870 int _retVal; |
|
14871 |
|
14872 if (__isExternalAddressLike(__INST(handle)) |
|
14873 && __isStringLike(subKeyString)) { |
|
14874 myKey = (HKEY)__externalAddressVal(__INST(handle)); |
|
14875 if ((_retVal = RegCreateKeyA(myKey, __stringVal(subKeyString), &subKey)) == ERROR_SUCCESS) { |
|
14876 subHandle = __MKEXTERNALADDRESS(subKey); |
|
14877 } else { |
|
14878 if ((_retVal != ERROR_PATH_NOT_FOUND) |
|
14879 && (_retVal != ERROR_FILE_NOT_FOUND)) { |
|
14880 errorNumber = __MKSMALLINT(_retVal); |
|
14881 } |
|
14882 } |
|
14883 } |
|
14884 %}. |
|
14885 subHandle notNil ifTrue:[ |
|
14886 newEntry := self class basicNew |
|
14887 setHandle:subHandle |
|
14888 path:(path , self class separator asString , subKeyString). |
|
14889 newEntry registerForFinalization. |
|
14890 ^ newEntry. |
|
14891 ]. |
|
14892 errorNumber notNil ifTrue:[ |
|
14893 (OperatingSystem errorHolderForNumber:errorNumber) reportError. |
|
14894 ]. |
|
14895 ^ nil |
|
14896 |
14908 |
14897 " |
14909 " |
14898 |top sub| |
14910 |top sub| |
14899 |
14911 |
14900 top := self key:'HKEY_LOCAL_MACHINE'. |
14912 top := self key:'HKEY_CURRENT_USER'. |
14901 sub := top createSubKeyNamed:'FooBarBaz'. |
14913 sub := top createSubKeyNamed:'FooBarBaz'. |
|
14914 " |
|
14915 ! |
|
14916 |
|
14917 createSubKeyNamed:subKeyString flags:flags |
|
14918 "create a new key below mySelf and return a new registry entry for it. |
|
14919 If it already exists, return it. |
|
14920 Return nil if the new key cannot be created. |
|
14921 flags may be one of: |
|
14922 #KEY_WOW64_64KEY to force access to the 64Bit Windows key, |
|
14923 #KEY_WOW64_32KEY to force access to the 32Bit Windows key, |
|
14924 or nil, to access the key (32/64) for the current application" |
|
14925 |
|
14926 |
|
14927 ^ self subKeyNamed:subKeyString flags:flags createIfAbsent:true |
|
14928 |
|
14929 " |
|
14930 |top sub| |
|
14931 |
|
14932 top := self key:'HKEY_CURRENT_USER'. |
|
14933 sub := top createSubKeyNamed:'FooBarBaz' flags:nil. |
14902 " |
14934 " |
14903 ! |
14935 ! |
14904 |
14936 |
14905 deleteSubKeyNamed:subKeyString |
14937 deleteSubKeyNamed:subKeyString |
14906 "delete a key below mySelf. |
14938 "delete a key below mySelf. |
14907 Return true on success." |
14939 Return true on success." |
14908 |
14940 |
14909 |errorNumber| |
14941 ^ self deleteSubKeyNamed:subKeyString flags:nil |
|
14942 |
|
14943 " |
|
14944 |top sub| |
|
14945 |
|
14946 top := self key:'HKEY_CURRENT_USER'. |
|
14947 sub := top createSubKeyNamed:'FooBarBaz'. |
|
14948 top deleteSubKeyNamed:'FooBarBaz'. |
|
14949 " |
|
14950 ! |
|
14951 |
|
14952 deleteSubKeyNamed:subKeyString flags:flags |
|
14953 "delete a key below mySelf. |
|
14954 Return true on success. |
|
14955 flags may be one of: |
|
14956 #KEY_WOW64_64KEY to force access to the 64Bit Windows key, |
|
14957 #KEY_WOW64_32KEY to force access to the 32Bit Windows key, |
|
14958 or nil, to access the key (32/64) for the current application. |
|
14959 |
|
14960 CAVEAT: due to a missing library entry in the BCC system, |
|
14961 the flags are currently ignored" |
|
14962 |
|
14963 |subKeyStringZ errorNumber| |
|
14964 |
|
14965 subKeyStringZ := subKeyString asUnicode16StringZ. |
14910 |
14966 |
14911 %{ |
14967 %{ |
14912 HKEY myKey; |
14968 #ifndef KEY_WOW64_64KEY |
|
14969 // this is missing in BCC header files |
|
14970 # define KEY_WOW64_64KEY 0x0100 |
|
14971 # define KEY_WOW64_32KEY 0x0200 |
|
14972 #endif |
|
14973 |
|
14974 HKEY myKey, subKey = 0; |
14913 int _retVal; |
14975 int _retVal; |
|
14976 int _flags = 0; |
|
14977 |
|
14978 if (flags != nil) { |
|
14979 if (flags == @symbol(KEY_WOW64_64KEY)) { |
|
14980 _flags = KEY_WOW64_64KEY; |
|
14981 } else if (flags == @symbol(KEY_WOW64_32KEY)) { |
|
14982 _flags = KEY_WOW64_32KEY; |
|
14983 } else { |
|
14984 errorNumber = @symbol(badArgument2); |
|
14985 goto out; |
|
14986 } |
|
14987 } |
14914 |
14988 |
14915 if (__isExternalAddressLike(__INST(handle)) |
14989 if (__isExternalAddressLike(__INST(handle)) |
14916 && __isStringLike(subKeyString)) { |
14990 && __isUnicode16String(subKeyStringZ)) { |
14917 myKey = (HKEY)__externalAddressVal(__INST(handle)); |
14991 myKey = (HKEY)__externalAddressVal(__INST(handle)); |
14918 if ((_retVal = RegDeleteKeyA(myKey, __stringVal(subKeyString))) == ERROR_SUCCESS) { |
14992 #ifdef __BORLANDC__ |
14919 RETURN (true); |
14993 _retVal = RegDeleteKeyW(myKey, __unicode16StringVal(subKeyStringZ)); |
14920 } |
14994 #else |
14921 if ((_retVal != ERROR_PATH_NOT_FOUND) |
14995 _retVal = RegDeleteKeyExW(myKey, |
14922 && (_retVal != ERROR_FILE_NOT_FOUND)) { |
14996 __unicode16StringVal(subKeyStringZ), |
14923 errorNumber = __MKSMALLINT(_retVal); |
14997 _flags, |
14924 } |
14998 0); // reserved |
14925 } |
14999 #endif |
|
15000 if (_retVal == ERROR_SUCCESS) { |
|
15001 RETURN (true); |
|
15002 } |
|
15003 if ((_retVal != ERROR_PATH_NOT_FOUND) |
|
15004 && (_retVal != ERROR_FILE_NOT_FOUND)) { |
|
15005 errorNumber = __MKSMALLINT(_retVal); |
|
15006 } |
|
15007 } |
|
15008 out:; |
14926 %}. |
15009 %}. |
|
15010 |
14927 errorNumber notNil ifTrue:[ |
15011 errorNumber notNil ifTrue:[ |
14928 (OperatingSystem errorHolderForNumber:errorNumber) reportError. |
15012 (OperatingSystem errorHolderForNumber:errorNumber) reportError. |
14929 ]. |
15013 ]. |
14930 ^ false |
15014 ^ false |
14931 |
15015 |
14932 " |
15016 " |
14933 |top sub| |
15017 |top sub| |
14934 |
15018 |
14935 top := self key:'HKEY_LOCAL_MACHINE'. |
15019 top := self key:'HKEY_CURRENT_USER'. |
14936 sub := top createSubKeyNamed:'FooBarBaz'. |
15020 sub := top createSubKeyNamed:'FooBarBaz'. |
14937 top deleteSubKeyNamed:'FooBarBaz'. |
15021 top deleteSubKeyNamed:'FooBarBaz' flags:nil. |
14938 " |
15022 " |
14939 ! |
15023 ! |
14940 |
15024 |
14941 remoteKeyOnHost:hostName |
15025 remoteKeyOnHost:hostName |
14942 "return the corresponding registry entry from |
15026 "return the corresponding registry entry from |
15050 |
15134 |
15051 subKeyNamed:subKeyString |
15135 subKeyNamed:subKeyString |
15052 "return a new registry entry below mySelf with the given subKey. |
15136 "return a new registry entry below mySelf with the given subKey. |
15053 Return nil if no such key exists" |
15137 Return nil if no such key exists" |
15054 |
15138 |
15055 |newEntry subHandle errorNumber| |
15139 ^ self subKeyNamed:subKeyString flags:nil createIfAbsent:false |
15056 |
|
15057 %{ |
|
15058 HKEY myKey, subKey = 0; |
|
15059 int _retVal; |
|
15060 |
|
15061 if (__isExternalAddressLike(__INST(handle)) |
|
15062 && __isStringLike(subKeyString)) { |
|
15063 myKey = (HKEY)__externalAddressVal(__INST(handle)); |
|
15064 _retVal = RegOpenKeyA(myKey, __stringVal(subKeyString), &subKey); |
|
15065 if (_retVal == ERROR_SUCCESS) { |
|
15066 subHandle = __MKEXTERNALADDRESS(subKey); |
|
15067 } else { |
|
15068 if ((_retVal != ERROR_PATH_NOT_FOUND) |
|
15069 && (_retVal != ERROR_FILE_NOT_FOUND)) { |
|
15070 errorNumber = __MKSMALLINT(_retVal); |
|
15071 } |
|
15072 } |
|
15073 } |
|
15074 %}. |
|
15075 subHandle notNil ifTrue:[ |
|
15076 newEntry := self class basicNew |
|
15077 setHandle:subHandle |
|
15078 path:((path ? '?') , self class separator asString , subKeyString). |
|
15079 |
|
15080 newEntry registerForFinalization. |
|
15081 ^ newEntry. |
|
15082 ]. |
|
15083 errorNumber notNil ifTrue:[ |
|
15084 (OperatingSystem errorHolderForNumber:errorNumber) reportError. |
|
15085 ]. |
|
15086 ^ nil |
|
15087 |
15140 |
15088 " |
15141 " |
15089 |top sub| |
15142 |top sub| |
15090 |
15143 |
15091 top := self key:'HKEY_LOCAL_MACHINE'. |
15144 top := self key:'HKEY_LOCAL_MACHINE'. |
15096 subKeyNamed:subKeyString createIfAbsent:createIfAbsent |
15149 subKeyNamed:subKeyString createIfAbsent:createIfAbsent |
15097 "return a new registry entry below mySelf with the given subKey. |
15150 "return a new registry entry below mySelf with the given subKey. |
15098 If no such key exists and createIfAbsent is true, the key is created. |
15151 If no such key exists and createIfAbsent is true, the key is created. |
15099 Otherwise, nil is returned" |
15152 Otherwise, nil is returned" |
15100 |
15153 |
15101 |k| |
15154 ^ self subKeyNamed:subKeyString flags:nil createIfAbsent:createIfAbsent |
15102 |
15155 ! |
15103 (k := self subKeyNamed:subKeyString) isNil ifTrue:[ |
15156 |
15104 createIfAbsent ifTrue:[ |
15157 subKeyNamed:subKeyString flags:flags |
15105 ^ self createSubKeyNamed:subKeyString |
15158 "return a new registry entry below mySelf with the given subKey. |
15106 ]. |
15159 Return nil if no such key exists. |
|
15160 flags may be one of: |
|
15161 #KEY_WOW64_64KEY to force access to the 64Bit Windows key, |
|
15162 #KEY_WOW64_32KEY to force access to the 32Bit Windows key, |
|
15163 or nil, to access the key (32/64) for the current application" |
|
15164 |
|
15165 |
|
15166 ^ self subKeyNamed:subKeyString flags:flags createIfAbsent:false |
|
15167 ! |
|
15168 |
|
15169 subKeyNamed:subKeyString flags:flags createIfAbsent:createIfAbsent |
|
15170 "return a new registry entry below mySelf with the given subKey. |
|
15171 If no such key exists and createIfAbsent is true, the key is created. |
|
15172 Otherwise, nil is returned. |
|
15173 flags may be one of: |
|
15174 #KEY_WOW64_64KEY to force access to the 64Bit Windows key, |
|
15175 #KEY_WOW64_32KEY to force access to the 32Bit Windows key, |
|
15176 or nil, to access the key (32/64) for the current application" |
|
15177 |
|
15178 |subKeyStringZ newEntry subHandle errorNumber| |
|
15179 |
|
15180 subKeyStringZ := subKeyString asUnicode16StringZ. |
|
15181 |
|
15182 %{ |
|
15183 #ifndef KEY_WOW64_64KEY |
|
15184 // this is missing in BCC header files |
|
15185 # define KEY_WOW64_64KEY 0x0100 |
|
15186 # define KEY_WOW64_32KEY 0x0200 |
|
15187 #endif |
|
15188 |
|
15189 HKEY myKey, subKey = 0; |
|
15190 int _retVal; |
|
15191 int _flags = 0; |
|
15192 |
|
15193 if (flags != nil) { |
|
15194 if (flags == @symbol(KEY_WOW64_64KEY)) { |
|
15195 _flags = KEY_WOW64_64KEY; |
|
15196 } else if (flags == @symbol(KEY_WOW64_32KEY)) { |
|
15197 _flags = KEY_WOW64_32KEY; |
|
15198 } else { |
|
15199 errorNumber = @symbol(badArgument2); |
|
15200 goto out; |
|
15201 } |
|
15202 } |
|
15203 |
|
15204 if (__isExternalAddressLike(__INST(handle)) |
|
15205 && __isUnicode16String(subKeyStringZ)) { |
|
15206 myKey = (HKEY)__externalAddressVal(__INST(handle)); |
|
15207 if (createIfAbsent == true) { |
|
15208 _retVal = RegCreateKeyExW(myKey, |
|
15209 __unicode16StringVal(subKeyStringZ), |
|
15210 0, // reserved |
|
15211 NULL, // class |
|
15212 0, // options |
|
15213 KEY_READ|_flags, |
|
15214 NULL, // securityAttributes - handle cannot be inherited |
|
15215 &subKey, |
|
15216 NULL); // disposition (created vs. opened) - we are not interested |
|
15217 } else { |
|
15218 _retVal = RegOpenKeyExW(myKey, |
|
15219 __unicode16StringVal(subKeyStringZ), |
|
15220 0, |
|
15221 KEY_READ|_flags, |
|
15222 &subKey); |
|
15223 } |
|
15224 if (_retVal == ERROR_SUCCESS) { |
|
15225 subHandle = __MKEXTERNALADDRESS(subKey); |
|
15226 } else { |
|
15227 if ((_retVal != ERROR_PATH_NOT_FOUND) |
|
15228 && (_retVal != ERROR_FILE_NOT_FOUND)) { |
|
15229 errorNumber = __MKSMALLINT(_retVal); |
|
15230 } |
|
15231 } |
|
15232 } |
|
15233 out:; |
|
15234 %}. |
|
15235 subHandle notNil ifTrue:[ |
|
15236 newEntry := self class basicNew |
|
15237 setHandle:subHandle |
|
15238 path:((path ? '?') , self class separator asString , subKeyString). |
|
15239 |
|
15240 newEntry registerForFinalization. |
|
15241 ^ newEntry. |
15107 ]. |
15242 ]. |
15108 ^ k |
15243 errorNumber notNil ifTrue:[ |
15109 |
15244 (OperatingSystem errorHolderForNumber:errorNumber) reportError. |
15110 "Created: / 19-01-2011 / 15:58:45 / cg" |
15245 ]. |
|
15246 ^ nil |
|
15247 |
|
15248 " |
|
15249 |top sub| |
|
15250 |
|
15251 top := self key:'HKEY_LOCAL_MACHINE'. |
|
15252 sub := top subKeyNamed:'Software' flags:nil createIfAbsent:false |
|
15253 |
|
15254 |top sub| |
|
15255 |
|
15256 top := self key:'HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Development Kit'. |
|
15257 top valueNamed:'CurrentVersion'. |
|
15258 sub := top subKeyNamed:'1.8' flags:#KEY_WOW64_64KEY createIfAbsent:false. |
|
15259 " |
15111 ! ! |
15260 ! ! |
15112 |
15261 |
15113 !Win32OperatingSystem::RegistryEntry methodsFor:'accessing values'! |
15262 !Win32OperatingSystem::RegistryEntry methodsFor:'accessing values'! |
15114 |
15263 |
15115 defaultValue |
15264 defaultValue |