Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

361 lines
13 KiB

  1. <%
  2. '-------------------------------------------------------------------------
  3. ' inc_registry.asp: Includes all the Registry funcitons of stdRegProv
  4. ' Copyright (c) Microsoft Corporation. All rights reserved.
  5. '-------------------------------------------------------------------------
  6. '-------------------------------------------------------------------------
  7. 'Note :When ever you are using these functions in your asp files the
  8. ' localized error messages should be declared in your files
  9. '-------------------------------------------------------------------------
  10. '-----------------------------------------------------------------------------------
  11. 'Start of localization content
  12. '-----------------------------------------------------------------------------------
  13. 'Const L_SERVERCONNECTIONFAIL_ERRORMESSAGE ="Connection Failure"
  14. 'Const L_CANNOTREADFROMREGISTRY_ERRORMESSAGE ="Unable to Read From Registry"
  15. 'Const L_CANNOTUPDATEREGISTRY_ERRORMESSAGE ="Unable to update the Registry"
  16. 'Const L_CANNOTCREATEKEY_ERRORMESSAGE ="Unable to Create key in the Registry"
  17. 'Const L_CANNOTDELETEKEY_ERRORMESSAGE ="Unable to delete the key from the Registry "
  18. '-----------------------------------------------------------------------------------
  19. 'Global variables
  20. '-----------------------------------------------------------------------------------
  21. Const G_HKEY_LOCAL_MACHINE = &H80000002
  22. Const CONST_DWORD = 1
  23. Const CONST_STRING = 2
  24. Const CONST_MULTISTRING = 3
  25. Const CONST_BINARY = 4
  26. Const CONST_EXPANDEDSTRING = 5
  27. '-------------------------------------------------------------------------
  28. 'Function name: RegConnection
  29. 'Description: Returns a handle to the registry
  30. 'Input Variables: None
  31. 'Output Variables: None
  32. 'Returns: Obj-Registry object
  33. 'Global Variables: In:L_(*) -Localized variables
  34. '-------------------------------------------------------------------------
  35. Function RegConnection()
  36. Dim objLocator
  37. Dim objNameSpace
  38. Dim objRegistry
  39. '
  40. ' Clear errors
  41. '
  42. SA_ClearError()
  43. 'Connect to the default namespace on the server
  44. Set objLocator = Server.CreateObject("WbemScripting.SWbemLocator")
  45. Set objNameSpace = objLocator.ConnectServer(".","root\default" )
  46. 'Get the registry handle
  47. Set objRegistry = objNameSpace.Get("StdRegProv")
  48. If Err.number <> 0 Then
  49. 'ServeFailurePage L_SERVERCONNECTIONFAIL_ERRORMESSAGE & "(" & Err.Number & ")" ,mstrReturnURL
  50. ' Set an error
  51. SA_SetLastError Err.Number, "RegConnection"
  52. Set RegConnection = nothing
  53. Else
  54. 'return the registry
  55. set RegConnection = objRegistry
  56. End If
  57. End Function
  58. '-------------------------------------------------------------------------
  59. 'Function name: RegEnumKey
  60. 'Description: Gets the Subkeys in the given Key
  61. 'Input Variables: objRegistryHandle- reference to the registry
  62. ' strPath - Key path
  63. 'Output Variables: None
  64. 'Returns: arrStr -Returns an array containing sub keys
  65. 'Global Variables: In:L_(*) -Localized variables
  66. '-------------------------------------------------------------------------
  67. Function RegEnumKey(objRegistryHandle,strPath)
  68. Dim arrSubNames()
  69. Dim intReturnCode
  70. '
  71. ' Clear errors
  72. '
  73. SA_ClearError()
  74. intReturnCode = objRegistryHandle.EnumKey(G_HKEY_LOCAL_MACHINE, strPath, arrSubNames)
  75. If Err.number <> 0 or intReturnCode <> 0 Then
  76. 'ServeFailurePage L_CANNOTREADFROMREGISTRY_ERRORMESSAGE & "(" & Hex(Err.Number) & ")"
  77. ' Set an error
  78. SA_SetLastError Err.Number, "RegEnumKey"
  79. RegEnumKey = nothing
  80. Else
  81. RegEnumKey = arrSubNames
  82. End If
  83. End Function
  84. '-------------------------------------------------------------------------
  85. 'Function name: RegEnumValues
  86. 'Description: Gets the values in the given SubKey
  87. 'Input Variables: strPath - Sub Key path
  88. ' objRegistryHandle- reference to the registry
  89. 'Output Variables: None
  90. 'Returns: arrStr -Returns an array containing sub keys
  91. 'Global Variables: In:G_HKEY_LOCAL_MACHINE- Machine Const
  92. ' In:L_(*) -Localized variables
  93. '-------------------------------------------------------------------------
  94. Function RegEnumKeyValues(objRegistryHandle,strPath)
  95. Dim arrKeyNames()
  96. Dim arrDataTypes()
  97. Dim intReturnCode
  98. '
  99. ' Clear errors
  100. '
  101. SA_ClearError()
  102. intReturnCode = objRegistryHandle.Enumvalues(G_HKEY_LOCAL_MACHINE, strPath, arrKeyNames,arrDataTypes)
  103. If Err.number <> 0 or intReturnCode <> 0 Then
  104. 'ServeFailurePage L_CANNOTREADFROMREGISTRY_ERRORMESSAGE & "(" & Hex(Err.Number)&Err.description & ")" ,mstrReturnURL
  105. SA_SetLastError Err.Number, "RegEnumKeyValues"
  106. RegEnumKeyValues = nothing
  107. Else
  108. RegEnumKeyValues = arrKeyNames
  109. End If
  110. End Function
  111. '-------------------------------------------------------------------------
  112. 'Function name: getRegkeyvalue
  113. 'Description: gets the value in the registry for a given value
  114. 'Input Variables: In-strSubKey ->relative path to the subkey
  115. ' In-strKeyName -> KeyName in the sub key
  116. ' In-objRegistryHandle - refernce to the registry
  117. ' In-intDataType - datatype of the registry key
  118. 'Output Variables:
  119. 'Returns: Variant-the value of the requested key or an empty string
  120. ' if the key did key value did not exist.
  121. 'Global Variables: In:G_HKEY_LOCAL_MACHINE- Machine Const
  122. ' In:L_(*) -Localized variables
  123. 'intDataType may be of any of the following values depending on the input
  124. 'the corresponding function is executed and returns the value
  125. ' 1------->DWORD
  126. ' 2------->STRING
  127. ' 3------->MULTISTRING
  128. ' 4------->binary
  129. ' 5------->Expanded String
  130. '-------------------------------------------------------------------------
  131. Function GetRegKeyValue(objRegistryHandle,strSubKey,strKeyName,intDataType)
  132. Dim iRc
  133. Dim strKeyValue
  134. '
  135. ' Clear errors
  136. '
  137. SA_ClearError()
  138. Select Case intDataType
  139. Case CONST_DWORD
  140. iRc = objRegistryHandle.GetDWORDValue(G_HKEY_LOCAL_MACHINE,_
  141. strSubKey,_
  142. strKeyName,_
  143. strKeyValue)
  144. Case CONST_STRING
  145. iRc = objRegistryHandle.GetStringValue(G_HKEY_LOCAL_MACHINE,_
  146. strSubKey,_
  147. strKeyName,_
  148. strKeyValue)
  149. Case CONST_MULTISTRING
  150. iRc = objRegistryHandle.GetMultiStringValue(G_HKEY_LOCAL_MACHINE,_
  151. strSubKey,_
  152. strKeyName,_
  153. strKeyValue)
  154. Case CONST_BINARY
  155. iRc = objRegistryHandle.GetBinaryValue(G_HKEY_LOCAL_MACHINE,_
  156. strSubKey,_
  157. strKeyName,_
  158. strKeyValue)
  159. Case CONST_EXPANDEDSTRING
  160. iRc = objRegistryHandle.GetExpandedStringValue(G_HKEY_LOCAL_MACHINE,_
  161. strSubKey,_
  162. strKeyName,_
  163. strKeyValue)
  164. Case Else
  165. SA_TraceErrorOut "GetRegKeyValue", "Invalid data type parameter: " + CStr(intDataType)
  166. ' Unknown case
  167. End Select
  168. If Err.number <> 0 Then
  169. SA_SetLastError Err.Number, "GetRegKeyValue( objReg, " & strSubKey & ", " & strKeyName & " ) Failed"
  170. GetRegKeyValue = ""
  171. ElseIf iRc <> 0 Then
  172. SA_SetLastError Err.Number, "GetRegKeyValue( objReg, " & strSubKey & ", " & strKeyName & " ) Failed"
  173. GetRegKeyValue = ""
  174. Else
  175. GetRegKeyValue = strKeyValue
  176. End If
  177. End Function
  178. '-------------------------------------------------------------------------
  179. 'Function name: updateRegkeyvalue
  180. 'Description: Sets the value in the registry for a given key
  181. 'Input Variables: In-strSubKey ->relative path to the subkey
  182. ' In-strKeyName -> KeyName in the sub key
  183. ' In-objRegistryHandle - refernce to the registry
  184. ' In-intValuetoSet - The value of the key to be updated
  185. ' In-intDataType - datatype of the registry key
  186. 'Output Variables: None
  187. 'Returns: int-The Error code
  188. 'Global Variables: In:G_HKEY_LOCAL_MACHINE- Machine Const
  189. ' In:L_(*) -Localized variables
  190. 'intDataType may be of any of the following values depending on the input
  191. 'the corresponding function is executed and returns the value
  192. ' 1------->DWORD
  193. ' 2------->STRING
  194. ' 3------->MULTISTRING
  195. ' 4------->binary
  196. ' 5------->Expanded String
  197. '-------------------------------------------------------------------------
  198. Function updateRegkeyvalue(objRegistryHandle,strSubKey,strKeyName,intValuetoSet,intDataType)
  199. '
  200. ' Clear errors
  201. '
  202. SA_ClearError()
  203. Dim intReturnCode
  204. updateRegkeyvalue = FALSE
  205. 'To Set DWORD value
  206. If intDataType = CONST_DWORD Then
  207. intReturnCode = objRegistryHandle.SetDWORDValue(G_HKEY_LOCAL_MACHINE, strSubKey,strKeyName,intValuetoSet)
  208. 'To Set String value
  209. Elseif intDataType = CONST_STRING Then
  210. intReturnCode = objRegistryHandle.SetStringValue(G_HKEY_LOCAL_MACHINE, strSubKey,strKeyName,intValuetoSet)
  211. 'To Set MultiString value
  212. Elseif intDataType = CONST_MULTISTRING Then
  213. intReturnCode = objRegistryHandle.SetMultiStringValue(G_HKEY_LOCAL_MACHINE, strSubKey,strKeyName,intValuetoSet)
  214. 'To Set Binary value
  215. Elseif intDataType = CONST_BINARY Then
  216. intReturnCode = objRegistryHandle.SetBinaryValue(G_HKEY_LOCAL_MACHINE, strSubKey,strKeyName,intValuetoSet)
  217. 'To Set ExpandedString value
  218. Elseif intDataType = CONST_EXPANDEDSTRING Then
  219. intReturnCode = objRegistryHandle.SetExpandedStringValue(G_HKEY_LOCAL_MACHINE, strSubKey,strKeyName,intValuetoSet)
  220. End if
  221. If Err.number <> 0 or intReturnCode <>0 Then
  222. 'ServeFailurePage L_CANNOTUPDATEREGISTRY_ERRORMESSAGE & "(" & Hex(Err.Number) &intReturnCode&strSubKey&strKeyName& ")",mstrReturnURL
  223. SA_SetLastError Err.Number, "updateRegkeyvalue"
  224. Else
  225. updateRegkeyvalue = TRUE
  226. End If
  227. End Function
  228. '-------------------------------------------------------------------------
  229. 'Function name: RegCreateKey
  230. 'Description: Creates a key in the registry
  231. 'Input Variables: In-objRegistryHandle -> reference to the registry
  232. ' In-strKeyName - Sub KeyName
  233. 'Output Variables: None
  234. 'Returns: Int -Error code
  235. 'Global Variables: In:G_HKEY_LOCAL_MACHINE- Machine Const
  236. ' In:L_(*) -Localized variables
  237. '-------------------------------------------------------------------------
  238. Function RegCreateKey(objRegistryHandle,strKeyName)
  239. RegCreateKey = FALSE
  240. '
  241. ' Clear errors
  242. '
  243. SA_ClearError()
  244. Dim intReturnCode
  245. intReturnCode = objRegistryHandle.createKey(G_HKEY_LOCAL_MACHINE, strKeyName)
  246. If Err.number <> 0 or intReturnCode <>0 then
  247. 'ServeFailurePage L_CANNOTCREATEKEY_ERRORMESSAGE & "(" & Hex(Err.Number) & ")",mstrReturnURL
  248. SA_SetLastError Err.Number, "RegCreateKey"
  249. Else
  250. RegCreateKey = TRUE
  251. End If
  252. End Function
  253. '-------------------------------------------------------------------------
  254. 'Function name: RegDeleteKey
  255. 'Description: Deletes the given subkey
  256. 'Input Variables: In-objRegistryHandle -> reference to the registry
  257. ' In-strKeyName - Sub KeyName
  258. 'Output Variables: None
  259. 'Returns: Int -Error code
  260. 'Global Variables: In:G_HKEY_LOCAL_MACHINE- Machine Const
  261. ' In:L_(*) -Localized variables
  262. '-------------------------------------------------------------------------
  263. Function RegDeleteKey(objRegistryHandle,strKeyName)
  264. RegDeleteKey = FALSE
  265. '
  266. ' Clear errors
  267. '
  268. SA_ClearError()
  269. Dim intReturnCode
  270. intReturnCode = objRegistryHandle.deleteKey(G_HKEY_LOCAL_MACHINE, strKeyName)
  271. If Err.number <> 0 or intReturnCode <>0 Then
  272. 'ServeFailurePage L_CANNOTDELETEKEY_ERRORMESSAGE & "(" & Hex(Err.Number) & ")",mstrReturnURL
  273. SA_SetLastError Err.Number, "RegDeleteKey"
  274. Else
  275. RegDeleteKey = TRUE
  276. End If
  277. End Function
  278. '-------------------------------------------------------------------------
  279. 'Function name: RegDeleteValue
  280. 'Description: Deletes the given key value
  281. 'Input Variables: In-strSubKeyName - sub key name
  282. ' In-strKeyName - KeyName in the sub key
  283. 'Output Variables: None
  284. 'Returns: Int -Error code
  285. 'Global Variables: In:G_HKEY_LOCAL_MACHINE- Machine Const
  286. ' In:L_(*) -Localized variables
  287. '-------------------------------------------------------------------------
  288. Function RegDeleteValue(objRegistryHandle,strSubKeyName,strKeyName)
  289. RegDeleteValue = FALSE
  290. '
  291. ' Clear errors
  292. '
  293. SA_ClearError()
  294. Dim intReturnCode
  295. intReturnCode = objRegistryHandle.deleteValue(G_HKEY_LOCAL_MACHINE, strSubKeyName,strKeyName)
  296. If Err.number <> 0 or intReturnCode <>0 then
  297. 'ServeFailurePage L_CANNOTDELETEKEY_ERRORMESSAGE & "(" & Hex(Err.Number) & ")" ,mstrReturnURL
  298. SA_SetLastError Err.Number, "RegDeleteValue"
  299. Else
  300. RegDeleteValue = TRUE
  301. End If
  302. End Function
  303. %>