Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for reg2scr.vbs

(view source code of reg2scr.vbs as plain text)

  1. Option Explicit
  2.  
  3. Dim intCounter, intRC, intArgs
  4. Dim objFile, objFSO
  5. Dim strComment, strComputer, strDisclaimer, strFile, strKey, strVersion
  6.  
  7. strVersion  = "0.0.2 alpha"
  8. strComment  = ""
  9. intCounter  = 0
  10.  
  11. With WScript.Arguments
  12. 	intArgs = 0
  13. 	If .Unnamed.Count > 0 Then Syntax
  14. 	If .Named.Count   < 2 Then Syntax
  15. 	If .Named.Exists( "C" ) Then
  16. 		strComputer = .Named.Item( "C" )
  17. 		intArgs     = intArgs + 1
  18. 		If Trim( strComputer ) = "" Then Syntax
  19. 	Else
  20. 		strComputer = "."
  21. 	End If
  22. 	If .Named.Exists( "F" ) Then
  23. 		strFile = .Named.Item( "F" )
  24. 		intArgs = intArgs + 1
  25. 		If Trim( strFile ) = "" Then Syntax
  26. 	End If
  27. 	If .Named.Exists( "R" ) Then
  28. 		strKey  = .Named.Item( "R" )
  29. 		intArgs = intArgs + 1
  30. 		If Trim( strKey ) = "" Then Syntax
  31. 		If Left( UCase( strKey ), 5 ) <> "HKEY_" Then Syntax
  32. 		If InStr( strKey, "\" ) = 0 Then Syntax
  33. 	End If
  34. 	If .Named.Count <> intArgs Then Syntax
  35. End With
  36.  
  37. intRC = ConvertReg( strKey, strFile )
  38.  
  39. WScript.Quit intRC
  40.  
  41.  
  42. Function ConvertReg( myRegPath, myFileName )
  43. ' This subroutine will read the specified registry key FROM any machine and
  44. ' create KiXtart and VBScript scripts to RECREATE this key on any other machine
  45. 	ConvertReg = 1
  46. 	intCounter = intCounter + 1
  47.  
  48. 	Dim arrHives, arrKey, arrSubKeys, arrTypes, arrValueNames, arrValueTypes
  49. 	Dim blnValid, blnWriteDisclaimer
  50. 	Dim i, intHive, intRC
  51. 	Dim objFSO, objReg, objKiXtartFile, objVBScriptFile
  52. 	Dim strFileName, strHeader, strKiXtartFile, strLine, strValue, strVBScriptFile
  53. 	Dim varValue
  54.  
  55. 	' Hive constants
  56. 	Const HKEY_CLASSES_ROOT   = &H80000000
  57. 	Const HKEY_CURRENT_USER   = &H80000001
  58. 	Const HKEY_LOCAL_MACHINE  = &H80000002
  59. 	Const HKEY_USERS          = &H80000003
  60. 	Const HKEY_CURRENT_CONFIG = &H80000005
  61. 	Const HKEY_DYN_DATA       = &H80000006 ' Windows 95/98 only
  62.  
  63. 	' Array to convert constants' values back to their names
  64. 	arrHives = Array( "HKEY_CLASSES_ROOT",   _
  65. 	                  "HKEY_CURRENT_USER",   _
  66. 	                  "HKEY_LOCAL_MACHINE",  _
  67. 	                  "HKEY_USERS",          _
  68. 	                  "",                    _
  69. 	                  "HKEY_CURRENT_CONFIG", _
  70. 	                  "HKEY_DYN_DATA"        )
  71.  
  72. 	' Value types constants
  73. 	Const REG_SZ                         =  1
  74. 	Const REG_EXPAND_SZ                  =  2
  75. 	Const REG_BINARY                     =  3
  76. 	Const REG_DWORD                      =  4
  77. 	Const REG_DWORD_BIG_ENDIAN           =  5 ' Handled like ordinary DWORD
  78. 	Const REG_LINK                       =  6 ' Not supported by this script
  79. 	Const REG_MULTI_SZ                   =  7
  80. 	Const REG_RESOURCE_LIST              =  8 ' Not supported by this script
  81. 	Const REG_FULL_RESOURCE_DESCRIPTOR   =  9 ' Not supported by this script
  82. 	Const REG_RESOURCE_REQUIREMENTS_LIST = 10 ' Not supported by this script
  83. 	Const REG_QWORD                      = 11 ' Windows Vista/Server 2008 only, not supported by this script
  84.  
  85. 	' Array to convert constants' values back to their names
  86. 	arrTypes = Array( "",                               _
  87. 	                  "REG_SZ",                         _
  88. 	                  "REG_EXPAND_SZ",                  _
  89. 	                  "REG_BINARY",                     _
  90. 	                  "REG_DWORD",                      _
  91. 	                  "REG_DWORD_BIG_ENDIAN",           _
  92. 	                  "REG_LINK",                       _
  93. 	                  "REG_MULTI_SZ",                   _
  94. 	                  "REG_RESOURCE_LIST",              _
  95. 	                  "REG_FULL_RESOURCE_DESCRIPTOR",   _
  96. 	                  "REG_RESOURCE_REQUIREMENTS_LIST", _
  97. 	                  "REG_QWORD"                       )
  98.  
  99. 	' I/O mode constants
  100. 	Const ForReading   = 1
  101. 	Const ForWriting   = 2
  102. 	Const ForAppending = 8
  103.  
  104. 	' ASCII/Unicode constants
  105. 	Const TristateUseDefault = -2
  106. 	Const TristateMixed      = -2
  107. 	Const TristateTrue       = -1
  108. 	Const TristateFalse      =  0
  109.  
  110. 	' Split specified registry path into the hive name and the rest
  111. 	arrKey = Split( myRegPath, "\", 2 )
  112. 	' Check if the specified key is valid
  113. 	If Not IsArray( arrkey ) Then Exit Function
  114. 	If UBound( arrkey ) <> 1 Then Exit Function
  115. 	blnValid = False
  116. 	For i = 0 To UBound( arrHives )
  117. 		If arrHives(i) = UCase( arrKey(0) ) Then
  118. 			intHive  = &H80000000 + i
  119. 			blnValid = True
  120. 		End If
  121. 	Next
  122. 	If Not blnValid Then Exit Function
  123.  
  124. 	' Read the specified file name, strip its extension
  125. 	Set objFSO = CreateObject( "Scripting.FileSystemObject" )
  126. 	With objFSO
  127. 		strFileName = .BuildPath( .GetParentFolderName( myFileName ), .GetBaseName( myFileName ) )
  128. 	End With
  129. 	' Append extensions for the scripts to be generated
  130. 	strKiXtartFile  = strFileName & ".kix"
  131. 	strVBScriptFile = strFileName & ".vbs"
  132. 	strHeader       = WriteHeader( "KiXtart" )
  133. 	' Open the existing files or create new ones, and
  134. 	' write a header if the files don't already have one
  135. 	If objFSO.FileExists( strKiXtartFile ) Then
  136. 		blnWriteDisclaimer = True
  137. 		Set objKiXtartFile = objFSO.OpenTextFile( strKiXtartFile, ForReading,   False )
  138. 		If InStr( objKiXtartFile.ReadAll, strDisclaimer ) > 0 Then blnWriteDisclaimer = False
  139. 		objKiXtartFile.Close
  140. 		Set objKiXtartFile = Nothing
  141. 		Set objKiXtartFile = objFSO.OpenTextFile( strKiXtartFile, ForAppending, False, TristateFalse )
  142. 		If blnWriteDisclaimer Then objKiXtartFile.Write vbCrLf & vbCrLf & strHeader
  143. 	Else
  144. 		Set objKiXtartFile = objFSO.OpenTextFile( strKiXtartFile, ForWriting,   True,  TristateFalse )
  145. 		objKiXtartFile.Write strHeader
  146. 	End If
  147. 	strHeader = WriteHeader( "VBScript" )
  148. 	If objFSO.FileExists( strVBScriptFile ) Then
  149. 		blnWriteDisclaimer = True
  150. 		Set objVBScriptFile = objFSO.OpenTextFile( strVBScriptFile, ForReading,   False )
  151. 		If InStr( objVBScriptFile.ReadAll, strDisclaimer ) > 0 Then blnWriteDisclaimer = False
  152. 		objVBScriptFile.Close
  153. 		Set objVBScriptFile = Nothing
  154. 		Set objVBScriptFile = objFSO.OpenTextFile( strVBScriptFile, ForAppending, False, TristateFalse )
  155. 		If blnWriteDisclaimer Then objVBScriptFile.Write vbCrLf & vbCrLf & strHeader
  156. 	Else
  157. 		Set objVBScriptFile = objFSO.OpenTextFile( strVBScriptFile, ForWriting,   True,  TristateFalse )
  158. 		objVBScriptFile.Write strHeader
  159. 	End If
  160.  
  161. 	' Connect to the registry on the specified computer
  162. 	Set objReg = GetObject( "winmgmts:{impersonationLevel=impersonate}!//" & strComputer & "/root/default:StdRegProv" )
  163.  
  164. 	' Read all values in the specified registry key
  165. 	objReg.EnumValues intHive, arrKey(1), arrValueNames, arrValueTypes
  166.  
  167. 	' If no values were found, add an (empty) default value
  168. 	If IsNull( arrValueNames ) Then
  169. 		arrValueNames = Array( "" )
  170. 		arrValueTypes = Array( REG_SZ )
  171. 	End If
  172.  
  173. 	' Add the results to the scripts
  174. 	objKiXtartFile.WriteLine  vbCrLf & "$RC = $objReg.CreateKey( $" _
  175. 	                        & arrHives( intHive - &H80000000 ) _
  176. 	                        & ", """ & arrKey(1) & """ )" & vbCrLf
  177. 	objVBScriptFile.WriteLine vbCrLf & "intRC = objReg.CreateKey( " _
  178. 	                        & arrHives( intHive - &H80000000 ) _
  179. 	                        & ", """ & arrKey(1) & """ )" & vbCrLf
  180.  
  181. 	' Convert each value into KiXtart and VBScript code
  182. 	For i = 0 To UBound( arrValueNames )
  183. 		' The code for each value type differs only slightly
  184. 		Select Case arrValueTypes(i)
  185. 			Case REG_SZ
  186. 				' Read the registry value(s)
  187. 				objReg.GetStringValue intHive, arrKey(1), arrValueNames(i), varValue
  188. 				' Write the code to RECREATE those values
  189. 				objKiXtartFile.WriteLine  "$RC = $objReg.SetStringValue( $" _
  190. 				                        & arrHives( intHive - &H80000000 ) & ", """ _
  191. 				                        & arrKey(1) & """, """ & arrValueNames(i) _
  192. 				                        & """, """ & varValue & """ )"
  193. 				objVBScriptFile.WriteLine "intRC = objReg.SetStringValue( " _
  194. 				                        & arrHives( intHive - &H80000000 ) & ", """ _
  195. 				                        & arrKey(1) & """, """ & arrValueNames(i) _
  196. 				                        & """, """ & varValue & """ )"
  197. 			Case REG_EXPAND_SZ
  198. 				' Read the registry value(s)
  199. 				objReg.GetExpandedStringValue intHive, arrKey(1), arrValueNames(i), varValue
  200. 				' Write the code to RECREATE those values
  201. 				objKiXtartFile.WriteLine  "$RC = $objReg.SetExpandedStringValue( $" _
  202. 				                        & arrHives( intHive - &H80000000 ) & ", """ _
  203. 				                        & arrKey(1) & """, """ & arrValueNames(i) _
  204. 				                        & """, """ & varValue & """ )"
  205. 				objVBScriptFile.WriteLine "intRC = objReg.SetExpandedStringValue( " _
  206. 				                        & arrHives( intHive - &H80000000 ) & ", """ _
  207. 				                        & arrKey(1) & """, """ & arrValueNames(i) _
  208. 				                        & """, """ & varValue & """ )"
  209. 				' Add a comment/warning note
  210. 				strComment = strComment _
  211. 				           & "' Value """ & myRegPath & "\" & arrValueNames(i) _
  212. 				           & """ is of type REG_EXPAND_SZ; it was expanded on the source computer," _
  213. 				           & " and might not be correct on the target computer" & vbCrLf
  214. 			Case REG_BINARY
  215. 				' Read the registry value(s)
  216. 				objReg.GetBinaryValue intHive, arrKey(1), arrValueNames(i), varValue
  217. 				' Write the code to RECREATE those values
  218. 				objKiXtartFile.WriteLine  vbCrLf & "$arrBinaryValue = " _
  219. 				                        & Join( varValue, "," ) & vbCrLf _
  220. 				                        & "$RC = $objReg.SetBinaryValue( $" _
  221. 				                        & arrHives( intHive - &H80000000 ) & ", """ _
  222. 				                        & arrKey(1) & """, """ & arrValueNames(i) _
  223. 				                        & """, $arrBinaryValue )"
  224. 				objVBScriptFile.WriteLine "intRC = objReg.SetBinaryValue( " _
  225. 				                        & arrHives( intHive - &H80000000 ) & ", """ _
  226. 				                        & arrKey(1) & """, """ & arrValueNames(i) _
  227. 				                        & """, Array( " & Join( varValue, "," ) & " ) )"
  228. 			Case REG_DWORD, REG_DWORD_BIG_ENDIAN
  229. 				' Read the registry value(s)
  230. 				objReg.GetDWORDValue intHive, arrKey(1), arrValueNames(i), varValue
  231. 				' Write the code to RECREATE those values
  232. 				objKiXtartFile.WriteLine  "$RC = $objReg.SetDWORDValue( $" _
  233. 				                        & arrHives( intHive - &H80000000 ) & ", """ _
  234. 				                        & arrKey(1) & """, """ & arrValueNames(i) _
  235. 				                        & """, " & varValue & " )"
  236. 				objVBScriptFile.WriteLine "intRC = objReg.SetDWORDValue( " _
  237. 				                        & arrHives( intHive - &H80000000 ) & ", """ _
  238. 				                        & arrKey(1) & """, """ & arrValueNames(i) _
  239. 				                        & """, " & varValue & " )"
  240. 			Case REG_MULTI_SZ
  241. 				' Read the registry value(s)
  242. 				objReg.GetMultiStringValue intHive, arrKey(1), arrValueNames(i), varValue
  243. 				' Escape doublequotes, dollar signs and "at" signs for KiXtart
  244. 				strValue = ""
  245. 				For Each strLine In varValue
  246. 					If InStr( strLine, "'" ) Then
  247. 						strComment = strComment _
  248. 						           & "' Single quotes were found in REG_MULTI_SZ value """ _
  249. 						           & myRegPath & "\" & arrValueNames(i) _
  250. 						           & """ (may cause problems in KiXtart)" & vbCrLf
  251. 					End If
  252. 					strValue = strValue & ",'" & strLine & "'"
  253. 				Next
  254. 				strValue = Mid( strValue, 2 )
  255. 				' Write the code to RECREATE those registry values
  256. 				objKiXtartFile.WriteLine  vbCrLf & "$arrMultiStringValue = " _
  257. 				                        & strValue & vbCrLf _
  258. 				                        & "$RC = $objReg.SetMultiStringValue( $" _
  259. 				                        & arrHives( intHive - &H80000000 ) & ", """ _
  260. 				                        & arrKey(1) & """, """ & arrValueNames(i) _
  261. 				                        & """, $arrMultiStringValue )"
  262. 				' Escape doublequotes for VBScript
  263. 				strValue = ""
  264. 				For Each strLine In varValue
  265. 					strValue = strValue & ",""" & Replace( strLine, """", """""" ) & """"
  266. 				Next
  267. 				strValue = Mid( strValue, 2 )
  268. 				' Write the code to RECREATE those registry values
  269. 				objVBScriptFile.WriteLine "intRC = objReg.SetMultiStringValue( " _
  270. 				                        & arrHives( intHive - &H80000000 ) & ", """ _
  271. 				                        & arrKey(1) & """, """ & arrValueNames(i) _
  272. 				                        & """, Array( " & strValue & " ) )"
  273. 			Case REG_LINK, REG_RESOURCE_LIST, REG_FULL_RESOURCE_DESCRIPTOR, REG_RESOURCE_REQUIREMENTS_LIST, REG_QWORD
  274. 				' Add a comment/warning note
  275. 				strComment = strComment _
  276. 				           & "' Registry value """ & myRegPath & "\" & arrValueNames(i) _
  277. 				           & """ is of a valid type (" & arrValueTypes(i) _
  278. 				           & "), but this type is not supported by Reg2Scr.vbs." & vbCrLf
  279. 			Case Else
  280. 				' Add a comment/warning note
  281. 				strComment = strComment _
  282. 				           & "' Registry value """ & myRegPath & "\" & arrValueNames(i) _
  283. 				           & """ is of unknown type (" & i  & ")" & vbCrLf
  284. 		End Select
  285. 	Next
  286.  
  287. 	' Close the files
  288. 	objKiXtartFile.Close
  289. 	objVBScriptFile.Close
  290. 	Set objKiXtartFile  = Nothing
  291. 	Set objVBScriptFile = Nothing
  292.  
  293. 	' Recurse through the subkeys
  294. 	objReg.EnumKey intHive, arrKey(1), arrSubKeys
  295. 	If IsArray( arrSubKeys ) Then
  296. 		For i = 0 To UBound( arrSubKeys )
  297. 			intRC = ConvertReg( myRegPath & "\" & arrSubKeys(i), myFileName )
  298. 		Next
  299. 	End If
  300.  
  301. 	' Once we're back at the end of the first iteration,
  302. 	' we'll append the comments/warning notes to the scripts
  303. 	intCounter = intCounter - 1
  304. 	If intCounter = 0 Then
  305. 		WScript.Echo "Done. Two scripts have been generated:" & vbCrLf & vbCrLf _
  306. 		           & vbTab & """" & strKiXtartFile & """" & vbCrLf & vbCrLf _
  307. 		           & "and" & vbCrLf & vbCrLf _
  308. 		           & vbTab & """" & strVBScriptFile & """" & vbCrLf
  309. 		If strComment <> "" Then
  310. 			' Write the comments/warning notes
  311. 			WScript.Echo "Please read the NOTES AND WARNINGS at the end of the generated code!"
  312. 			strComment = vbCrLf     & vbCrLf     & vbCrLf _
  313. 			           & "' NOTES AND WARNINGS:" & vbCrLf _
  314. 			           & "' ===================" & vbCrLf _
  315. 			           & strComment              & vbCrLf
  316. 			Set objVBScriptFile = objFSO.OpenTextFile( strVBScriptFile, ForAppending, False, TristateFalse )
  317. 			objVBScriptFile.Write strComment
  318. 			objVBScriptFile.Close
  319. 			Set objVBScriptFile = Nothing
  320. 			strComment = Replace( strComment, "' ", "; " )
  321. 			Set objKiXtartFile = objFSO.OpenTextFile( strKiXtartFile, ForAppending, False, TristateFalse )
  322. 			objKiXtartFile.Write strComment
  323. 			objKiXtartFile.Close
  324. 			Set objKiXtartFile = Nothing
  325. 		End If
  326. 	End If
  327.  
  328. 	Set objFSO = Nothing
  329. 	Set objReg = Nothing
  330. 	ConvertReg = 0
  331. End Function
  332.  
  333.  
  334. Function WriteHeader( myScriptLanguage )
  335. 	strDisclaimer = "' Disclaimer: Though I did my best to provide error free code,"  & vbCrLf _
  336. 	              & "'             I cannot guarantee that the code generated by"     & vbCrLf _
  337. 	              & "'             Reg2Scr.vbs will work on your system(s)."          & vbCrLf _
  338. 	              & "'             This script is generated without any human"        & vbCrLf _
  339. 	              & "'             intervention, and is designed to modify the"       & vbCrLf _
  340. 	              & "'             registry, which is always risky."                  & vbCrLf _
  341. 	              & "'             This script does not check for runtime errors,"    & vbCrLf _
  342. 	              & "'             but you can easily add your own error checking."   & vbCrLf _
  343. 	              & "'             USE THIS SCRIPT AT YOUR OWN RISK, AND ONLY IF"     & vbCrLf _
  344. 	              & "'             YOU FULLY UNDERSTAND ITS IMPLICATIONS!"            & vbCrLf _
  345. 	              & "'             Test this script thoroughly before using it in"    & vbCrLf _
  346. 	              & "'             a production environment."                         & vbCrLf _
  347. 	              & "'             Always have a verified full backup ready before"   & vbCrLf _
  348. 	              & "'             using ANY script that modifies the registry."      & vbCrLf _
  349. 	              & "'             CHECK FOR NOTES AND WARNINGS END OF THE GENERATED" & vbCrLf _
  350. 	              & "'             CODE: IF REG2SCR.VBS DETECTED ANY ""ANOMALITIES""" & vbCrLf _
  351. 	              & "'             WHILE GENERATING THIS SCRIPT, IT WILL LEAVE A"     & vbCrLf _
  352. 	              & "'             SHORT DESCRIPTION THERE!"                          & vbCrLf
  353. 	Select Case LCase( myScriptLanguage )
  354. 		Case "vbscript"
  355. 			WriteHeader = "' VBScript generated with Reg2Scr.vbs,  Version " & strVersion  & vbCrLf _
  356. 			            & "' by Rob van der Woude, http://www.robvanderwoude.com" & vbCrLf & vbCrLf _
  357. 			            & strDisclaimer     & vbCrLf _
  358. 			            & "Option Explicit" & vbCrLf & vbCrLf _
  359. 			            & "Const HKEY_CLASSES_ROOT   = &H80000000" & vbCrLf _
  360. 			            & "Const HKEY_CURRENT_USER   = &H80000001" & vbCrLf _
  361. 			            & "Const HKEY_LOCAL_MACHINE  = &H80000002" & vbCrLf _
  362. 			            & "Const HKEY_USERS          = &H80000003" & vbCrLf _
  363. 			            & "Const HKEY_CURRENT_CONFIG = &H80000005" & vbCrLf _
  364. 			            & "Const HKEY_DYN_DATA       = &H80000006" & vbCrLf & vbCrLf _
  365. 			            & "Const REG_SZ                         =  1" & vbCrLf _
  366. 			            & "Const REG_EXPAND_SZ                  =  2" & vbCrLf _
  367. 			            & "Const REG_BINARY                     =  3" & vbCrLf _
  368. 			            & "Const REG_DWORD                      =  4" & vbCrLf _
  369. 			            & "Const REG_DWORD_BIG_ENDIAN           =  5" & vbCrLf _
  370. 			            & "Const REG_LINK                       =  6" & vbCrLf _
  371. 			            & "Const REG_MULTI_SZ                   =  7" & vbCrLf _
  372. 			            & "Const REG_RESOURCE_LIST              =  8" & vbCrLf _
  373. 			            & "Const REG_FULL_RESOURCE_DESCRIPTOR   =  9" & vbCrLf _
  374. 			            & "Const REG_RESOURCE_REQUIREMENTS_LIST = 10" & vbCrLf _
  375. 			            & "Const REG_QWORD                      = 11" & vbCrLf & vbCrLf _
  376. 			            & "Dim intRC, objReg, strComputer"   & vbCrLf & vbCrLf _
  377. 			            & "strComputer = ""."""     & vbCrLf & vbCrLf _
  378. 			            & "Set objReg = GetObject( ""winmgmts:{impersonationLevel=impersonate}" _
  379. 			            & "!//"" & strComputer & ""/root/default:StdRegProv"" )" & vbCrLf
  380. 		Case "kixtart"
  381. 			strDisclaimer = Replace( strDisclaimer, "'", ";" )
  382. 			WriteHeader = "; KiXtart code generated with Reg2Scr.vbs,  Version "  & strVersion & vbCrLf _
  383. 			            & "; by Rob van der Woude, http://www.robvanderwoude.com" & vbCrLf & vbCrLf _
  384. 			            & strDisclaimer                      & vbCrLf _
  385. 			            & "$HKEY_CLASSES_ROOT   = &80000000" & vbCrLf _
  386. 			            & "$HKEY_CURRENT_USER   = &80000001" & vbCrLf _
  387. 			            & "$HKEY_LOCAL_MACHINE  = &80000002" & vbCrLf _
  388. 			            & "$HKEY_USERS          = &80000003" & vbCrLf _
  389. 			            & "$HKEY_CURRENT_CONFIG = &80000005" & vbCrLf _
  390. 			            & "$HKEY_DYN_DATA       = &80000006" & vbCrLf & vbCrLf _
  391. 			            & "$REG_SZ                         =  1" & vbCrLf _
  392. 			            & "$REG_EXPAND_SZ                  =  2" & vbCrLf _
  393. 			            & "$REG_BINARY                     =  3" & vbCrLf _
  394. 			            & "$REG_DWORD                      =  4" & vbCrLf _
  395. 			            & "$REG_DWORD_BIG_ENDIAN           =  5" & vbCrLf _
  396. 			            & "$REG_LINK                       =  6" & vbCrLf _
  397. 			            & "$REG_MULTI_SZ                   =  7" & vbCrLf _
  398. 			            & "$REG_RESOURCE_LIST              =  8" & vbCrLf _
  399. 			            & "$REG_FULL_RESOURCE_DESCRIPTOR   =  9" & vbCrLf _
  400. 			            & "$REG_RESOURCE_REQUIREMENTS_LIST = 10" & vbCrLf _
  401. 			            & "$REG_QWORD                      = 11" & vbCrLf & vbCrLf _
  402. 			            & "Dim $RC, $objReg, $Computer" & vbCrLf & vbCrLf _
  403. 			            & "$Computer = ""."""  & vbCrLf & vbCrLf _
  404. 			            & "$objReg = GetObject( ""winmgmts:{impersonationLevel=impersonate}" _
  405. 			            & "!//$Computer/root/default:StdRegProv"" )" & vbCrLf
  406. 		Case Else
  407. 			WriteHeader = ""
  408. 	End Select
  409. End Function
  410.  
  411.  
  412. Sub Syntax
  413. 	Dim strMsg
  414. 	strMsg = vbCrLf _
  415. 	       & "Reg2Scr.vbs,  Version " & strVersion & vbCrLf _
  416. 	       & "Read the specified registry key from the specified computer, and generate"     & vbCrLf _
  417. 	       & "KiXtart and VBScript code to recreate that registry key on any other computer" & vbCrLf & vbCrLf _
  418. 	       & "Usage:  REG2SRC.VBS  /R:regkey  /F:outputfile  [ /C:remotecomputer ]" & vbCrLf & vbCrLf _
  419. 	       & "Where:  ""regkey""          is the full registry path"                & vbCrLf _
  420. 	       & "                          (e.g. HKEY_LOCAL_MACHINE\SOFTWARE\MyKey)"   & vbCrLf _
  421. 	       & "        ""outputfile""      is the (path and) file name for the output scripts" & vbCrLf _
  422. 	       & "                          (if an extension is specified it will be ignored)"    & vbCrLf _
  423. 	       & "        ""remotecomputer""  is the optional remote computer name"               & vbCrLf _
  424. 	       & "                          (default if not specified is the local computer)"     & vbCrLf & vbCrLf _
  425. 	       & "Notes:  USE THIS SCRIPT AND THE ONES GENERATED ENTIRELY AT YOUR OWN RISK!"      & vbCrLf _
  426. 	       & "        The scripts generated need to be tested thorougly before being used"    & vbCrLf _
  427. 	       & "        in a production environment. Make sure you have a verified, recent,"    & vbCrLf _
  428. 	       & "        full backup ready before using the generated scripts."                  & vbCrLf _
  429. 	       & "        Read the NOTES/WARNINGS at the end of the generated code; they point"   & vbCrLf _
  430. 	       & "        out any ""anomalies"" encountered by Reg2Scr.vbs."            & vbCrLf  & vbCrLf _
  431. 	       & "Written by Rob van der Woude"           & vbCrLf _
  432. 	       & "http://www.robvanderwoude.com"
  433. 	WScript.Echo strMsg
  434. 	WScript.Quit 1
  435. End Sub

page last uploaded: 2017-08-21, 14:26