Powered by GeSHi

Source code for wmigen.hta

(view source code of wmigen.hta as plain text)

  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  2. <html lang="en">
  3. <head>
  4. <title>WMI Code Generator</title>
  5. <HTA:APPLICATION
  6.   APPLICATIONNAME="WMI Code Generator"
  7.   ID="WMIGen"
  8.   VERSION="9.02"
  9.   SCROLL="auto"
  10.   SINGLEINSTANCE="yes"
  11.   WINDOWSTATE="maximize"/>
  12. <style type="text/css">
  1. a
  2. {
  3. 	color: blue;
  4. }
  5.  
  6. body
  7. {
  8. 	color: white;
  9. 	font-family: arial, sans-serif;
  10. 	font-size: 12pt;
  11. 	margin: 0;
  12. 	padding: 0;
  13. 	filter: progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr='#000000', EndColorStr='#FFFFFF');
  14. }
  15.  
  16. code, .Code
  17. {
  18. 	color: #006000;
  19. 	font-family: courier, monospace;
  20. 	white-space: nowrap;
  21. }
  22.  
  23. p
  24. {
  25. 	color: black;
  26. 	font-size: 80%;
  27. }
  28.  
  29. td
  30. {
  31. 	text-align: left;
  32. }
  33.  
  34. .Blue
  35. {
  36. 	color: blue;
  37. }
  38.  
  39. .Button
  40. {
  41. 	width: 10em;
  42. 	height: 2em;
  43. 	margin: 3px 0.67em 3px 0.67em;
  44. }
  45.  
  46. .Center
  47. {
  48. 	margin-left: auto;
  49. 	margin-right: auto;
  50. 	text-align: center;
  51. }
  52.  
  53. td.CheckBox
  54. {
  55. 	text-align: right;
  56. 	vertical-align: top;
  57. 	width: 2em;
  58. }
  59.  
  60. td.CheckBoxLabel
  61. {
  62. 	text-align: left;
  63. 	vertical-align: bottom;
  64. }
  65.  
  66. .Help
  67. {
  68. 	background-color: white;
  69. 	color: black;
  70. 	margin: 10px;
  71. 	max-width: 900px;
  72. 	padding: 10px;
  73. }
  74.  
  75. .Left
  76. {
  77. 	text-align: left;
  78. }
  79.  
  80. .Red
  81. {
  82. 	color: red;
  83. }
  84.  
  85. .Right
  86. {
  87. 	text-align: right;
  88. }
  89.  
  90. .Top
  91. {
  92. 	vertical-align: top;
  93. }
  94.  
  95. .White
  96. {
  97. 	color: white;
  98. }
  99.  
  100. @media print
  101. {
  102. 	a
  103. 	{
  104. 		color: black;
  105. 		text-decoration: none;
  106. 	}
  107.  
  108. 	body
  109. 	{
  110. 		color: black;
  111. 		font-family: arial, sans-serif;
  112. 		font-size: 12pt;
  113. 		margin: 0;
  114. 		padding: 0;
  115. 		filter: none;
  116. 	}
  117.  
  118. 	code, .Code
  119. 	{
  120. 		color: black;
  121. 		font-family: courier, monospace;
  122. 	}
  123.  
  124. 	p
  125. 	{
  126. 		color: black;
  127. 		font-size: 80%;
  128. 	}
  129.  
  130. 	.Blue
  131. 	{
  132. 		color: black;
  133. 	}
  134.  
  135. 	.Help
  136. 	{
  137. 		background-color: white;
  138. 		color: black;
  139. 		margin: 10px;
  140. 		max-width: 100%;
  141. 		padding: 10px;
  142. 	}
  143.  
  144. 	.Red
  145. 	{
  146. 		color: black;
  147. 	}
  148.  
  149. 	.White
  150. 	{
  151. 		color: black;
  152. 	}
  153. }
  1. </style>
  2. </head>
  3.  
  4. <script language="VBScript">
  1. Option Explicit
  2.  
  3. Dim dummy
  4.  
  5. Const TristateFalse      =  0
  6. Const TristateMixed      = -2
  7. Const TristateTrue       = -1
  8. Const TristateUseDefault = -2
  9.  
  10. Const ForAppending = 8
  11. Const ForReading   = 1
  12. Const ForWriting   = 2
  13.  
  14. ' Minimum window size
  15. Dim gviMinHeight, gviMinWidth
  16. gviMinHeight = Min( 600, window.screen.height )
  17. gviMinWidth  = Min( 800, window.screen.width  )
  18.  
  19. ' Year to be displayed in copyrights notices
  20. Dim gviCopyrightsYear
  21. gviCopyrightsYear = 2014
  22.  
  23. ' Configuration file
  24. Dim gvsConfigFile
  25. gvsConfigFile = Left( Self.location.pathname, Len( Self.location.pathname ) - 4 ) & ".cfg"
  26.  
  27. ' Dictionary objects to hold all defaults, permanent settings and session settings
  28. Dim gvaDefaultsBool, gvaDefaultsStr, gvaSettingsBool, gvaSettingsStr
  29. Set gvaDefaultsBool = CreateObject( "Scripting.Dictionary" )
  30. Set gvaDefaultsStr  = CreateObject( "Scripting.Dictionary" )
  31. Set gvaSettingsBool = CreateObject( "Scripting.Dictionary" )
  32. Set gvaSettingsStr  = CreateObject( "Scripting.Dictionary" )
  33.  
  34. ' Arrays to hold the classes and the selected class' methods and properties
  35. Dim gvaClasses( ), gvaMethods( ), gvaProperties( )
  36.  
  37. ' Variables to check if the namespaces and classes have been listed
  38. Dim gvbClassesListed, gvbNamespacesListed
  39. gvbClassesListed    = False
  40. gvbNamespacesListed = False
  41.  
  42. ' Variable to check if the text in the Code window is code or a query result
  43. Dim gvbCodeView
  44. gvbCodeView = False
  45.  
  46. ' More global variables
  47. Dim gvaNamespaces( )
  48. Dim gvbClassValidate
  49. Dim gvbCommandlineValidate
  50. Dim gvbInteractive
  51. Dim gvbLanguageValidate
  52. Dim gvbNamespaceValidate
  53. Dim gviMaxLen
  54. Dim gviReqHeight
  55. Dim gviReqWidth
  56. Dim gvoClass
  57. Dim gvoProperty
  58. Dim gvoWMIService
  59. Dim gvsClass
  60. Dim gvsCommandline
  61.  
  62. gvbCommandlineValidate = True
  63. gvbClassValidate       = True
  64. gvbInteractive         = True
  65. gvbLanguageValidate    = True
  66. gvbNamespaceValidate   = True
  67. gviReqHeight           = window.screen.height
  68. gviReqWidth            = window.screen.width
  69. gvsCommandline         = WMIGen.CommandLine
  70.  
  71.  
  72. Sub DebugShowSettings( myTitle )
  73. 	Dim strKey, strMsg
  74. 	strMsg = ""
  75. 	For Each strKey In gvaSettingsBool.Keys
  76. 		strMsg = strMsg & strKey & " = " & gvaSettingsBool.Item( strKey ) & vbCrLf
  77. 	Next
  78. 	For Each strKey In gvaSettingsStr.Keys
  79. 		strMsg = strMsg & strKey & " = " & gvaSettingsStr.Item( strKey ) & vbCrLf
  80. 	Next
  81. 	MsgBox strMsg, vbOKOnly + vbInformation + vbApplicationModal, myTitle
  82. End Sub
  83.  
  84.  
  85. Sub ArraySort( ByRef myArray )
  86. 	' Bubble sort algorithm found in Microsoft's Script Repository
  87. 	' http://www.microsoft.com/technet/scriptcenter/resources/qanda/nov04/hey1122.mspx
  88. 	Dim i, j, k, strHolder
  89. 	If UBound( myArray ) > 1 Then
  90. 		For i = UBound( myArray ) - 1 To 0 Step -1
  91. 			For j= 0 to i
  92. 				k = j + 1
  93. 				If UCase( myArray(j) ) > UCase( myArray(k) ) Then
  94. 					strHolder  = myArray(k)
  95. 					myArray(k) = myArray(j)
  96. 					myArray(j) = strHolder
  97. 				End If
  98. 			Next
  99. 		Next
  100. 	End If
  101. End Sub
  102.  
  103.  
  104. Function Backup( myFile )
  105. 	' Backup this HTA; the COPY command is used because it handles open files much better than the FileSystemObject does
  106. 	Dim strBackup, strNow, wshShell
  107. 	strNow = Year( Now ) & Right( "0" & Month( Now ), 2 ) & Right( "0" & Day( Now ), 2 ) & "." & Right( "0" & Hour( Now ), 2 ) & Right( "0" & Minute( Now ), 2 ) & Right( "0" & Second( Now ), 2 )
  108. 	strBackup = myFile & "." & WMIGen.Version & ".backup." & strNow
  109. 	Set wshShell = CreateObject( "WScript.Shell" )
  110. 	wshShell.Run "CMD.EXE /C COPY /Y """ & myFile & """ """ & strBackup & """", 7, True
  111. 	Set wshShell = Nothing
  112. 	Backup = strBackup
  113. End Function
  114.  
  115.  
  116. Sub ButtonState( )
  117. 	If Trim( Code.value ) = "" Then
  118. 		CodeLabel.innerHTML      = "Code:"
  119. 		CopyCodeButton.disabled  = True
  120. 		CopyCodeButton.title     = ""
  121. 		ClearCodeButton.disabled = True
  122. 		ClearCodeButton.title    = ""
  123. 		SaveCodeButton.disabled  = True
  124. 		SaveCodeButton.title     = ""
  125. 	Else
  126. 		CopyCodeButton.disabled  = False
  127. 		CopyCodeButton.title     = "Press this button to copy the generated code to the clipboard"
  128. 		ClearCodeButton.disabled = False
  129. 		ClearCodeButton.title    = "Press this button to erase the generated code"
  130. 		SaveCodeButton.disabled  = False
  131. 		SaveCodeButton.title     = "Press this button to save the generated code to a file"
  132. 	End If
  133. End Sub
  134.  
  135.  
  136. Sub CheckEscape( )
  137. 	If Self.window.event.keyCode = 27 Then
  138. 		OnClickButtonCancel
  139. 	End If
  140. 	If Self.window.event.keyCode = 8 And Settings.style.display = "none" Then
  141. 		OnClickButtonCancel
  142. 	End If
  143. End Sub
  144.  
  145.  
  146. Sub CheckUpdate( )
  147. 	If Not gvaSettingsBool.Item( "NOUPD" ) Then
  148. 		Dim intAnswer, intButtons, lenLatestVer
  149. 		Dim objFSO, wshShell
  150. 		Dim strCurDir, strCurrentVer, strLatestver, strPrompt, strTitle, strZIPFile
  151.  
  152. 		' Change mouse pointer to hourglass while checking for update
  153. 		document.body.style.cursor = "wait"
  154. 		Set objFSO    = CreateObject( "Scripting.FileSystemObject" )
  155. 		Set wshShell  = CreateObject( "WScript.Shell" )
  156. 		' Clear the IE cache
  157. 		wshShell.Run "RUNDll32.EXE InetCpl.cpl,ClearMyTracksByProcess 8", 7, True
  158. 		strCurrentVer = WMIGen.Version
  159. 		strLatestVer  = TextFromHTML( "http://www.robvanderwoude.com/updates/wmigen.txt" )
  160. 		lenLatestVer  = Len( strLatestVer )
  161. 		If lenLatestVer = 4 Then
  162. 			intAnswer  = vbNo
  163. 			intButtons = vbYesNoCancel + vbApplicationModal + vbInformation
  164. 			If strLatestVer < strCurrentVer Then
  165. 				strTitle  = "Unofficial unsupported version"
  166. 				strPrompt = "You seem to be using a pre-release version (" & strCurrentVer & ") of the WMI Code Generator." _
  167. 				          & vbCrLf & vbCrLf _
  168. 				          & "The latest official release is " & strLatestver _
  169. 				          & vbCrLf & vbCrLf _
  170. 				          & "Do you want to download and install the latest official release?"
  171. 				intAnswer = MsgBox( strPrompt, intButtons + vbDefaultButton2, strTitle )
  172. 			End If
  173. 			If strLatestVer > strCurrentVer Then
  174. 				strTitle  = "Update available"
  175. 				strPrompt = "You are using version " & strCurrentVer & " of the WMI Code Generator." _
  176. 				          & vbCrLf & vbCrLf _
  177. 				          & "The latest official release is " & strLatestver _
  178. 				          & vbCrLf & vbCrLf _
  179. 				          & "Do you want to download and install the update?"
  180. 				intAnswer = MsgBox( strPrompt, intButtons, strTitle )
  181. 			End If
  182. 			If intAnswer = vbYes Then
  183. 				strCurDir  = objFSO.GetParentFolderName( Self.location.pathname )
  184. 				strZIPFile = objFSO.BuildPath( strCurDir, "updatecheck.zip" )
  185. 				' Delete existing ZIP file
  186. 				If objFSO.FileExists( strZIPFile ) Then objFSO.DeleteFile strZIPFile, True
  187. 				' Backup current HTA
  188. 				strTitle  = "Backup saved"
  189. 				strPrompt = "The current HTA has been copied to" & vbCrLf _
  190. 				          & """" & Backup( Self.location.pathname ) & """" & vbCrLf & vbCrLf _
  191. 				          & "Click OK to continue"
  192. 				intAnswer = MsgBox( strPrompt, vbOKCancel + vbApplicationModal + vbInformation, strTitle )
  193. 				If intAnswer = vbOK Then
  194. 					If Download( "http://www.robvanderwoude.com/files/wmigen.zip", strZIPFile ) > 23000 Then
  195. 						' Overwrite current HTA with extracted new version and restart HTA
  196. 						Extract strZIPFile, strCurDir
  197. 						setTimeout "Self.location.reload", 3000, "VBScript"
  198. 					Else
  199. 						' Delete corrupted ZIP file
  200. 						If objFSO.FileExists( strZIPFile ) Then objFSO.DeleteFile strZIPFile, True
  201. 						intButtons = vbOKOnly + vbExclamation + vbApplicationModal
  202. 						strPrompt  = "An error occurred while trying to download ""wmigen.zip""." _
  203. 						           & vbCrLf & vbCrLf _
  204. 						           & "Try again later, or contact the author if the problem persists."
  205. 						strTitle   = "Download Error"
  206. 						MsgBox strPrompt, intButtons, strTitle
  207. 					End If
  208. 				Else
  209. 					wshShell.Run "http://www.robvanderwoude.com/wmigen.php", 3, False
  210. 				End If
  211. 			End If
  212. 		End If
  213. 		Set wshShell = Nothing
  214. 		Set objFSO = Nothing
  215. 		' Change mouse pointer back to default
  216. 		document.body.style.cursor = "default"
  217. 	End If
  218. End Sub
  219.  
  220.  
  221. Sub CheckWindowSize( )
  222. 	Dim smallBoxHeight
  223. 	smallBoxHeight  = Max(  6, CInt( document.body.clientHeight / 100 ) )
  224. 	Code.rows       = Max( 15, CInt( document.body.clientHeight /  75 ) )
  225. 	Code.cols       = CInt( document.body.clientWidth / 9 )
  226. 	Properties.size = smallBoxHeight
  227. 	Methods.size    = smallBoxHeight
  228. 	WMIClasses.size = smallBoxHeight
  229. End Sub
  230.  
  231.  
  232. Sub ClearCode( )
  233. 	Code.value = ""
  234. 	ButtonState
  235. End Sub
  236.  
  237.  
  238. Sub ConfigReadCommandline( )
  239. 	Dim objFSO
  240. 	Dim strItem, strKey, strUC
  241. 	strUC = UCase( gvsCommandline )
  242. 	For Each strKey In gvaSettingsBool.Keys
  243. 		If InStr( strUC, "/" & strKey ) Then gvaSettingsBool.Item( strKey ) = True
  244. 	Next
  245. 	strItem = GetParameter( gvsCommandline, "CLASS" )
  246. 	If strItem <> "" Then gvaSettingsStr.Item( "CLASS" ) = strItem
  247. 	strItem = GetParameter( gvsCommandline, "LANGUAGE" )
  248. 	If strItem <> "" Then gvaSettingsStr.Item( "LANGUAGE" ) = strItem
  249. 	strItem = GetParameter( gvsCommandline, "NAMESPACE" )
  250. 	If strItem <> "" Then gvaSettingsStr.Item( "NAMESPACE" ) = strItem
  251. 	strItem = GetParameter( gvsCommandline, "SIZE" )
  252. 	If strItem <> "" Then gvaSettingsStr.Item( "SIZE" ) = ValidatedWindowSize( strItem )
  253. 	strItem = GetParameter( gvsCommandline, "SAVE" )
  254. 	Set objFSO = CreateObject( "Scripting.FileSystemObject" )
  255. 	If strItem <> "" Then
  256. 		With objFSO
  257. 			If .FolderExists( .GetParentFolderName( .GetAbsolutePathName( strItem ) ) ) Then
  258. 				gvaSettingsStr.Item( "SAVE" ) = strItem
  259. 			Else
  260. 				gvaSettingsStr.Item( "SAVE" ) = ""
  261. 			End If
  262. 		End With
  263. 	End If
  264. 	If InStr( strUC, "/COPY" )     Then gvaSettingsBool.Item( "COPY" )     = True
  265. 	If InStr( strUC, "/GENERATE" ) Then gvaSettingsBool.Item( "GENERATE" ) = True
  266. 	If InStr( strUC, "/RUN" )      Then gvaSettingsBool.Item( "RUN" )      = True
  267. 	gvbInteractive = True
  268. 	If ( gvaSettingsStr.Item( "NAMESPACE" ) <> "" ) And gvaSettingsStr.Item( "CLASS" ) <> "" Then
  269. 		If gvaSettingsBool.Item( "RUN" ) Or ( gvaSettingsBool.Item( "GENERATE" ) And gvaSettingsStr.Item( "LANGUAGE" ) <> "" ) Then
  270. 			If gvaSettingsBool.Item( "COPY" ) Or gvaSettingsStr.Item( "SAVE" ) <> "" Then
  271. 				gvbInteractive = False
  272. 				gvaSettingsBool.Item( "FAST" )  = True
  273. 				gvaSettingsBool.Item( "NOUPD" ) = True
  274. 			End If
  275. 		End If
  276. 	Else
  277. 		gvaSettingsBool.Item( "COPY" )     = False
  278. 		gvaSettingsBool.Item( "GENERATE" ) = False
  279. 		gvaSettingsBool.Item( "RUN" )      = False
  280. 		gvaSettingsStr.Item( "SAVE" )      = ""
  281. 	End If
  282. 	Set objFSO = Nothing
  283. End Sub
  284.  
  285.  
  286. Sub ConfigReadDefaults( )
  287. 	Dim strKey
  288. 	gvaDefaultsBool.Item( "BW" )          = False
  289. 	gvaDefaultsBool.Item( "COPY" )        = False
  290. 	gvaDefaultsBool.Item( "FAST" )        = False
  291. 	gvaDefaultsBool.Item( "GENERATE" )    = False
  292. 	gvaDefaultsBool.Item( "NOPERF" )      = False
  293. 	gvaDefaultsBool.Item( "NOUPD" )       = False
  294. 	gvaDefaultsBool.Item( "LOWRES" )      = False
  295. 	gvaDefaultsBool.Item( "RUN" )         = False
  296. 	gvaDefaultsBool.Item( "SPACES" )      = False
  297. 	gvaDefaultsBool.Item( "WIN32" )       = False
  298. 	gvaDefaultsBool.Item( "WRAP" )        = False
  299. 	gvaDefaultsStr.Item( "CLASS" )        = ""
  300. 	gvaDefaultsStr.Item( "LANGUAGE" )     = "Batch"
  301. 	gvaDefaultsStr.Item( "NAMESPACE" )    = "root/CIMV2"
  302. 	gvaDefaultsStr.Item( "SAVE" )         = ""
  303. 	gvaDefaultsStr.Item( "SIZE" )         = ""
  304. 	For Each strKey In gvaDefaultsBool.Keys
  305. 		gvaSettingsBool.Item( strKey ) = gvaDefaultsBool.Item( strKey )
  306. 	Next
  307. 	For Each strKey In gvaDefaultsStr.Keys
  308. 		gvaSettingsStr.Item( strKey ) = gvaDefaultsStr.Item( strKey )
  309. 	Next
  310. End Sub
  311.  
  312.  
  313. Sub ConfigReadFile( )
  314. 	Dim intMinSize, intSize
  315. 	Dim objFile, objFSO
  316. 	Dim strConfig, strItem, strKey, strUConfig
  317. 	Set objFSO = CreateObject( "Scripting.FileSystemObject" )
  318. 	If objFSO.FileExists( gvsConfigFile ) Then
  319. 		' Check config file size
  320. 		Set objFile = objFSO.GetFile( gvsConfigFile )
  321. 		intSize = objFile.Size
  322. 		Set objFile = Nothing
  323. 		' Check minimum required file size by "measuring" command line switch length
  324. 		intMinSize = 9999
  325. 		For Each strKey In gvaSettingsBool.Keys
  326. 			intMinSize = Min( intMinSize, Len( strKey ) )
  327. 		Next
  328. 		' Add 1 for the forward slash
  329. 		intMinSize = intMinSize + 1
  330. 		' Config file is useless if its size is less than the length of the shortest command line switch
  331. 		If intSize < intMinSize Then
  332. 			objFSO.DeleteFile gvsConfigFile, True
  333. 		Else
  334. 			' Read the entire contents of the configuration file
  335. 			Set objFile = objFSO.OpenTextFile( gvsConfigFile, ForReading, False, TristateFalse )
  336. 			strConfig  = Trim( Replace( objFile.ReadAll( ), vbCrLf, " " ) )
  337. 			strUConfig = UCase( strConfig )
  338. 			objFile.Close
  339. 			Set objFile = Nothing
  340. 			If InStr( strUConfig, "/BW" )        Then gvaSettingsBool.Item( "BW" )        = True
  341. 			If InStr( strUConfig, "/FAST" )      Then gvaSettingsBool.Item( "FAST" )      = True
  342. 			If InStr( strUConfig, "/NOPERF" )    Then gvaSettingsBool.Item( "NOPERF" )    = True
  343. 			If InStr( strUConfig, "/NOUPD" )     Then gvaSettingsBool.Item( "NOUPD" )     = True
  344. 			If InStr( strUConfig, "/LOWRES" )    Then gvaSettingsBool.Item( "LOWRES" )    = True
  345. 			If InStr( strUConfig, "/SPACES" )    Then gvaSettingsBool.Item( "SPACES" )    = True
  346. 			If InStr( strUConfig, "/WIN32" )     Then gvaSettingsBool.Item( "WIN32" )     = True
  347. 			If InStr( strUConfig, "/WRAP" )      Then gvaSettingsBool.Item( "WRAP" )      = True
  348. 			strItem = GetParameter( strConfig, "LANGUAGE" )
  349. 			If strItem <> "" Then gvaSettingsStr.Item( "LANGUAGE" ) = strItem
  350. 			strItem = GetParameter( strConfig, "NAMESPACE" )
  351. 			If strItem <> "" Then gvaSettingsStr.Item( "NAMESPACE" ) = strItem
  352. 			strItem = GetParameter( strConfig, "SIZE" )
  353. 			If strItem <> "" Then gvaSettingsStr.Item( "SIZE" ) = ValidatedWindowSize( strItem )
  354. 			Command_Line.value = strConfig
  355. 		End If
  356. 	End If
  357. 	Set objFSO = Nothing
  358. End Sub
  359.  
  360.  
  361. Sub ConfigRemoveFile( )
  362. 	Dim objFSO
  363. 	Set objFSO = CreateObject( "Scripting.FileSystemObject" )
  364. 	If objFSO.FileExists( gvsConfigFile ) Then objFSO.DeleteFile gvsConfigFile, True
  365. 	Set objFSO = Nothing
  366. End Sub
  367.  
  368.  
  369. Sub ConfigSaveChanges( )
  370. 	Dim objOption
  371. 	gvaSettingsBool.Item( "BW" )        = BW.checked
  372. 	gvaSettingsBool.Item( "FAST" )      = Exclusive_Namespace.checked
  373. 	gvaSettingsBool.Item( "NOPERF" )    = Exclude_Perf.checked
  374. 	gvaSettingsBool.Item( "NOUPD" )     = Not Update_Check.checked
  375. 	gvaSettingsBool.Item( "LOWRES" )    = Resource_Friendly.checked
  376. 	gvaSettingsBool.Item( "SPACES" )    = Use_Spaces.checked
  377. 	gvaSettingsBool.Item( "WIN32" )     = Win32_Only.checked
  378. 	gvaSettingsBool.Item( "WRAP" )      = Word_Wrap.checked
  379. 	gvaSettingsStr.Item( "LANGUAGE" )   = Default_Language.value
  380. 	gvaSettingsStr.Item( "NAMESPACE" )  = Default_Namespace.value
  381. 	For Each objOption In Default_Namespace.options
  382. 		If objOption.selected Then
  383. 			gvaSettingsStr.Item( "NAMESPACE" ) = objOption.value
  384. 		End If
  385. 	Next
  386. 	gvaSettingsStr.Item( "SIZE" ) = ValidatedWindowSize( Window_Size.value )
  387. 	For Each objOption In CodeLanguage.options
  388. 		If objOption.value = gvaSettingsStr.Item( "LANGUAGE" ) Then
  389. 			objOption.selected = True
  390. 		Else
  391. 			objOption.selected = False
  392. 		End If
  393. 	Next
  394. 	For Each objOption In Default_Language.options
  395. 		If objOption.value = gvaSettingsStr.Item( "LANGUAGE" ) Then
  396. 			objOption.selected = True
  397. 		Else
  398. 			objOption.selected = False
  399. 		End If
  400. 	Next
  401. 	If Not gvbNamespacesListed Then
  402. 		FillNamespacesDropdown
  403. 	End If
  404. 	For Each objOption In Namespaces.options
  405. 		If objOption.value = gvaSettingsStr.Item( "NAMESPACE" ) Then
  406. 			objOption.selected = True
  407. 		Else
  408. 			objOption.selected = False
  409. 		End If
  410. 	Next
  411. 	For Each objOption In Default_Namespace.options
  412. 		If objOption.value = gvaSettingsStr.Item( "NAMESPACE" ) Then
  413. 			objOption.selected = True
  414. 		Else
  415. 			objOption.selected = False
  416. 		End If
  417. 	Next
  418. 	FillClassesDropdown
  419. 	If gvaSettingsStr.Item( "CLASS" ) <> "" Then
  420. 		For Each objOption In WMIClasses.options
  421. 			If objOption.value = gvaSettingsStr.Item( "CLASS" ) Then
  422. 				objOption.selected = True
  423. 			Else
  424. 				objOption.selected = False
  425. 			End If
  426. 		Next
  427. 	End If
  428. 	WindowSize
  429. 	HandleClassChange
  430. End Sub
  431.  
  432.  
  433. Sub ConfigSaveFile( )
  434. 	Dim objFile, objFSO
  435. 	dim strConfig, strKey
  436. 	strConfig = ""
  437. 	For Each strKey In gvaSettingsBool.Keys
  438. 		If gvaSettingsBool.Item( strKey ) Then
  439. 			strConfig = strConfig & " /" & strKey
  440. 		End If
  441. 	Next
  442. 	If gvaSettingsStr.Item( "LANGUAGE" ) <> "" Then
  443. 		If gvaSettingsStr.Item( "LANGUAGE" ) <> gvaDefaultsStr.Item( "LANGUAGE" ) Then
  444. 			strConfig = strConfig & " /LANGUAGE:" & gvaSettingsStr.Item( "LANGUAGE" )
  445. 		End If
  446. 	End If
  447. 	If gvaSettingsStr.Item( "NAMESPACE" ) <> "" Then
  448. 		If gvaSettingsStr.Item( "NAMESPACE" ) <> gvaDefaultsStr.Item( "NAMESPACE" ) Then
  449. 			strConfig = strConfig & " /NAMESPACE:" & gvaSettingsStr.Item( "NAMESPACE" )
  450. 		End If
  451. 	End If
  452. 	If gvaSettingsStr.Item( "SIZE" ) <> "" Then
  453. 		If gvaSettingsStr.Item( "SIZE" ) <> "maximize" Then
  454. 			strConfig = strConfig & " /SIZE:" & gvaSettingsStr.Item( "SIZE" )
  455. 		End If
  456. 	End If
  457. 	Set objFSO  = CreateObject( "Scripting.FileSystemObject" )
  458. 	Set objFile = objFSO.OpenTextFile( gvsConfigFile, ForWriting, True, TristateFalse )
  459. 	objFile.Write Trim( strConfig )
  460. 	objFile.Close
  461. 	Set objFile = Nothing
  462. 	Set objFSO  = Nothing
  463. 	Command_Line.value = Trim( strConfig )
  464. End Sub
  465.  
  466.  
  467. Sub ConfigSetDefaults( )
  468. 		Dim strKey
  469. 		For Each strKey In gvaDefaultsBool.Keys
  470. 			gvaSettingsBool.Item( strKey ) = gvaDefaultsBool.Item( strKey )
  471. 		Next
  472. 		For Each strKey In gvaDefaultsStr.Keys
  473. 			gvaSettingsStr.Item( strKey ) = gvaDefaultsStr.Item( strKey )
  474. 		Next
  475. End Sub
  476.  
  477.  
  478. Sub ConfigUpdateStatus( )
  479. 	Dim objOption
  480. 	BW.checked = gvaSettingsBool.Item( "BW" )
  481. 	HandleBWChange
  482. 	For Each objOption In CodeLanguage.options
  483. 		If UCase( objOption.value ) = UCase( gvaSettingsStr.Item( "LANGUAGE" ) ) Then
  484. 			objOption.selected = True
  485. 		Else
  486. 			objOption.selected = False
  487. 		End If
  488. 	Next
  489. 	For Each objOption In Default_Language.options
  490. 		If UCase( objOption.value ) = UCase( gvaSettingsStr.Item( "LANGUAGE" ) ) Then
  491. 			objOption.selected = True
  492. 		Else
  493. 			objOption.selected = False
  494. 		End If
  495. 	Next
  496. 	If Not gvbNamespacesListed Then
  497. 		FillNamespacesDropdown
  498. 	End If
  499. 	For Each objOption In Namespaces.options
  500. 		If UCase( objOption.value ) = UCase( gvaSettingsStr.Item( "NAMESPACE" ) ) Then
  501. 			objOption.selected = True
  502. 		Else
  503. 			objOption.selected = False
  504. 		End If
  505. 	Next
  506. 	For Each objOption In Default_Namespace.options
  507. 		If UCase( objOption.value ) = UCase( gvaSettingsStr.Item( "NAMESPACE" ) ) Then
  508. 			objOption.selected = True
  509. 		Else
  510. 			objOption.selected = False
  511. 		End If
  512. 	Next
  513. 	FillClassesDropdown
  514. 	If gvaSettingsStr.Item( "CLASS" ) <> "" Then
  515. 		For Each objOption In WMIClasses.options
  516. 			If UCase( objOption.value ) = UCase( gvaSettingsStr.Item( "CLASS" ) ) Then
  517. 				objOption.selected = True
  518. 			Else
  519. 				objOption.selected = False
  520. 			End If
  521. 		Next
  522. 	End If
  523. 	WindowSize
  524. 	HandleClassChange
  525. End Sub
  526.  
  527.  
  528. Sub CopyCode( )
  529. 	Document.parentWindow.clipboardData.setData "text", Code.value
  530. End Sub
  531.  
  532.  
  533. Function CreateLine( myProperty, myMaxLen )
  534. 	' This subroutine will split up a string into separate words if command line switch /SPACES is used:
  535. 	' "SCSILogicalUnit" will be converted to "SCSI Logical Unit"
  536. 	Dim colMatches, intMatches, maxLen, objRE, strProperty
  537. 	maxLen      = myMaxLen
  538. 	strProperty = myProperty
  539. 	If gvaSettingsBool.Item( "SPACES" ) Then
  540. 		maxLen = maxLen + 5
  541. 		Set objRE = New RegExp
  542. 		objRE.Global     = False
  543. 		objRE.IgnoreCase = False
  544. 		' Insert a space between lowwercase and immediately following uppercase letters
  545. 		' e.g. "SCSILogicalUnit" becomes "SCSILogical Unit"
  546. 		objRE.Pattern = "([a-z])([A-Z])"
  547. 		intMatches    = -1
  548. 		Do Until intMatches = 0
  549. 			Set colMatches = objRE.Execute( strProperty )
  550. 			intMatches = colMatches.Count
  551. 			If intMatches > 0 Then
  552. 				strProperty = objRE.Replace( strProperty, colMatches(0).Submatches(0) & " " & colMatches(0).Submatches(1) )
  553. 			End If
  554. 		Loop
  555. 		' Insert a space between the second last and last uppercase letters in a row of uppercase only
  556. 		' e.g. "SCSILogical Unit" becomes "SCSI Logical Unit"
  557. 		objRE.Pattern = "([A-Z]+)([A-Z][a-z])"
  558. 		intMatches    = -1
  559. 		Do Until intMatches = 0
  560. 			Set colMatches = objRE.Execute( strProperty )
  561. 			intMatches = colMatches.Count
  562. 			If intMatches > 0 Then
  563. 				strProperty = objRE.Replace( strProperty, colMatches(0).Submatches(0) & " " & colMatches(0).Submatches(1) )
  564. 			End If
  565. 		Loop
  566. 		Set objRE = Nothing
  567. 	End If
  568. 	CreateLine = Left( strProperty & Space( MaxLen ), MaxLen ) & " :"
  569. End Function
  570.  
  571.  
  572. Function Download( myURL, myFile )
  573. 	Dim i, intLen, objFile, objFSO, objHTTP
  574. 	intLen = 0
  575. 	Set objFSO  = CreateObject( "Scripting.FileSystemObject" )
  576. 	Set objFile = objFSO.OpenTextFile( myFile, ForWriting, True )
  577. 	Set objHTTP = CreateObject( "WinHttp.WinHttpRequest.5.1" )
  578. 	objHTTP.Open "GET", myURL, False
  579. 	objHTTP.Send
  580. 	' Write the downloaded byte stream to the target file
  581. 	intLen = LenB( objHTTP.ResponseBody )
  582. 	For i = 1 To intLen
  583. 		objFile.Write Chr( AscB( MidB( objHTTP.ResponseBody, i, 1 ) ) )
  584. 	Next
  585. 	objFile.Close( )
  586. 	Set objHTTP = Nothing
  587. 	Set objFile = Nothing
  588. 	Set objFSO  = Nothing
  589. 	Download = intLen
  590. End Function
  591.  
  592.  
  593. Sub EnumNamespaces( myNamespace )
  594. 	Dim intSize
  595. 	Dim colNamespaces, objNamespace, objWMIService
  596. 	intSize = UBound( gvaNamespaces )
  597. 	Set objWMIService = GetObject ( "winmgmts:{impersonationLevel=impersonate}//./" & myNamespace )
  598. 	Set colNamespaces = objWMIService.InstancesOf( "__NAMESPACE" )
  599. 	For Each objNamespace In colNamespaces
  600. 		If Left( objNamespace.Name, 2 ) <> "__" Then
  601. 			intSize = UBound( gvaNamespaces ) + 1
  602. 			ReDim Preserve gvaNamespaces( intSize )
  603. 			gvaNamespaces( intSize ) = myNamespace & "/" & objNamespace.Name
  604. 			EnumNamespaces myNamespace & "/" & objNamespace.Name
  605. 		End If
  606. 	Next
  607. 	gvbNamespacesListed = True
  608. End Sub
  609.  
  610.  
  611. Sub Extract( myZIPFile, myTargetDir )
  612. 	Dim intOptions, objShell, objSource, objTarget
  613. 	Set objShell  = CreateObject( "Shell.Application" )
  614. 	Set objSource = objShell.NameSpace( myZIPFile ).Items( )
  615. 	Set objTarget = objShell.NameSpace( myTargetDir )
  616. 	' These are the available CopyHere options, according to MSDN
  617. 	' (http://msdn2.microsoft.com/en-us/library/ms723207.aspx).
  618. 	' On my test systems, however, the options were completely ignored.
  619. 	'      4: Do not display a progress dialog box.
  620. 	'      8: Give the file a new name in a move, copy, or rename operation if a file with the target name already exists.
  621. 	'     16: Click "Yes to All" in any dialog box that is displayed.
  622. 	'     64: Preserve undo information, if possible.
  623. 	'    128: Perform the operation on files only if a wildcard file name (*.*) is specified.
  624. 	'    256: Display a progress dialog box but do not show the file names.
  625. 	'    512: Do not confirm the creation of a new directory if the operation requires one to be created.
  626. 	'   1024: Do not display a user interface if an error occurs.
  627. 	'   4096: Only operate in the local directory. Don't operate recursively into subdirectories.
  628. 	'   8192: Do not copy connected files as a group. Only copy the specified files.
  629. 	intOptions = 16 + 256
  630. 	objTarget.CopyHere objSource, intOptions
  631. 	Set objSource = Nothing
  632. 	Set objTarget = Nothing
  633. 	Set objShell  = Nothing
  634. End Sub
  635.  
  636.  
  637. Sub FillClassesDropdown( )
  638. 	Dim blnCheck
  639. 	Dim intSize, i, j, k
  640. 	Dim colClasses, objClass, objNewOption, objWMIService
  641. 	intSize = 0
  642. 	' Change cursor to hourglass while loading WMI class list
  643. 	Document.body.style.cursor = "wait"
  644. 	' Enable custom error handling
  645. 	On Error Resume Next
  646. 	Set objWMIService = GetObject( "winmgmts:{impersonationLevel=impersonate}" & gvaSettingsStr.Item( "NAMESPACE" ) )
  647. 	If Err Then
  648. 		MsgBox "Could not connect to " & gvaSettingsStr.Item( "NAMESPACE" ), vbOKOnly, "Namespace Error"
  649. 		Exit Sub
  650. 	End If
  651. 	If gvaSettingsStr.Item( "CLASS" ) <> "" And gvaSettingsBool.Item( "FAST" ) Then
  652. 		ReDim gvaClasses(0)
  653. 		gvaClasses(0) = gvaSettingsStr.Item( "CLASS" )
  654. 	Else
  655. 		Set colClasses = objWMIService.SubClassesOf
  656. 		If Err Then
  657. 			MsgBox "Error " & Err.Number & ": " & Err.Description, vbOKOnly, "Error"
  658. 			Exit Sub
  659. 		End If
  660. 		' Store the list of classes in an array
  661. 		For Each objClass In colClasses
  662. 			' List only Win32_* classes if /WIN32 was used
  663. 			If Left( UCase( objClass.Path_.Class ), 6 ) = "WIN32_" Or Not gvaSettingsBool.Item( "WIN32" ) Then
  664. 				' Skip Win32_Perf* classes if /NOPERF was used
  665. 				If Left( UCase( objClass.Path_.Class ), 10 ) <> "WIN32_PERF" Or Not gvaSettingsBool.Item( "NOPERF" ) Then
  666. 					' Skip WMI systemm properties starting with a double underscore
  667. 					If Left( objClass.Path_.Class, 2 ) <> "__" Then
  668. 						ReDim Preserve gvaClasses( intSize )
  669. 						gvaClasses( intSize ) = objClass.Path_.Class
  670. 						intSize = intSize + 1
  671. 					End If
  672. 				End If
  673. 			End If
  674. 		Next
  675. 	End If
  676. 	If IsArray( gvaClasses ) Then
  677. 		If UBound( gvaClasses ) > 1 Then
  678. 			' Sort the classes
  679. 			ArraySort gvaClasses
  680. 		End if
  681. 		' First purge the classes list
  682. 		WMIClasses.innerHTML = ""
  683. 		' Next repopulate the classes list
  684. 		If gvaSettingsStr.Item( "CLASS" ) = "" Then
  685. 			blnCheck = True
  686. 		Else
  687. 			blnCheck = False
  688. 		End If
  689. 		For i = 0 To UBound( gvaClasses )
  690. 			Set objNewOption  = document.createElement( "OPTION" )
  691. 			If CInt( i / 2 ) <> ( i / 2 ) Then
  692. 				objNewOption.style.backgroundcolor = "#F0F0F0"
  693. 			End If
  694. 			objNewOption.text  = gvaClasses(i)
  695. 			objNewOption.value = gvaClasses(i)
  696. 			If gvaSettingsStr.Item( "CLASS" ) = "" Then
  697. 				If i = 0 Then
  698. 					objNewOption.selected = True
  699. 				End If
  700. 			Else
  701. 				If UCase( gvaClasses(i) ) = UCase( gvaSettingsStr.Item( "CLASS" ) ) Then
  702. 					objNewOption.selected = True
  703. 					blnCheck              = True
  704. 				End If
  705. 			End If
  706. 			WMIClasses.options.add( objNewOption )
  707. 		Next
  708. 		If Not blnCheck Then
  709. 			gvbCommandlineValidate = False
  710. 			gvbClassValidate       = False
  711. 		End If
  712. 	End If
  713. 	' Change cursor back to default
  714. 	Document.body.style.cursor = "default"
  715. 	On Error Goto 0
  716. 	HandleClassChange
  717. End Sub
  718.  
  719.  
  720. Sub FillNamespacesDropdown( )
  721. 	Dim blnCheck
  722. 	Dim intSize, i, j, k
  723. 	Dim objNamespace, objNewOption, objNewOption2
  724. 	intSize = 0
  725. 	' Change cursor to hourglass while loading WMI class list
  726. 	Document.body.style.cursor = "wait"
  727. 	' Enable custom error handling
  728. 	If gvaSettingsBool.Item( "FAST" ) Then
  729. 		ReDim gvaNamespaces(0)
  730. 		gvaNamespaces(0) = gvaSettingsStr.Item( "NAMESPACE" )
  731. 	Else
  732. 		' Get a list of available namespaces
  733. 		ReDim Preserve gvaNamespaces(0)
  734. 		gvaNamespaces(0) = "root"
  735. 		EnumNamespaces( "root" )
  736. 		' Sort the array of namespaces
  737. 		ArraySort gvaNamespaces
  738. 	End If
  739. 	' Populate the namespaces list
  740. 	If gvaSettingsStr.Item( "NAMESPACE" ) = "" Then
  741. 		blnCheck = True
  742. 	Else
  743. 		blnCheck = False
  744. 	End If
  745. 	For i = 0 To UBound( gvaNamespaces )
  746. 		Set objNewOption  = document.createElement( "OPTION" )
  747. 		Set objNewOption2 = document.createElement( "OPTION" )
  748. 		If CInt( i / 2 ) <> ( i / 2 ) Then
  749. 			objNewOption.style.backgroundcolor  = "#F0F0F0"
  750. 			objNewOption2.style.backgroundcolor = "#F0F0F0"
  751. 		End If
  752. 		objNewOption.text   = gvaNamespaces(i)
  753. 		objNewOption.value  = gvaNamespaces(i)
  754. 		objNewOption2.text  = gvaNamespaces(i)
  755. 		objNewOption2.value = gvaNamespaces(i)
  756. 		If gvaSettingsStr.Item( "NAMESPACE" ) = "" Then
  757. 			If i = 0 Then
  758. 				objNewOption.selected  = True
  759. 				objNewOption2.selected = True
  760. 			Else
  761. 				objNewOption.selected  = False
  762. 				objNewOption2.selected = False
  763. 			End If
  764. 		Else
  765. 			If UCase( objNewOption.text ) = UCase( gvaSettingsStr.Item( "NAMESPACE" ) ) Then
  766. 				objNewOption.selected  = True
  767. 				objNewOption2.selected = True
  768. 				gvaSettingsStr.Item( "NAMESPACE" ) = objNewOption.text
  769. 				blnCheck = True
  770. 			Else
  771. 				objNewOption.selected  = False
  772. 				objNewOption2.selected = False
  773. 			End If
  774. 		End If
  775. 		Namespaces.options.add( objNewOption )
  776. 		Default_Namespace.options.add( objNewOption2 )
  777. 	Next
  778. 	If Not blnCheck Then
  779. 		gvbCommandlineValidate = False
  780. 		gvbNamespaceValidate   = False
  781. 	End If
  782. 	' Change cursor back to default
  783. 	Document.body.style.cursor = "default"
  784. 	HandleClassChange
  785. End Sub
  786.  
  787.  
  788. Function GetExt( myFile )
  789. 	Dim strExt, strFile, strNewExt
  790. 	' If .* was specified for the extension, replace it based on the language of choice
  791. 	strExt  = Mid( myFile, InStrRev( myFile, "." ) )
  792. 	strFile = myFile
  793. 	If strExt = ".*" Then
  794. 		If gvbCodeView Then
  795. 			' If gvbCodeView is true, the generated text is code
  796. 			Select Case UCase( gvaSettingsStr.Item( "LANGUAGE" ) )
  797. 				Case "BATCH":
  798. 					strNewExt = ".bat"
  799. 	            case "C#":
  800. 	            	strNewExt = ".cs"
  801. 	            Case "DELPHI":
  802. 	            	strNewExt = ".pas"
  803. 	            Case "F#":
  804. 	            	strNewExt = ".fs"
  805. 	            Case "JAVA":
  806. 	            	strNewExt = ".java"
  807. 	            Case "JSCRIPT":
  808. 	            	strNewExt = ".js"
  809. 	            Case "KIXTART":
  810. 	            	strNewExt = ".kix"
  811. 	            Case "LUA":
  812. 	            	strNewExt = ".lua"
  813. 	            Case "OBJECTPASCAL":
  814. 	            	strNewExt = ".pas"
  815. 	            Case "OBJECTREXX":
  816. 	            	strNewExt = ".rex"
  817. 	            Case "PERL":
  818. 	            	strNewExt = ".pl"
  819. 	            Case "POWERSHELL":
  820. 	            	strNewExt = ".ps1"
  821. 	            case "PYTHON":
  822. 	            	strNewExt = ".py"
  823. 	            Case "RUBY":
  824. 	            	strNewExt = ".rb"
  825. 	            Case "VB.NET":
  826. 	            	strNewExt = ".vb"
  827. 	            Case "VBSCRIPT":
  828. 	            	strNewExt = ".vbs"
  829. 			End Select
  830. 		Else
  831. 			' If gvbCodeView is false, the generated text is not code but a query result
  832. 			strNewExt = ".txt"
  833. 		End If
  834. 		strFile = Mid( strFile, 1, Len( strFile ) - 2 ) & strNewExt
  835. 	End If
  836. 	GetExt = strFile
  837. End Function
  838.  
  839.  
  840. Sub GetMSDNHelp( )
  841. 	Dim objOption, strClass, strMember, urlHelp, wshShell
  842. 	Set wshShell = CreateObject( "WScript.Shell" )
  843. 	' Check which class is selected
  844. 	For Each objOption In WMIClasses.options
  845. 		If objOption.selected = True Then
  846. 			strClass = Trim( objOption.text) & "+class"
  847. 		End If
  848. 	Next
  849. 	' Check which Property is selected, if any
  850. 	strMember = ""
  851. 	For Each objOption In Properties.options
  852. 		If objOption.selected = True Then
  853. 			strMember = "+" & Trim( objOption.text ) & "+property"
  854. 		End If
  855. 	Next
  856. 	' Check which Method is selected, if any
  857. 	For Each objOption In Methods.options
  858. 		If objOption.selected = True Then
  859. 			strMember = "+" & Trim( objOption.text ) & "+method"
  860. 		End If
  861. 	Next
  862. 	' Google search techniques learned from
  863. 	' http://www.seroundtable.com/archives/015944.html
  864. 	urlHelp = "https://www.google.com/search?q=" & strClass & strMember & "&site=msdn.microsoft.com&btnI=745&pws=0"
  865. 	wshShell.Run urlHelp, 3, False
  866. End Sub
  867.  
  868.  
  869. Function GetParameter( myString, myParameter )
  870. 	' Extract switch value from command line,
  871. 	' e.g. GetParameter( "/FAST /LANGUAGE:C# /NOUPD", "LANGUAGE" ) to extract "C#"
  872. 	Dim strItem, strParameter, strString
  873. 	' Default return value is an empty string
  874. 	GetParameter = ""
  875. 	strParameter = UCase( myParameter )
  876. 	myString     = Trim( myString )
  877. 	strString    = UCase( myString )
  878. 	If InStr( strString, "/" & strParameter & ":" ) Then
  879. 		' Step 1: extract switch and everything following it, e.g. "/LANGUAGE:C# /NOUPD"
  880. 		strItem = Mid( myString, InStr( strString, "/" & strParameter & ":" ) )
  881. 		' Check if there is anything following the switch and colon
  882. 		If Len( strItem ) > Len( "/" & strParameter & ":" ) Then
  883. 			' Step 2: remove the switch name and colon, e.g. in our example this leaves us with "C# /NOUPD"
  884. 			strItem = Mid( strItem, Len( "/" & strParameter & ":" ) + 1 )
  885. 			' Check again if there is anything left to parse
  886. 			If Len( strItem ) > 1 Then
  887. 				' Check if the value starts with a doublequote
  888. 				If Left( strItem, 1 ) = """" Then
  889. 					' Remove the opening doublequote
  890. 					strItem = Mid( strItem, 2 )
  891. 					' Remove the closing doublequote and everything after it
  892. 					strItem = Left( strItem, InStr( strItem, """" ) - 1 )
  893. 				Else
  894. 					' If not in doublequotes, remove the first space and everything following it,
  895. 					' e.g. in our example this leaves us with "C#"
  896. 					If InStr( strItem, " " ) Then strItem = Left( strItem, InStr( strItem, " " ) - 1 )
  897. 				End If
  898. 				' Return the result
  899. 				GetParameter = Trim( strItem )
  900. 			End If
  901. 		End If
  902. 	End If
  903. End Function
  904.  
  905.  
  906. Sub HandleBWChange( )
  907. 	Dim objRE, objTag
  908. 	Set objRE = New RegExp
  909. 	If BW.checked Then
  910. 		gvaDefaultsBool.Item( "BW" )        = True
  911. 		document.body.style.color           = "black"
  912. 		document.body.style.filter          = "none"
  913. 		For Each objTag In document.getElementsByTagName( "code" )
  914. 			objTag.style.color = "black"
  915. 		Next
  916. 		objRE.Pattern = "(^| )Code( |$)"
  917. 		For Each objTag In document.body.getElementsByTagName( "*" ) ' Selects all tags ...
  918. 			If objRE.Test( objTag.className ) Then ' ... with class "Code"
  919. 				objTag.style.color = "black"
  920. 			End If
  921. 		Next
  922. 		objRE.Pattern = "(^| )Red( |$)"
  923. 		For Each objTag In document.body.getElementsByTagName( "*" ) ' Selects all tags ...
  924. 			If objRE.Test( objTag.className ) Then ' ... with class "Red"
  925. 				objTag.style.color = "black"
  926. 			End If
  927. 		Next
  928. 	Else
  929. 		gvaDefaultsBool.Item( "BW" )        = False
  930. 		document.body.style.color           = "white"
  931. 		document.body.style.filter          = "progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr='#000000', EndColorStr='#FFFFFF');"
  932. 		For Each objTag In document.getElementsByTagName( "code" )
  933. 			objTag.style.color = "#006000"
  934. 		Next
  935. 		objRE.Pattern = "(^| )Code( |$)"
  936. 		For Each objTag In document.body.getElementsByTagName( "*" ) ' Selects all tags ...
  937. 			If objRE.Test( objTag.className ) Then ' ... with class "Code"
  938. 				objTag.style.color = "#006000"
  939. 			End If
  940. 		Next
  941. 		objRE.Pattern = "(^| )Red( |$)"
  942. 		For Each objTag In document.body.getElementsByTagName( "*" ) ' Selects all tags ...
  943. 			If objRE.Test( objTag.className ) Then ' ... with class "Red"
  944. 				objTag.style.color = "red"
  945. 			End If
  946. 		Next
  947. 	End If
  948. 	Set objRE = Nothing
  949. End Sub
  950.  
  951.  
  952. Sub HandleClassChange( )
  953. 	Dim intMethods, intProperties, i, j, k
  954. 	Dim objClass, objMethod, objNewOption, objOption, objProperty, objWMIService
  955. 	Dim strClass, strOption
  956. 	gvbCodeView = False
  957. 	' Purge the Methods list
  958. 	For Each objMethod in Methods.options
  959. 		objMethod.RemoveNode
  960. 	Next
  961. 	ReDim gvaMethods(0)
  962. 	intMethods = 0
  963. 	' Purge the Properties list
  964. 	For Each objProperty in Properties.options
  965. 		objProperty.RemoveNode
  966. 	Next
  967. 	ReDim gvaProperties(0)
  968. 	intProperties = 0
  969. 	' Change cursor to hourglass while loading the class' members lists
  970. 	Document.body.style.cursor = "wait"
  971. 	For Each objOption In WMIClasses.Options
  972. 		If objOption.selected = True Then
  973. 			strClass = objOption.text
  974. 			Set objWMIService = GetObject( "winmgmts:{impersonationLevel=impersonate}" & gvaSettingsStr.Item( "NAMESPACE" ) )
  975. 			Set objClass      = objWMIService.Get( strClass )
  976. 			' Store the list of methods in an array
  977. 			For Each objMethod In objClass.Methods_
  978. 				ReDim Preserve gvaMethods( intMethods )
  979. 				gvaMethods( intMethods ) = objMethod.Name
  980. 				intMethods = intMethods + 1
  981. 			Next
  982. 			If IsArray( gvaMethods ) Then
  983. 				' Sort the methods list
  984. 				ArraySort gvaMethods
  985. 			End If
  986. 			' Populate the Methods list
  987. 			i = 0
  988. 			For Each strOption in gvaMethods
  989. 				Set objNewOption  = document.createElement( "OPTION" )
  990. 				If CInt( i / 2 ) <> ( i / 2 ) Then
  991. 					objNewOption.style.backgroundcolor = "#F0F0F0"
  992. 				End If
  993. 				objNewOption.text = strOption
  994. 				Methods.options.Add( objNewOption )
  995. 				i = i + 1
  996. 			Next
  997. 			' Store the list of properties in an array
  998. 			For Each objProperty In objClass.Properties_
  999. 				ReDim Preserve gvaProperties( intProperties )
  1000. 				gvaProperties( intProperties ) = objProperty.Name
  1001. 				intProperties = intProperties + 1
  1002. 			Next
  1003. 			If IsArray( gvaProperties ) Then
  1004. 				' Sort the properties list
  1005. 				ArraySort gvaProperties
  1006. 			End If
  1007. 			' Populate the Properties list
  1008. 			i = 0
  1009. 			For Each strOption in gvaProperties
  1010. 				Set objNewOption  = document.createElement( "OPTION" )
  1011. 				If CInt( i / 2 ) <> ( i / 2 ) Then
  1012. 					objNewOption.style.backgroundcolor = "#F0F0F0"
  1013. 				End If
  1014. 				objNewOption.text = strOption
  1015. 				Properties.options.Add( objNewOption )
  1016. 				i = i + 1
  1017. 			Next
  1018. 		End If
  1019. 	Next
  1020. 	gvbClassesListed = True
  1021. 	' Change cursor back to default
  1022. 	Document.body.style.cursor = "default"
  1023. 	Code.value = ""
  1024. 	ButtonState
  1025. End Sub
  1026.  
  1027.  
  1028. Sub HandleLanguageChange( )
  1029. 	gvaSettingsStr.Item( "LANGUAGE" ) = CodeLanguage.value
  1030. 	gvbCodeView = False
  1031. 	If Trim( Code.value ) = "" Then
  1032. 		ButtonState
  1033. 		Code.value = ""
  1034. 	Else
  1035. 		ShowCode
  1036. 	End If
  1037. End Sub
  1038.  
  1039.  
  1040. Sub HandleNamespaceChange( )
  1041. 	Dim objOption
  1042. 	gvbCodeView = False
  1043. 	WMIClasses.innerHTML = ""
  1044. 	Code.value           = ""
  1045. 	Methods.innerHTML    = ""
  1046. 	Properties.innerHTML = ""
  1047. 	ButtonState
  1048. 	For Each objOption In Namespaces.options
  1049. 		If objOption.selected = True Then
  1050. 			gvaSettingsStr.Item( "NAMESPACE" ) = objOption.text
  1051. 		End If
  1052. 	Next
  1053. 	FillClassesDropdown
  1054. End Sub
  1055.  
  1056.  
  1057. Sub ShowHelp( )
  1058. 	Main.style.display     = "none"
  1059. 	Settings.style.display = "none"
  1060. 	Help.style.display     = "block"
  1061. 	Credits.style.display  = "none"
  1062. End Sub
  1063.  
  1064.  
  1065. Function IsAdmin( showMessage )
  1066.     ' Based on code by Denis St-Pierre
  1067.     Dim intbuttons, intRC
  1068.     Dim wshShell
  1069.     Dim strMsg, strTitle
  1070.     IsAdmin = False
  1071.     Set wshShell = CreateObject( "WScript.Shell" )
  1072.     On Error Resume Next
  1073.     intRC = wshShell.Run( "CMD /C OPENFILES > NUL 2>&1", 7, True )
  1074.     If Err Then intRC = 1
  1075.     On Error Goto 0
  1076. 	Set wshShell = Nothing
  1077.     If intRC = 0 Then
  1078.     	IsAdmin = True
  1079.     Else
  1080. 		If showMessage Then
  1081. 	   		intButtons = vbOKOnly + vbInformation + vbApplicationModal
  1082. 			strMsg     = "This HTA requires elevated privileges." & vbCrLf & vbCrLf _
  1083. 			           & "Please run this HTA as administrator."  & vbCrLf & vbCrLf & vbCrLf & vbCrLf _
  1084. 			           & "On some 64-bit systems, you may still get this message, wether running with elevated privileges or not." & vbCrLf & vbCrLf _
  1085. 			           & "Usually this is caused by HTAs being incorrectly associated with the 32-bit MSHTA version (%windir%\SysWOW64\mshta.exe)." & vbCrLf & vbCrLf _
  1086. 			           & "In that case, add the path to the proper (64-bit) MSHTA to this HTA's command line:" & vbCrLf & vbCrLf & vbCrLf _
  1087. 			           & """%windir%\system32\mshta.exe"" """ & Self.location.pathname & """"
  1088. 			strTitle   = "Elevated privileges required"
  1089. 			MsgBox strMsg, intButtons, strTitle
  1090. 		End If
  1091. 	End If
  1092. End Function
  1093.  
  1094.  
  1095. Function Max( num1, num2 )
  1096. 	If num1 > num2 Then
  1097. 		Max = num1
  1098. 	Else
  1099. 		Max = num2
  1100. 	End If
  1101. End Function
  1102.  
  1103.  
  1104. Function Min( num1, num2 )
  1105. 	If num1 < num2 Then
  1106. 		Min = num1
  1107. 	Else
  1108. 		Min = num2
  1109. 	End If
  1110. End Function
  1111.  
  1112.  
  1113. Sub OnClickButtonCancel( )
  1114. 	Main.style.display     = "block"
  1115. 	Settings.style.display = "none"
  1116. 	Help.style.display     = "none"
  1117. 	Credits.style.display  = "none"
  1118. End Sub
  1119.  
  1120.  
  1121. Sub OnClickButtonEditSettings( )
  1122. 	Dim objFile, objFSO, strConfig, wshShell
  1123. 	Set objFSO   = CreateObject( "Scripting.FileSystemObject" )
  1124. 	Set wshShell = CreateObject( "WScript.Shell" )
  1125. 	wshShell.Run "notepad.exe """ & gvsConfigFile & """", 3, True
  1126. 	Set wshShell = Nothing
  1127. 	Set objFSO   = Nothing
  1128. 	ConfigReadFile
  1129. 	ConfigUpdateStatus
  1130. End Sub
  1131.  
  1132.  
  1133. Sub OnClickButtonResetSettings( )
  1134. 	ConfigRemoveFile
  1135. 	ConfigReadDefaults
  1136. 	ConfigSetDefaults
  1137. 	ConfigUpdateStatus
  1138. End Sub
  1139.  
  1140.  
  1141. Sub OnClickButtonSaveSettings( )
  1142. 	ConfigSaveChanges
  1143. 	ConfigSaveFile
  1144. 	ConfigUpdateStatus
  1145. 	Main.style.display     = "block"
  1146. 	Settings.style.display = "none"
  1147. 	Help.style.display     = "none"
  1148. 	Credits.style.display  = "none"
  1149. End Sub
  1150.  
  1151.  
  1152. Sub OnClickButtonSettings( )
  1153. 	Dim objFile, objFSO, objOption
  1154. 	Main.style.display     = "none"
  1155. 	Settings.style.display = "block"
  1156. 	Help.style.display     = "none"
  1157. 	Credits.style.display  = "none"
  1158. 	If gvaSettingsStr.Item( "SIZE" ) = "" Then
  1159. 		Window_Size.value = "maximize"
  1160. 	Else
  1161. 		Window_Size.value = gvaSettingsStr.Item( "SIZE" )
  1162. 	End If
  1163. 	For Each objOption In Default_Language.options
  1164. 		If objOption.value = gvaSettingsStr.Item( "LANGUAGE" ) Then
  1165. 			objOption.selected = True
  1166. 		Else
  1167. 			objOption.selected = False
  1168. 		End If
  1169. 	Next
  1170. 	For Each objOption In Default_Namespace.options
  1171. 		If objOption.value = gvaSettingsStr.Item( "NAMESPACE" ) Then
  1172. 			objOption.selected = True
  1173. 		Else
  1174. 			objOption.selected = False
  1175. 		End If
  1176. 	Next
  1177. 	Exclusive_Namespace.checked = gvaSettingsBool.Item( "FAST" )
  1178. 	Win32_Only.checked          = gvaSettingsBool.Item( "WIN32" )
  1179. 	Exclude_Perf.checked        = gvaSettingsBool.Item( "NOPERF" )
  1180. 	Resource_Friendly.checked   = gvaSettingsBool.Item( "LOWRES" )
  1181. 	Use_Spaces.checked          = gvaSettingsBool.Item( "SPACES" )
  1182. 	Word_Wrap.checked           = gvaSettingsBool.Item( "WRAP" )
  1183. 	Update_Check.checked        = Not gvaSettingsBool.Item( "NOUPD" )
  1184. 	BW.checked                  = gvaSettingsBool.Item( "BW" )
  1185. 	Set objFSO = CreateObject( "Scripting.FileSystemObject" )
  1186. 	If objFSO.FileExists( gvsConfigFile ) Then
  1187. 		Set objFile = objFSO.OpenTextFile( gvsConfigFile, ForReading, False, TristateFalse )
  1188. 		Command_Line.value = Trim( Replace( objFile.ReadAll( ), vbCrLf, " " ) )
  1189. 		objFile.Close
  1190. 		Set objFile = Nothing
  1191. 	End If
  1192. 	Set objFSO = Nothing
  1193. End Sub
  1194.  
  1195.  
  1196. Sub RunCode( )
  1197. 	Dim i, maxLen
  1198. 	Dim colItems, objItem, objOption, objProperty, objWMIService
  1199. 	Dim strClass, strCode, strProperty
  1200. 	gvbCodeView = False
  1201. 	' Set word wrap
  1202. 	If gvaSettingsBool.Item( "WRAP" ) Then
  1203. 		Code.wrap = "soft"
  1204. 	Else
  1205. 		Code.wrap = "off"
  1206. 	End If
  1207. 	strClass = ""
  1208. 	For Each objOption In WMIClasses.Options
  1209. 		If objOption.selected = True Then
  1210. 			strClass = Trim( objOption.text )
  1211. 		End If
  1212. 	Next
  1213. 	If strClass = "" Then
  1214. 		ButtonState
  1215. 		Exit Sub
  1216. 	End If
  1217. 	i = 0
  1218. 	For Each objOption in Properties.options
  1219. 		If Trim( objOption.text ) <> "" Then
  1220. 			i = i + 1
  1221. 		End If
  1222. 	Next
  1223. 	If i = 0 Then
  1224. 		ButtonState
  1225. 		Exit Sub
  1226. 	End If
  1227. 	' Change mouse pointer to hourglass while running the code
  1228. 	Document.body.style.cursor = "wait"
  1229. 	Code.value                 = " . . . Please Wait . . ."
  1230. 	CodeLabel.innerHTML        = "Result:"
  1231. 	On Error Resume Next
  1232. 	Set objWMIService = GetObject( "winmgmts://./" & gvaSettingsStr.Item( "NAMESPACE" ) )
  1233. 	Set colItems      = objWMIService.InstancesOf( strClass )
  1234. 	If colItems.Count = 1 Then
  1235. 		strCode = "1 instance:"
  1236. 	Else
  1237. 		strCode = colItems.Count & " instances:"
  1238. 	End If
  1239. 	strCode = strCode & vbCrLf & vbCrLf
  1240. 	maxLen = 0
  1241. 	For Each objItem In colItems
  1242. 		For Each objProperty In objItem.Properties_
  1243. 			If Len( objProperty.Name ) > maxLen Then maxLen = Len( objProperty.Name )
  1244. 		Next
  1245. 	Next
  1246. 	For Each objItem In colItems
  1247. 		For Each objProperty In objItem.Properties_
  1248. 			strProperty = objProperty.Name
  1249. 			strCode = strCode & CreateLine( strProperty, maxLen ) & " "
  1250. 			If IsArray( objItem.Properties_.Item( strProperty, 0 ) ) Then
  1251. 				strCode = strCode & Join( objItem.Properties_.Item( strProperty, 0 ), ";" )
  1252. 			Else
  1253. 				strCode = strCode & objItem.Properties_.Item( strProperty, 0 )
  1254. 			End If
  1255. 			strCode = strCode & vbCrLf
  1256. 		Next
  1257. 		strCode = strCode & vbCrLf
  1258. 	Next
  1259. 	On Error Goto 0
  1260. 	Code.value = strCode
  1261. 	Code.title = "After pressing the 'Generate Code' button again, the generated code to display the available properties and their values for the selected WMI class and scripting language will be shown here once more"
  1262. 	ButtonState
  1263. 	' Change mouse pointer back to default
  1264. 	Document.body.style.cursor  = "default"
  1265. End Sub
  1266.  
  1267.  
  1268. Sub SaveCode( )
  1269. 	Dim intAnswer, intButtons
  1270. 	Dim objFile, objFSO
  1271. 	Dim strExt, strFile, strFolder, strMsg, strNewExt, strTitle
  1272. 	strFile = gvaSettingsStr( "SAVE" )
  1273. 	Set objFSO = CreateObject( "Scripting.FileSystemObject" )
  1274. 	If strFile = "" Or gvbInteractive Then
  1275. 		strTitle = "Enter File Name"
  1276. 		strMsg   = "Please enter the file (path and) name to save the generated code to:"
  1277. 		strFile  = Trim( InputBox( strMsg, strTitle, strFile ) )
  1278. 		If strFile = "" Then
  1279. 			intButtons = vbOKOnly + vbCritical + vbApplicationModal
  1280. 			strTitle   = "Invalid Path"
  1281. 			strMsg     = "No file was specified." & vbCrLf & vbCrLf & "Data could not be saved!"
  1282. 			MsgBox strMsg, intButtons, strTitle
  1283. 			Exit Sub
  1284. 		End If
  1285. 		strFolder = objFSO.GetParentFolderName( strFile )
  1286. 		If Not strFolder = "" Then
  1287. 			If Not objFSO.FolderExists( strFolder ) Then
  1288. 				intButtons = vbOKOnly + vbCritical + vbApplicationModal
  1289. 				strTitle   = "Invalid Path"
  1290. 				strMsg     = "The specified folder does not exist." & vbCrLf & vbCrLf & "Data could not be saved!"
  1291. 				MsgBox strMsg, intButtons, strTitle
  1292. 				Exit Sub
  1293. 			End If
  1294. 		End If
  1295. 	End If
  1296. 	' If .* was specified for the extension, replace it based on the language of choice
  1297. 	strFile = GetExt( strFile )
  1298. 	' If the specified output file exists, delete it first
  1299. 	If objFSO.FileExists( strFile ) Then objFSO.DeleteFile strFile, True
  1300. 	' Open the file for writing
  1301. 	Set objFile = objFSO.OpenTextFile( strFile, ForWriting, True, TristateFalse )
  1302. 	objFile.Write Code.value
  1303. 	objFile.Close
  1304. 	If gvbInteractive Then
  1305. 		intButtons = vbOKOnly + vbInformation + vbApplicationModal
  1306. 		strTitle   = "File Saved"
  1307. 		strMsg     = "The file was saved as" & vbCrLf & vbCrLf & objFSO.GetAbsolutePathName( strFile )
  1308. 		MsgBox strMsg, intButtons, strTitle
  1309. 	End If
  1310. 	Set objFile = Nothing
  1311. 	Set objFSO  = Nothing
  1312. End Sub
  1313.  
  1314.  
  1315. Sub ShowBatchCode( )
  1316. 	Dim strCode, strNamespace
  1317. 	If UCase( gvaSettingsStr.Item( "NAMESPACE" ) ) = "ROOT/CIMV2" Then
  1318. 		strNamespace = ""
  1319. 	Else
  1320. 		strNamespace = " /Namespace:\\" & Replace( gvaSettingsStr.Item( "NAMESPACE" ), "/", "\" )
  1321. 	End If
  1322. 	strCode = "@ECHO OFF\n" _
  1323. 	        & ":: WMI query to list all properties and values of the \\" & Replace( gvaSettingsStr.Item( "NAMESPACE" ), "/", "\" ) & ":" & gvsClass & " class.\n" _
  1324. 	        & ":: This batch file was generated using the WMI Code Generator, Version " & WMIGen.Version & "\n" _
  1325. 	        & ":: http://www.robvanderwoude.com/wmigen.php\n\n" _
  1326. 	        & "IF ""%~1""=="""" (\n" _
  1327. 	        & "\tSET Node=%ComputerName%\n" _
  1328. 	        & ") ELSE (\n" _
  1329. 	        & "\tSET Node=%~1\n" _
  1330. 	        & ")\n\n" _
  1331. 	        & "FOR /F %%A IN ('WMIC.EXE /Node:""%Node%""" & strNamespace & " Path " & gvsClass & " Get /Format:CSV ^| MORE /E +2 ^| FIND /C "",""') DO (\n" _
  1332. 	        & "\tIF %%A EQU 1 (\n" _
  1333. 	        & "\t\tECHO 1 instance:\n" _
  1334. 	        & "\t) ELSE (\n" _
  1335. 	        & "\t\tECHO %%A instances:\n" _
  1336. 	        & "\t)\n" _
  1337. 	        & ")\n\n" _
  1338. 	        & "WMIC.EXE /Node:""%Node%""" & strNamespace & " Path " & gvsClass & " Get /Format:LIST\n"
  1339. 	strCode = Replace( Replace( strCode, "\n", vbCrLf ), "\t", vbTab )
  1340. 	Code.value = strCode
  1341. 	ButtonState
  1342. End Sub
  1343.  
  1344.  
  1345. Sub ShowCode( )
  1346. 	Dim i, objOption
  1347. 	gvbCodeView = False
  1348. 	' Change mouse pointer to hourglass while running the code
  1349. 	Document.body.style.cursor = "wait"
  1350. 	Codelabel.innerHTML        = "Code:"
  1351. 	' Set word wrap
  1352. 	If gvaSettingsBool.Item( "WRAP" ) Then
  1353. 		Code.wrap = "soft"
  1354. 	Else
  1355. 		Code.wrap = "off"
  1356. 	End If
  1357. 	gvsClass = ""
  1358. 	For Each objOption In WMIClasses.Options
  1359. 		If objOption.selected = True Then
  1360. 			gvsClass = Trim( objOption.value )
  1361. 		End If
  1362. 	Next
  1363. 	If gvsClass = "" Then
  1364. 		ButtonState
  1365. 		Exit Sub
  1366. 	End If
  1367. 	' Check if there are any properties
  1368. 	i = 0
  1369. 	For Each objOption in Properties.options
  1370. 		If Trim( objOption.text ) <> "" Then
  1371. 			i = i + 1
  1372. 		End If
  1373. 	Next
  1374. 	If i = 0 Then
  1375. 		ButtonState
  1376. 		Exit Sub
  1377. 	End If
  1378. 	gvbCodeView = True
  1379. 	Set gvoWMIService = GetObject( "winmgmts:{impersonationLevel=impersonate}" & gvaSettingsStr.Item( "NAMESPACE" ) )
  1380. 	Set gvoClass      = gvoWMIService.Get( gvsClass )
  1381. 	gviMaxLen = 0
  1382. 	For Each gvoProperty In gvoClass.Properties_
  1383. 		If Len( gvoProperty.Name ) > gviMaxLen Then
  1384. 			gviMaxLen = Len( gvoProperty.Name )
  1385. 		End If
  1386. 	Next
  1387. 	Select Case CodeLanguage.value
  1388. 		Case "Batch"
  1389. 			ShowBatchCode
  1390. 		Case "C#"
  1391. 			ShowCSharpCode
  1392. 		Case "Delphi", "ObjectPascal"
  1393. 			ShowPascalCode
  1394. 		Case "F#"
  1395. 			ShowFSharpCode
  1396. 		Case "Java"
  1397. 			ShowJavaCode
  1398. 		Case "JScript"
  1399. 			ShowJScriptCode
  1400. 		Case "KiXtart"
  1401. 			ShowKiXtartCode
  1402. 		Case "Lua"
  1403. 			ShowLuaCode
  1404. 		Case "ObjectRexx"
  1405. 			ShowObjectRexxCode
  1406. 		Case "Perl"
  1407. 			ShowPerlCode
  1408. 		Case "PowerShell"
  1409. 			ShowPowerShellCode
  1410. 		Case "Python"
  1411. 			ShowPythonCode
  1412. 		Case "Ruby"
  1413. 			ShowRubyCode
  1414. 		Case "VB.NET"
  1415. 			ShowVBDotNETCode
  1416. 		Case "VBScript"
  1417. 			ShowVBScriptCode
  1418. 	End Select
  1419. 	Set gvoClass      = Nothing
  1420. 	Set gvoWMIService = Nothing
  1421. 	' Change mouse pointer back to default
  1422. 	Document.body.style.cursor  = "default"
  1423. 	Code.title = "After pressing the 'Run WMI Code' button, the generated (VBScript) code will be executed, and the result will be shown here"
  1424. End Sub
  1425.  
  1426.  
  1427. Sub ShowCredits( )
  1428. 	Main.style.display     = "none"
  1429. 	Settings.style.display = "none"
  1430. 	Help.style.display     = "none"
  1431. 	Credits.style.display  = "block"
  1432. End Sub
  1433.  
  1434.  
  1435. Sub ShowCSharpCode( )
  1436. 	Dim intCIMType
  1437. 	Dim objProperty
  1438. 	Dim strCIMType, strCode
  1439. 	Const wbemCIMTypeSint16    =   2 'Signed 16-bit integer
  1440. 	Const wbemCIMTypeSint32    =   3 'Signed 32-bit integer
  1441. 	Const wbemCIMTypeReal32    =   4 '32-bit real number
  1442. 	Const wbemCIMTypeReal64    =   5 '64-bit real number
  1443. 	Const wbemCIMTypeString    =   8 'String
  1444. 	Const wbemCIMTypeBoolean   =  11 'Boolean value
  1445. 	Const wbemCIMTypeObject    =  13 'CIM object
  1446. 	Const wbemCIMTypeSint8     =  16 'Signed 8-bit integer
  1447. 	Const wbemCIMTypeUint8     =  17 'Unsigned 8-bit integer
  1448. 	Const wbemCIMTypeUint16    =  18 'Unsigned 16-bit integer
  1449. 	Const wbemCIMTypeUint32    =  19 'Unsigned 32-bit integer
  1450. 	Const wbemCIMTypeSint64    =  20 'Signed 64-bit integer
  1451. 	Const wbemCIMTypeUint64    =  21 'Unsigned 64-bit integer
  1452. 	Const wbemCIMTypeDatetime  = 101 'Date/time value
  1453. 	Const wbemCIMTypeReference = 102 'Reference to a CIM object
  1454. 	Const wbemCIMTypeChar16    = 103 '16-bit character
  1455. 	strCode = "// WMI query to list all properties and values of the " & Replace( gvaSettingsStr.Item( "NAMESPACE" ), "/", "\" ) & ":" & gvsClass & " class.\n" _
  1456. 	        & "// This C# code was generated using the WMI Code Generator, Version " & WMIGen.Version & "\n" _
  1457. 	        & "// http://www.robvanderwoude.com/wmigen.php \n\n" _
  1458. 	        & "using System;\n" _
  1459. 	        & "using System.Linq;\n" _
  1460. 	        & "using System.Management;\n\n" _
  1461. 	        & "namespace WMIGen\n" _
  1462. 	        & "{\n" _
  1463. 	        & "\tpublic class " & gvsClass & "_Query\n" _
  1464. 	        & "\t{\n" _
  1465. 	        & "\t\tpublic static int Main(string[] args)\n" _
  1466. 	        & "\t\t{\n" _
  1467. 	        & "\t\t\ttry\n" _
  1468. 	        & "\t\t\t{\n" _
  1469. 	        & "\t\t\t\tstring computer = string.Empty;\n" _
  1470. 	        & "\t\t\t\tif (args.Count() == 1)\n" _
  1471. 	        & "\t\t\t\t{\n" _
  1472. 	        & "\t\t\t\t\tcomputer = @""\\"" + args[0] + @""\"";\n" _
  1473. 	        & "\t\t\t\t}\n\n" _
  1474. 	        & "\t\t\t\tManagementObjectSearcher searcher = new ManagementObjectSearcher(computer + @""" & Replace( gvaSettingsStr.Item( "NAMESPACE" ), "/", "\" ) & """, ""SELECT * FROM " & gvsClass & """);\n" _
  1475. 	        & "\t\t\t\tManagementObjectCollection colItems = searcher.Get( );\n\n" _
  1476. 	        & "\t\t\t\tConsole.WriteLine( ""{0} instance{1}"", colItems.Count, ( colItems.Count == 1 ? String.Empty : ""s"" ) );\n" _
  1477. 	        & "\t\t\t\tConsole.WriteLine( );\n\n" _
  1478. 	        & "\t\t\t\tforeach ( ManagementObject queryObj in colItems )\n" _
  1479. 	        & "\t\t\t\t{\n"
  1480. 	For Each objProperty In gvoClass.Properties_
  1481. 		If objProperty.IsArray = True Then
  1482. 			intCIMType = objProperty.CIMType
  1483. 			If intCIMType < 8 Then
  1484. 				strCIMType = "UInt16"
  1485. 			ElseIf intCIMType > 15 And intCIMType < 100 Then
  1486. 				strCIMType = "UInt16"
  1487. 			Else
  1488. 				strCIMType = "string"
  1489. 			End If
  1490. 			strCode = strCode _
  1491. 			        & "\t\t\t\t\tif (queryObj[""" & objProperty.Name & """] == null)\n" _
  1492. 			        & "\t\t\t\t\t{\n" _
  1493. 			        & "\t\t\t\t\t\tConsole.WriteLine(""" & CreateLine( objProperty.Name, gviMaxLen ) & " "");\n" _
  1494. 			        & "\t\t\t\t\t}\n" _
  1495. 			        & "\t\t\t\t\telse\n" _
  1496. 			        & "\t\t\t\t\t{\n" _
  1497. 			        & "\t\t\t\t\t\t" & strCIMType & "[] arrProperty = (" & strCIMType & "[])(queryObj[""" & objProperty.Name & """]);\n" _
  1498. 			        & "\t\t\t\t\t\tConsole.Write(""" & CreateLine( objProperty.Name, gviMaxLen ) & " "");\n" _
  1499. 			        & "\t\t\t\t\t\tConsole.WriteLine(string.Join("";"", arrProperty.Select(cap => cap.ToString()).ToArray()));\n" _
  1500. 			        & "\t\t\t\t\t}\n"
  1501. 		Else
  1502. 			strCode = strCode _
  1503. 			        & "\t\t\t\t\tConsole.WriteLine(""" & CreateLine( objProperty.Name, gviMaxLen ) & " {0}"", queryObj[""" & objProperty.Name & """]);\n"
  1504. 		End If
  1505. 	Next
  1506. 	strCode = strCode _
  1507. 	        & "\t\t\t\t\tConsole.WriteLine();\n" _
  1508. 	        & "\t\t\t\t}\n" _
  1509. 	        & "\t\t\t\treturn 0;\n" _
  1510. 	        & "\t\t\t}\n" _
  1511. 	        & "\t\t\tcatch (Exception e)\n" _
  1512. 	        & "\t\t\t{\n" _
  1513. 	        & "\t\t\t\tConsole.Error.WriteLine(""An error occurred while querying WMI: {0}"", e.Message);\n" _
  1514. 	        & "\t\t\t\treturn 1;\n" _
  1515. 	        & "\t\t\t}\n" _
  1516. 	        & "\t\t}\n" _
  1517. 	        & "\t}\n" _
  1518. 	        & "}\n"
  1519. 	strCode = Replace( Replace( strCode, "\n", vbCrLf ), "\t", vbTab )
  1520. 	Code.value = strCode
  1521. 	ButtonState
  1522. End Sub
  1523.  
  1524.  
  1525. Sub ShowFSharpCode( )
  1526. 	Dim objProperty, strCode
  1527. 	strCode = "// WMI query to list all properties and values of the " & Replace( gvaSettingsStr.Item( "NAMESPACE" ), "/", "\" ) & ":" & gvsClass & " class.\n" _
  1528. 	        & "// This F# code was generated using the WMI Code Generator, Version " & WMIGen.Version & "\n" _
  1529. 	        & "// http://www.robvanderwoude.com/wmigen.php\n\n" _
  1530. 	        & "#if INTERACTIVE\n" _
  1531. 	        & "#r ""System""\n" _
  1532. 	        & "#r ""System.Management""\n" _
  1533. 	        & "#endif\n\n" _
  1534. 	        & "open System\n" _
  1535. 	        & "open System.Management\n\n" _
  1536. 	        & "let scope = ManagementScope(@""\\localhost\" & Replace( gvaSettingsStr.Item( "NAMESPACE" ), "/", "\" ) & """)\n" _
  1537. 	        & "let query = ObjectQuery(""SELECT * FROM " & gvsClass & """)\n" _
  1538. 	        & "let searcher = new ManagementObjectSearcher(query)\n" _
  1539. 	        & "let colItems = searcher.Get( )\n\n" _
  1540. 	        & "printfn ""%A instance(s)"" (colItems.Count)\n" _
  1541. 	        & "printfn """"\n\n" _
  1542. 	        & "for obj in colItems do\n"
  1543. 	For Each objProperty In gvoClass.Properties_
  1544. 		strCode = strCode & "    printfn """ & CreateLine( objProperty.Name, gviMaxLen ) & " %A"" (obj.GetPropertyValue(""" & objProperty.Name & """))\n"
  1545. 	Next
  1546. 	strCode = strCode & "    printfn """""
  1547. 	strCode = Replace( strCode, "\n", vbCrLf )
  1548. 	Code.value = strCode
  1549. 	ButtonState
  1550. End Sub
  1551.  
  1552.  
  1553. Sub ShowJavaCode( )
  1554. 	Dim objProperty, strCode
  1555. 	strCode = "/**" & vbCrLf _
  1556. 	        & " * WMI query to list all properties and values of the \\" & Replace( gvaSettingsStr.Item( "NAMESPACE" ), "/", "\" ) & ":" & gvsClass & " class." & vbCrLf _
  1557. 	        & " * Based on a JACOB sample by 'NickDMax' on DreamInCode.net:" & vbCrLf _
  1558. 	        & " * http://www.dreamincode.net/code/snippet3297.htm"  & vbCrLf _
  1559. 	        & " * This Java code requires JACOB (JAva COm Bridge):" & vbCrLf _
  1560. 	        & " * http://sourceforge.net/projects/jacob-project/"   & vbCrLf _
  1561. 	        & " * This Java code was generated using the WMI Code Generator, Version " & WMIGen.Version & vbCrLf _
  1562. 	        & " * http://www.robvanderwoude.com/wmigen.php" & vbCrLf _
  1563. 	        & " */" & vbCrLf & vbCrLf _
  1564. 	        & "import com.jacob.activeX.ActiveXComponent;\n" _
  1565. 	        & "import com.jacob.com.Dispatch;\n" _
  1566. 	        & "import com.jacob.com.EnumVariant;\n" _
  1567. 	        & "import com.jacob.com.Variant;\n" & vbCrLf _
  1568. 	        & "public class WMIGen_" & gvsClass & " {\n" _
  1569. 	        & "\t/**" & vbCrLf _
  1570. 	        & "\t * @param args" & vbCrLf _
  1571. 	        & "\t */" & vbCrLf _
  1572. 	        & "\tpublic static void main(String[] args) {\n" _
  1573. 	        & "\t\tString host = ""localhost"";\n" _
  1574. 	        & "\t\tif (args.length > 0) {\n" _
  1575. 	        & "\t\t\thost = args[0];\n" _
  1576. 	        & "\t\t}\n" _
  1577. 	        & "\t\tString connectStr = String.format(""winmgmts:\\\\%s\\" & Replace( gvaSettingsStr.Item( "NAMESPACE" ), "/", "\\" ) & """, host);\n" _
  1578. 	        & "\t\tString query = ""SELECT * FROM " & gvsClass & """;\n" _
  1579. 	        & "\t\tString property = """";\n" _
  1580. 	        & "\t\tActiveXComponent axWMI = new ActiveXComponent(connectStr);\n" _
  1581. 	        & "\t\tVariant vCollection = axWMI.invoke(""ExecQuery"", new Variant(query));\n" _
  1582. 	        & "\t\tEnumVariant enumVariant = new EnumVariant(vCollection.toDispatch());\n" _
  1583. 	        & "\t\tDispatch item = null;\n" _
  1584. 	        & "\t\twhile (enumVariant.hasMoreElements()) {\n" _
  1585. 	        & "\t\t\titem = enumVariant.nextElement().toDispatch();\n"
  1586. 	For Each objProperty In gvoClass.Properties_
  1587. 		strCode = strCode _
  1588. 		        & "\t\t\tproperty = Dispatch.call(item,""" & objProperty.Name & """).toString();\n" _
  1589. 		        & "\t\t\tSystem.out.printf(""" & CreateLine( objProperty.Name, gviMaxLen ) & " %s\n"",property);\n"
  1590. 	Next
  1591. 	strCode = strCode _
  1592. 	        & "\t\t\tSystem.out.printf(""\n"");\n" _
  1593. 	        & "\t\t}\n" _
  1594. 	        & "\t}\n" _
  1595. 	        & "}\n"
  1596. 	strCode = Replace( strCode, "\n\n *", vbCrLf & vbCrLf )
  1597. 	strCode = Replace( strCode, ";\n", ";" & vbCrLf )
  1598. 	strCode = Replace( strCode, "}\n", "}" & vbCrLf )
  1599. 	strCode = Replace( strCode, "{\n", "{" & vbCrLf )
  1600. 	strCode = Replace( strCode, "\t", vbTab )
  1601. 	Code.value = strCode
  1602. 	ButtonState
  1603. End Sub
  1604.  
  1605.  
  1606. Sub ShowJScriptCode( )
  1607. 	' IsArray and Join() functionality "borrowed" from Scriptomatic 2.0
  1608. 	' http://www.microsoft.com/downloads/details.aspx?FamilyID=09dfc342-648b-4119-b7eb-783b0f7d1178&DisplayLang=en
  1609. 	Dim objProperty, strCode
  1610. 	strCode = "// WMI query to list all properties and values of the " & gvaSettingsStr.Item( "NAMESPACE" ) & ":" & gvsClass & " class.\n" _
  1611. 	        & "// This JScript code was generated using the WMI Code Generator, Version " & WMIGen.Version & "\n" _
  1612. 	        & "// http://www.robvanderwoude.com/wmigen.php\n\n"
  1613. 	If gvaSettingsBool.Item( "LOWRES" ) Then
  1614. 		strCode = strCode _
  1615. 		        & "var wbemFlagReturnImmediately = 0x10;\n" _
  1616. 		        & "var wbemFlagForwardOnly       = 0x20;\n\n"
  1617. 	End If
  1618. 	strCode = strCode _
  1619. 	        & "objArgs = WScript.Arguments;\n" _
  1620. 	        & "if ( objArgs.length == 1 ) {\n" _
  1621. 	        & "\tvar strComputer = objArgs[0];\n" _
  1622. 	        & "} else {\n" _
  1623. 	        & "\tvar strComputer = ""."";\n" _
  1624. 	        & "}\n\n" _
  1625. 	        & "var objWMIService = GetObject( ""winmgmts://"" + strComputer + ""/" & gvaSettingsStr.Item( "NAMESPACE" ) & """ );\n"
  1626. 	If gvaSettingsBool.Item( "LOWRES" ) Then
  1627. 		strCode = strCode _
  1628. 		        & "var colItems      = objWMIService.ExecQuery( ""SELECT * FROM " & gvsClass & """, ""WQL"", wbemFlagReturnImmediately | wbemFlagForwardOnly );\n\n"
  1629. 	Else
  1630. 		strCode = strCode _
  1631. 		        & "var colItems      = objWMIService.ExecQuery( ""SELECT * FROM " & gvsClass & """ );\n\n" _
  1632. 		        & "if ( colItems.Count == 1 ) {\n" _
  1633. 		        & "\tWScript.Echo( ""1 instance:"" );\n" _
  1634. 		        & "} else {\n" _
  1635. 		        & "\tWScript.Echo( colItems.Count + "" instances:"" );\n" _
  1636. 		        & "}\n" _
  1637. 		        & "WScript.Echo( );\n\n"
  1638. 	End If
  1639. 	strCode = strCode _
  1640. 	        & "var enumItems = new Enumerator( colItems );\n" _
  1641. 	        & "for ( ; !enumItems.atEnd(); enumItems.moveNext( ) ) {\n" _
  1642. 	        & "\tvar objItem = enumItems.item( );\n"
  1643. 	For Each objProperty In gvoClass.Properties_
  1644. 		strCode = strCode _
  1645. 			        & "\ttry {\n" _
  1646. 			        & "\t\tif ( objItem." & objProperty.Name & " == null ) {\n" _
  1647. 			        & "\t\t\tWScript.Echo( """ & CreateLine( objProperty.Name, gviMaxLen ) & " "" );\n" _
  1648. 			        & "\t\t} else {\n"
  1649. 		If objProperty.IsArray = True Then
  1650. 			strCode = strCode & "\t\t\tWScript.Echo( """ & CreateLine( objProperty.Name, gviMaxLen ) & " "" + ( objItem." & objProperty.Name & ".toArray( ) ).join( "","" ) );\n"
  1651. 		Else
  1652. 			strCode = strCode & "\t\t\tWScript.Echo( """ & CreateLine( objProperty.Name, gviMaxLen ) & " "" + objItem." & objProperty.Name & " );\n"
  1653. 		End If
  1654. 		strCode = strCode _
  1655. 		        & "\t\t}\n" _
  1656. 		        & "\t}\n" _
  1657. 		        & "\tcatch( e ) {\n" _
  1658. 		        & "\t\tWScript.Echo( """ & CreateLine( objProperty.Name, gviMaxLen ) & " "" );\n" _
  1659. 		        & "\t}\n"
  1660. 	Next
  1661. 	strCode = strCode _
  1662. 	        & "\tWScript.Echo( """" );\n" _
  1663. 	        & "}\n"
  1664. 	strCode = Replace( Replace( strCode, "\n", vbCrLf ), "\t", vbTab )
  1665. 	Code.value = strCode
  1666. 	ButtonState
  1667. End Sub
  1668.  
  1669.  
  1670. Sub ShowKiXtartCode( )
  1671. 	Dim objProperty, strCode
  1672. 	strCode = "; WMI query to list all properties and values of the " & gvaSettingsStr.Item( "NAMESPACE" ) & ":" & gvsClass & " class.\n" _
  1673. 	        & "; This KiXtart script was generated using the WMI Code Generator, Version " & WMIGen.Version & "\n" _
  1674. 	        & "; http://www.robvanderwoude.com/wmigen.php\n\n"
  1675. 	If gvaSettingsBool.Item( "LOWRES" ) Then
  1676. 		strCode = strCode _
  1677. 		        & "$wbemFlagReturnImmediately = &10\n" _
  1678. 		        & "$wbemFlagForwardOnly       = &20\n\n"
  1679. 	End If
  1680. 	strCode = strCode _
  1681. 	        & "Break On\n\n" _
  1682. 	        & "If $computer = """"\n" _
  1683. 	        & "\t$arrKixVer = Split( @Kix, ""."" )\n" _
  1684. 	        & "\t$KiXVer    = 100 * $arrKixVer[0] + $arrKixVer[1]\n" _
  1685. 	        & "\t$computer  = "".""\n" _
  1686. 	        & "\tIf $KixVer > 451\n" _
  1687. 	        & "\t\t$arrGetCommandLine = GetCommandLine(1)\n" _
  1688. 	        & "\t\t$LastArg = $arrGetCommandLine[ UBound( $arrGetCommandLine ) ]\n" _
  1689. 	        & "\t\tIf $LastArg <> ""@ScriptDir\@ScriptName""\n" _
  1690. 	        & "\t\t\t$computer = $LastArg\n" _
  1691. 	        & "\t\tEndIf\n" _
  1692. 	        & "\tEndIf\n" _
  1693. 	        & "EndIf\n\n" _
  1694. 	        & "$objWMIService = GetObject( ""winmgmts://"" + $computer + ""/" & gvaSettingsStr.Item( "NAMESPACE" ) & """ )\n"
  1695. 	If gvaSettingsBool.Item( "LOWRES" ) Then
  1696. 		strCode = strCode & "$colItems      = $objWMIService.ExecQuery( ""SELECT * FROM " & gvsClass & """, ""WQL"", wbemFlagReturnImmediately + wbemFlagForwardOnly )\n\n"
  1697. 	Else
  1698. 		strCode = strCode _
  1699. 		        & "$colItems      = $objWMIService.ExecQuery( ""SELECT * FROM " & gvsClass & """ )\n\n" _
  1700. 		        & "If $colItems.Count = 1\n" _
  1701. 		        & "\t? ""1 instance:"" ?\n" _
  1702. 		        & "Else\n" _
  1703. 		        & "\t? """" + $colItems.Count + "" instances:"" ?\n" _
  1704. 		        & "EndIf\n\n"
  1705. 	End If
  1706. 	strCode = strCode & "For Each $objItem In $colItems\n"
  1707. 	For Each objProperty In gvoClass.Properties_
  1708. 		strCode = strCode & "\t? """ & CreateLine( objProperty.Name, gviMaxLen ) & " "" + "
  1709. 		If objProperty.IsArray = True Then strCode = strCode & "Join( "
  1710. 		strCode = strCode & "$objItem." & objProperty.Name
  1711. 		If objProperty.IsArray = True Then strCode = strCode & ", "","" )"
  1712. 		strCode = strCode & "\n"
  1713. 	Next
  1714. 	strCode = strCode _
  1715. 	        & "\t?\n" _
  1716. 	        & "Next\n\n" _
  1717. 	        & "Quit\n"
  1718. 	strCode = Replace( Replace( strCode, "\n", vbCrLf ), "\t", vbTab )
  1719. 	Code.value = strCode
  1720. 	ButtonState
  1721. End Sub
  1722.  
  1723.  
  1724. Sub ShowLuaCode( )
  1725. 	Dim objProperty, strCode
  1726. 	strCode = "-- WMI query to list all properties and values of the " & gvaSettingsStr.Item( "NAMESPACE" ) & ":" & gvsClass & " class.\n" _
  1727. 	        & "-- This Lua code requires Lua for Windows:\n" _
  1728. 	        & "-- https://code.google.com/p/luaforwindows/\n" _
  1729. 	        & "-- This Lua script was generated using the WMI Code Generator, Version " & WMIGen.Version & "\n" _
  1730. 	        & "-- http://www.robvanderwoude.com/wmigen.php\n\n" _
  1731. 	        & "require( ""luacom"" )\n\n" _
  1732. 	        & "luacom.config.abort_on_API_error = true\n" _
  1733. 	        & "luacom.config.abort_on_error = false\n\n" _
  1734. 	        & "if arg[1] == nil then\n" _
  1735. 	        & "\tcomputer = "".""\n" _
  1736. 	        & "else\n" _
  1737. 	        & "\tcomputer = arg[1]\n" _
  1738. 	        & "end\n\n" _
  1739. 	        & "function display( objval )\n" _
  1740. 	        & "\tif objval == nil then\n" _
  1741. 	        & "\t\treturn """"\n" _
  1742. 	        & "\tend\n" _
  1743. 	        & "\tif type( objval ) == ""table"" then\n" _
  1744. 	        & "\t\treturn table.concat( objval, "";"" )\n" _
  1745. 	        & "\tend\n" _
  1746. 	        & "\treturn tostring( objval )\n" _
  1747. 	        & "end\n\n" _
  1748. 	        & "objWMIService = luacom.GetObject( ""winmgmts:{impersonationLevel=Impersonate}!//""..computer..""/root/cimv2"" )\n" _
  1749. 	        & "objSWbemRefresher = luacom.CreateObject( ""WbemScripting.SWbemRefresher"" )\n" _
  1750. 	        & "objSWbemRefresher.AutoReconnect = 1\n" _
  1751. 	        & "refobj" & gvsClass & " = objSWbemRefresher:AddEnum( objWMIService, """ & gvsClass & """ )\n" _
  1752. 	        & "objSWbemRefresher:Refresh( )\n" _
  1753. 	        & "obj" & gvsClass & "Enum = luacom.GetEnumerator( refobj" & gvsClass & ".ObjectSet )\n\n" _
  1754. 	        & "objSWbemRefresher:Refresh( )\n" _
  1755. 	        & "obj" & gvsClass & "Enum:Reset( )\n" _
  1756. 	        & "test = refobj" & gvsClass & ".ObjectSet.Count\n" _
  1757. 	        & "if test == 1 then\n" _
  1758. 	        & "\tprint( ""1 instance:"" )\n" _
  1759. 	        & "else\n" _
  1760. 	        & "\tprint( test.."" instances:"" )\n" _
  1761. 	        & "end\n" _
  1762. 	        & "print( )\n\n" _
  1763. 	        & "objSWbemRefresher:Refresh( )\n" _
  1764. 	        & "obj" & gvsClass & "Enum:Reset( )\n" _
  1765. 	        & "item = obj" & gvsClass & "Enum:Next( )\n" _
  1766. 	        & "while item do\n"
  1767. 	For Each objProperty In gvoClass.Properties_
  1768. 		strCode = strCode & vbTab & "print( """ & CreateLine( objProperty.Name, gviMaxLen ) & " ""..display(item:" & objProperty.Name & "( ) ) )\n"
  1769. 	Next
  1770. 	strCode = strCode _
  1771. 	        & "\tprint( )\n" _
  1772. 	        & "\titem = obj" & gvsClass & "Enum:Next( )\n" _
  1773. 	        & "end\n" _
  1774. 	        & "item = nil\n" _
  1775. 	        & "collectgarbage( )\n\n" _
  1776. 	        & "objWMIService = nil\n" _
  1777. 	        & "objSWbemRefresher = nil\n" _
  1778. 	        & "refobj" & gvsClass & " = nil\n" _
  1779. 	        & "obj" & gvsClass & "Enum = nil\n" _
  1780. 	        & "collectgarbage( )\n"
  1781. 	strCode = Replace( Replace( strCode, "\n", vbCrLf ), "\t", vbTab )
  1782. 	Code.value = strCode
  1783. 	ButtonState
  1784. End Sub
  1785.  
  1786.  
  1787. Sub ShowObjectRexxCode( )
  1788. 	' Based on the Rexx script samples found at the Script Repository:
  1789. 	' http://www.microsoft.com/technet/scriptcenter/scripts/rexx/default.mspx
  1790. 	' Tested with Open Object Rexx: http://www.oorexx.org/
  1791. 	Dim objProperty, strCode
  1792. 	strCode = "/*\n" _
  1793. 	        & "WMI query to list all properties and values of the " & gvaSettingsStr.Item( "NAMESPACE" ) & ":" & gvsClass & " class.\n" _
  1794. 	        & "This Open Object Rexx script was generated using the WMI Code Generator, Version " & WMIGen.Version & "\n" _
  1795. 	        & "http://www.robvanderwoude.com/wmigen.php\n" _
  1796. 	        & "*/\n\n"
  1797. 	If gvaSettingsBool.Item( "LOWRES" ) Then
  1798. 		strCode = strCode _
  1799. 		        & "wbemFlagReturnImmediately = 16\n" _
  1800. 		        & "wbemFlagForwardOnly       = 32\n\n"
  1801. 	End If
  1802. 	strCode = strCode _
  1803. 	        & "Parse Upper Arg strComputer .\n" _
  1804. 	        & "If strComputer = """" Then strComputer = "".""\n\n" _
  1805. 	        & "objWMIService = .OLEObject~GetObject( ""winmgmts://""||strComputer||""/" & gvaSettingsStr.Item( "NAMESPACE" ) & """ )\n"
  1806. 	If gvaSettingsBool.Item( "LOWRES" ) Then
  1807. 		strCode = strCode & "colItems = objWMIService~ExecQuery( ""SELECT * FROM " & gvsClass & """, ""WQL"", wbemFlagReturnImmediately + wbemFlagForwardOnly );\n\n"
  1808. 	Else
  1809. 		strCode = strCode _
  1810. 		        & "colItems = objWMIService~ExecQuery( ""SELECT * FROM " & gvsClass & """ )\n\n" _
  1811. 		        & "If colItems~Count = 1 Then Say ""1 instance:""; Else Say colItems~Count||"" instances:""\n" _
  1812. 		        & "Say\n\n"
  1813. 	End If
  1814. 	strCode = strCode & "Do objItem Over colItems\n"
  1815. 	For Each objProperty In gvoClass.Properties_
  1816. 		If objProperty.IsArray = True Then
  1817. 			strCode = strCode _
  1818. 			        & "\tstr" & objProperty.Name & " = """"\n" _
  1819. 		            & "\tIf objItem~" & objProperty.Name & " <> .NIL Then\n" _
  1820. 			        & "\t\tDo i = 1 To Length(objItem~" & objProperty.Name & ")\n" _
  1821. 			        & "\t\t\tIf objItem~" & objProperty.Name & "[i] <> .NIL Then str" & objProperty.Name & " = str" & objProperty.Name & "||"",""||objItem~" & objProperty.Name & "[i]\n" _
  1822. 			        & "\t\tEnd\n" _
  1823. 			        & "\tIf Length( str" & objProperty.Name & ") > 1 Then str" & objProperty.Name & " = str" & objProperty.Name & "~substr(2,)\n" _
  1824. 			        & "\tSay """ & CreateLine( objProperty.Name, gviMaxLen ) & " ""||str" & objProperty.Name & "\n"
  1825. 		Else
  1826. 			strCode = strCode _
  1827. 		            & "\tIf objItem~" & objProperty.Name & " = .NIL Then str" & objProperty.Name & " = """"; Else str" & objProperty.Name & " = objItem~" & objProperty.Name & "\n" _
  1828. 			        & "\tSay """ & CreateLine( objProperty.Name, gviMaxLen ) & " ""||str" & objProperty.Name & "\n"
  1829. 		End If
  1830. 	Next
  1831. 	strCode = strCode _
  1832. 	        & "\tSay\n" _
  1833. 	        & "End\n"
  1834. 	strCode = Replace( Replace( strCode, "\n", vbCrLf ), "\t", vbTab )
  1835. 	Code.value = strCode
  1836. 	ButtonState
  1837. End Sub
  1838.  
  1839.  
  1840. Sub ShowPascalCode( )
  1841. 	' Based on sample WMI code from 'The Road To Delphi':
  1842. 	' http://theroadtodelphi.wordpress.com/2010/12/01/accesing-the-wmi-from-pascal-code-delphi-oxygene-freepascal/#Lazarus
  1843. 	' This sample code would crash on properties of Array type, so the generated code skips arrays and returns a string "[Array]" instead
  1844. 	' Code adapted for and tested in Lazarus IDE
  1845. 	' http://www.lazarus.freepascal.org/
  1846. 	Dim objProperty, strCode
  1847. 	strCode = "// WMI query to list all properties and values of the \\" & Replace( gvaSettingsStr.Item( "NAMESPACE" ), "/", "\" ) & ":" & gvsClass & " class.\n" _
  1848. 	        & "// This Object Pascal code (for lazarus IDE) was generated using the WMI Code Generator, Version " & WMIGen.Version & "\n" _
  1849. 	        & "// http://www.robvanderwoude.com/wmigen.php\n\n" _
  1850. 	        & "// Based on sample WMI code from 'The Road To Delphi':\n" _
  1851. 	        & "// http://theroadtodelphi.wordpress.com/2010/12/01/accesing-the-wmi-from-pascal-code-delphi-oxygene-freepascal/#Lazarus\n" _
  1852. 	        & "// Code adapted for and tested in Lazarus IDE:\n" _
  1853. 	        & "// http://www.lazarus.freepascal.org/\n\n" _
  1854. 	        & "program WMIGen_" & gvsClass & ";\n\n" _
  1855. 	        & "\t{$mode objfpc}\n\n" _
  1856. 	        & "\tuses SysUtils, Variants, ComObj, ActiveX, Windows;\n\n" _
  1857. 	        & "\tfunction VarStrNull( const V : OleVariant ) : string; //avoid problems with null strings\n" _
  1858. 	        & "\t\tbegin\n" _
  1859. 	        & "\t\t\tResult := '';\n" _
  1860. 	        & "\t\t\tif not VarIsNull( V ) then\n" _
  1861. 	        & "\t\t\t\tbegin\n" _
  1862. 	        & "\t\t\t\t\tif VarIsArray( V ) then\n" _
  1863. 	        & "\t\t\t\t\t\tResult := '[Array]'\n" _
  1864. 	        & "\t\t\t\t\telse\n" _
  1865. 	        & "\t\t\t\t\t\tResult := VarToStr( V );\n" _
  1866. 	        & "\t\t\t\tend;\n" _
  1867. 	        & "\t\tend;\n\n" _
  1868. 	        & "\tfunction GetWMIObject( const objectName : string ) : IDispatch;\n" _
  1869. 	        & "\t\tvar\n" _
  1870. 	        & "\t\t\tchEaten : PULONG;\n" _
  1871. 	        & "\t\t\tBindCtx : IBindCtx;\n" _
  1872. 	        & "\t\t\tMoniker : IMoniker;\n\n" _
  1873. 	        & "\t\tbegin\n" _
  1874. 	        & "\t\t\tOleCheck( CreateBindCtx( 0, bindCtx ) );\n" _
  1875. 	        & "\t\t\tOleCheck( MkParseDisplayName( BindCtx, StringToOleStr( objectName ), chEaten, Moniker ) );\n" _
  1876. 	        & "\t\t\tOleCheck( Moniker.BindToObject( BindCtx, nil, IDispatch, Result ) );\n" _
  1877. 	        & "\t\tend;\n\n" _
  1878. 	        & "\tprocedure WMIGen_" & gvsClass & "( sComputer : string );\n" _
  1879. 	        & "\t\tvar\n" _
  1880. 	        & "\t\t\tobjWMIService : OleVariant;\n" _
  1881. 	        & "\t\t\tcolItems      : OleVariant;\n" _
  1882. 	        & "\t\t\tcolItem       : Variant;\n" _
  1883. 	        & "\t\t\toEnum         : IEnumvariant;\n" _
  1884. 	        & "\t\t\tsTemp         : string;\n\n" _
  1885. 	        & "\t\tbegin;\n" _
  1886. 	        & "\t\t\tobjWMIService := GetWMIObject( Format( 'winmgmts://%s/" & gvaSettingsStr.Item( "NAMESPACE" ) & "', [sComputer] ) );\n"
  1887. 	If gvaSettingsBool.Item( "LOWRES" ) Then
  1888. 		strCode = strCode _
  1889. 		        & "\t\t\tcolItems      := objWMIService.ExecQuery( 'SELECT * FROM " & gvsClass & "', 'WQL', 48 );\n" _
  1890. 		        & "\t\t\toEnum         := IUnknown( colItems._NewEnum ) as IEnumVariant;\n\n"
  1891. 	Else
  1892. 		strCode = strCode _
  1893. 		        & "\t\t\tcolItems      := objWMIService.ExecQuery( 'SELECT * FROM " & gvsClass & "', 'WQL', 0 );\n" _
  1894. 		        & "\t\t\toEnum         := IUnknown( colItems._NewEnum ) as IEnumVariant;\n\n" _
  1895. 		        & "\t\t\tif colItems.Count = 1 then\n" _
  1896. 		        & "\t\t\t\tWriteln( '1 instance' )\n" _
  1897. 		        & "\t\t\telse\n" _
  1898. 		        & "\t\t\t\tbegin\n" _
  1899. 		        & "\t\t\t\t\tsTemp := VarStrNull( colItems.Count );\n" _
  1900. 		        & "\t\t\t\t\tWriteln( Format( '%s instances', [sTemp] ) );\n" _
  1901. 		        & "\t\t\t\tend;\n" _
  1902. 		        & "\t\t\tWriteln( );\n\n"
  1903. 	End If
  1904. 	strCode = strCode _
  1905. 	        & "\t\t\twhile oEnum.Next( 1, colItem, nil ) = 0 do\n" _
  1906. 	        & "\t\t\t\tbegin\n"
  1907. 	For Each objProperty In gvoClass.Properties_
  1908. 		strCode = strCode _
  1909. 		        & "\t\t\t\t\tsTemp := VarStrNull( colItem." & objProperty.Name & " );\n" _
  1910. 		        & "\t\t\t\t\tWriteln( Format( '" & CreateLine( objProperty.Name, gviMaxLen ) & " %s', [sTemp] ) );\n"
  1911. 	Next
  1912. 	strCode = strCode _
  1913. 	        & "\t\t\t\t\tWriteLn( );\n" _
  1914. 	        & "\t\t\t\tend;\n" _
  1915. 	        & "\t\tend;\n\n" _
  1916. 	        & "\tvar\n" _
  1917. 	        & "\t\tsComputer : string;\n\n" _
  1918. 	        & "\tbegin\n" _
  1919. 	        & "\t\ttry\n" _
  1920. 	        & "\t\t\tbegin\n" _
  1921. 	        & "\t\t\t\t// First and only optional command line argument is remote computer name\n" _
  1922. 	        & "\t\t\t\tif ParamCount = 1 then\n" _
  1923. 	        & "\t\t\t\t\tsComputer := ParamStr( 1 )\n" _
  1924. 	        & "\t\t\t\telse\n" _
  1925. 	        & "\t\t\t\t\tsComputer := 'localhost';\n" _
  1926. 	        & "\t\t\t\tWMIGen_" & gvsClass & "( sComputer );\n" _
  1927. 	        & "\t\t\tend;\n" _
  1928. 	        & "\t\texcept\n" _
  1929. 	        & "\t\t\ton E : Exception do Writeln( E.Classname, ': ', E.Message );\n" _
  1930. 	        & "\tend;\n" _
  1931. 	        & "end.\n"
  1932. 	strCode = Replace( Replace( strCode, "\n", vbCrLf ), "\t", vbTab )
  1933. 	Code.value = strCode
  1934. 	ButtonState
  1935. End Sub
  1936.  
  1937.  
  1938. Sub ShowPerlCode( )
  1939. 	Dim objProperty, strCode
  1940. 	strCode = "#! perl\r\r" _
  1941. 	        & "# WMI query to list all properties and values of the " & gvaSettingsStr.Item( "NAMESPACE" ) & ":" & gvsClass & " class.\r" _
  1942. 	        & "# This Perl script was generated using the WMI Code Generator, Version " & WMIGen.Version & "\r" _
  1943. 	        & "# http://www.robvanderwoude.com/wmigen.php\r\r" _
  1944. 	        & "use Win32::OLE( 'in' );\r\r"
  1945. 	If gvaSettingsBool.Item( "LOWRES" ) Then
  1946. 		strCode = strCode _
  1947. 		        & "use constant wbemFlagReturnImmediately => 0x10;\r" _
  1948. 		        & "use constant wbemFlagForwardOnly       => 0x20;\r\r"
  1949. 	End If
  1950. 	strCode = strCode _
  1951. 	        & "if ( $ARGV[0] ) {\r" _
  1952. 	        & "\t$computer = $ARGV[0];\r" _
  1953. 	        & "} else {\r" _
  1954. 	        & "\t$computer = ""."";\r" _
  1955. 	        & "}\r\r" _
  1956. 	        & "my $objWMIService = Win32::OLE->GetObject( ""winmgmts://$computer/" & gvaSettingsStr.Item( "NAMESPACE" ) & """ ) or die ""WMI connection failed.\n"";\r"
  1957. 	If gvaSettingsBool.Item( "LOWRES" ) Then
  1958. 		strCode = strCode & "my $colItems = $objWMIService->ExecQuery( ""SELECT * FROM " & gvsClass & """, ""WQL"", wbemFlagReturnImmediately | wbemFlagForwardOnly );\r\r"
  1959. 	Else
  1960. 		strCode = strCode _
  1961. 		        & "my $colItems = $objWMIService->ExecQuery( ""SELECT * FROM " & gvsClass & """ );\r" _
  1962. 		        & "if ( $colItems->Count == 1 ) {\r" _
  1963. 		        & "\tprint ""1 instance:\n"";\r" _
  1964. 		        & "} else {\r" _
  1965. 		        & "\tprintf( ""%s instances:\n\n"", $colItems->Count );\r" _
  1966. 		        & "}\r\r"
  1967. 	End If
  1968. 	strCode = strCode & "foreach my $objItem ( in $colItems ) {\r"
  1969. 	For Each objProperty In gvoClass.Properties_
  1970. 		strCode = strCode & "\tprint """ & CreateLine( objProperty.Name, gviMaxLen ) & " "" . "
  1971. 		If objProperty.IsArray = True Then
  1972. 			strCode = strCode & "join( "","", ( in $objItem->{ " & objProperty.Name & " } ) )"
  1973. 		Else
  1974. 			strCode = strCode & "$objItem->{ " & objProperty.Name & " }"
  1975. 		End If
  1976. 		strCode = strCode & " . ""\n"";\r"
  1977. 	Next
  1978. 	strCode = strCode _
  1979. 	        & "\tprint ""\n"";\r" _
  1980. 	        & "}\r"
  1981. 	strCode = Replace( Replace( strCode, "\r", vbCrLf ), "\t", vbTab )
  1982. 	Code.value = strCode
  1983. 	ButtonState
  1984. End Sub
  1985.  
  1986.  
  1987. Sub ShowPowerShellCode( )
  1988. 	Dim objProperty, strCode
  1989. 	strCode = "# WMI query to list all properties and values of the \\" & Replace( gvaSettingsStr.Item( "NAMESPACE" ), "/", "\" ) & ":" & gvsClass & " class.\n" _
  1990. 	        & "# This PowerShell script was generated using the WMI Code Generator, Version " & WMIGen.Version & "\n" _
  1991. 	        & "# http://www.robvanderwoude.com/wmigen.php\n\n" _
  1992. 	        & "param( [string]$strComputer = ""."" )\n\n" _
  1993. 	        & "$colItems = get-wmiobject -class """ & gvsClass & """ -namespace """ & Replace( gvaSettingsStr.Item( "NAMESPACE" ), "/", "\" ) & """ -computername $strComputer\n\n" _
  1994. 	        & "$instances = ($colItems | measure-object).Count\n" _
  1995. 	        & "if ($instances -eq 1) {\n" _
  1996. 	        & "\twrite-host ""1 instance:""\n" _
  1997. 	        & "} else {\n" _
  1998. 	        & "\twrite-host ""$instances instances:""\n" _
  1999. 	        & "}\n" _
  2000. 	        & "write-host\n\n" _
  2001. 	        & "foreach ($objItem in $colItems) {\n"
  2002. 	For Each objProperty In gvoClass.Properties_
  2003. 		strCode = strCode & "\twrite-host """ & CreateLine( objProperty.Name, gviMaxLen ) & """ $objItem." & objProperty.Name & "\n"
  2004. 	Next
  2005. 	strCode = strCode _
  2006. 	        & "\twrite-host\n" _
  2007. 	        & "}\n"
  2008. 	strCode = Replace( Replace( strCode, "\n", vbCrLf ), "\t", vbTab )
  2009. 	Code.value = strCode
  2010. 	ButtonState
  2011. End Sub
  2012.  
  2013.  
  2014. Sub ShowPythonCode( )
  2015. 	Dim objProperty, strCode
  2016. 	strCode = "#! python\n\n" _
  2017. 	        & "# WMI query to list all properties and values of the " & gvaSettingsStr.Item( "NAMESPACE" ) & ":" & gvsClass & " class.\n" _
  2018. 	        & "# To use WMI in Python, install the Python for Windows extensions:\n" _
  2019. 	        & "# http://sourceforge.net/projects/pywin32/files/pywin32/\n" _
  2020. 	        & "# This Python script was generated using the WMI Code Generator, Version " & WMIGen.Version & "\n" _
  2021. 	        & "# http://www.robvanderwoude.com/wmigen.php\n\n" _
  2022. 	        & "import sys\n" _
  2023. 	        & "import win32com.client\n\n"
  2024. 	If gvaSettingsBool.Item( "LOWRES" ) Then
  2025. 		strCode = strCode _
  2026. 		        & "wbemFlagReturnImmediately = 0x10\n" _
  2027. 		        & "wbemFlagForwardOnly       = 0x20\n\n"
  2028. 	End If
  2029. 	strCode = strCode _
  2030. 	        & "try:\n" _
  2031. 	        & "\tstrComputer = sys.argv[1]\n" _
  2032. 	        & "except IndexError:\n" _
  2033. 	        & "\tstrComputer = "".""\n\n" _
  2034. 	        & "objWMIService = win32com.client.Dispatch( ""WbemScripting.SWbemLocator"" )\n" _
  2035. 	        & "objSWbemServices = objWMIService.ConnectServer( strComputer, """ & gvaSettingsStr.Item( "NAMESPACE" ) & """ )\n"
  2036. 	If gvaSettingsBool.Item( "LOWRES" ) Then
  2037. 		strCode = strCode _
  2038. 	        & "colItems = objSWbemServices.ExecQuery( ""SELECT * FROM " & gvsClass & """, ""WQL"", wbemFlagReturnImmediately + wbemFlagForwardOnly )\n\n"
  2039. 	Else
  2040. 		strCode = strCode _
  2041. 	        & "colItems = objSWbemServices.ExecQuery( ""SELECT * FROM " & gvsClass & """ )\n\n" _
  2042. 	        & "if colItems.Count == 1:\n" _
  2043. 	        & "\tprint( ""1 instance:"" )\n" _
  2044. 	        & "else:\n" _
  2045. 	        & "\tprint( str( colItems.Count ) + "" instances:"" )\n" _
  2046. 	        & "print\n\n"
  2047. 	End If
  2048. 	strCode = strCode & "for objItem in colItems:\n"
  2049. 	For Each objProperty In gvoClass.Properties_
  2050. 		If objProperty.IsArray = True Then
  2051. 			strCode = strCode _
  2052. 			        & "\tstrList = "" ""\n" _
  2053. 			        & "\ttry:\n" _
  2054. 			        & "\t\tfor objElem in objItem." & objProperty.Name & " :\n" _
  2055. 			        & "\t\t\tstrList = strList + str( objElem ) + "",""\n" _
  2056. 			        & "\texcept:\n" _
  2057. 			        & "\t\tstrList = strList + 'null'\n" _
  2058. 			        & "\tprint( """ & CreateLine( objProperty.Name, gviMaxLen ) & """ + strList )\n"
  2059. 		Else
  2060. 			strCode = strCode _
  2061. 			        & "\tif objItem." & objProperty.Name & " == None:\n" _
  2062. 			        & "\t\tprint( """ & CreateLine( objProperty.Name, gviMaxLen ) & " "" )\n" _
  2063. 			        & "\telse:\n" _
  2064. 			        & "\t\tprint( """ & CreateLine( objProperty.Name, gviMaxLen ) & " "" + str( objItem." & objProperty.Name & " ) )\n"
  2065. 		End If
  2066. 	Next
  2067. 	strCode = strCode & "\tprint\n"
  2068. 	strCode = Replace( Replace( strCode, "\n", vbCrLf ), "\t", vbTab )
  2069. 	Code.value = strCode
  2070. 	ButtonState
  2071. End Sub
  2072.  
  2073.  
  2074. Sub ShowRubyCode( )
  2075. 	Dim objProperty, strCode
  2076. 	strCode = "# WMI query to list all properties and values of the " & gvaSettingsStr.Item( "NAMESPACE" ) & ":" & gvsClass & " class.\n" _
  2077. 	        & "# This Ruby script was generated using the WMI Code Generator, Version " & WMIGen.Version & "\n" _
  2078. 	        & "# http://www.robvanderwoude.com/wmigen.php\n\n" _
  2079. 	        & "require 'win32ole'\n\n"
  2080. 	If gvaSettingsBool.Item( "LOWRES" ) Then
  2081. 		strCode = strCode _
  2082. 		        & "wbemFlagReturnImmediately = 0x10\n" _
  2083. 		        & "wbemFlagForwardOnly       = 0x20\n\n"
  2084. 	End If
  2085. 	strCode = strCode _
  2086. 	        & "if ARGV[0]\n" _
  2087. 	        & "\tcomputer = ARGV[0]\n" _
  2088. 	        & "else\n" _
  2089. 	        & "\tcomputer = "".""\n" _
  2090. 	        & "end\n\n" _
  2091. 	        & "objWMIService = WIN32OLE.connect( ""winmgmts://#{computer}/" & gvaSettingsStr.Item( "NAMESPACE" ) & """ )\n"
  2092. 	If gvaSettingsBool.Item( "LOWRES" ) Then
  2093. 		strCode = strCode & "colItems = objWMIService.ExecQuery( ""SELECT * FROM " & gvsClass & """, ""WQL"", wbemFlagReturnImmediately + wbemFlagForwardOnly )\n\n"
  2094. 	Else
  2095. 		strCode = strCode _
  2096. 	        & "colItems = objWMIService.ExecQuery( ""SELECT * FROM " & gvsClass & """ )\n\n" _
  2097. 	        & "if colItems.Count == 1\n\n" _
  2098. 	        & "\tputs ""1 instance:""\n" _
  2099. 	        & "else\n" _
  2100. 	        & "\tputs ""#{colItems.Count} instances:""\n" _
  2101. 	        & "end\n" _
  2102. 	        & "puts\n\n"
  2103. 	End If
  2104. 	strCode = strCode & "for objItem in colItems do\n"
  2105. 	For Each objProperty In gvoClass.Properties_
  2106. 		strCode = strCode & "\tputs """ & CreateLine( objProperty.Name, gviMaxLen ) & " #{objItem." & objProperty.Name & "}""\n"
  2107. 	Next
  2108. 	strCode = strCode _
  2109. 	        & "\tputs\n" _
  2110. 	        & "end\n"
  2111. 	strCode = Replace( Replace( strCode, "\n", vbCrLf ), "\t", vbTab )
  2112. 	Code.value = strCode
  2113. 	ButtonState
  2114. End Sub
  2115.  
  2116.  
  2117. Sub ShowVBDotNETCode( )
  2118. 	Dim intCIMType, objProperty, strArrayPr, strCIMType, strCode
  2119. 	Const wbemCIMTypeSint16    =   2 'Signed 16-bit integer
  2120. 	Const wbemCIMTypeSint32    =   3 'Signed 32-bit integer
  2121. 	Const wbemCIMTypeReal32    =   4 '32-bit real number
  2122. 	Const wbemCIMTypeReal64    =   5 '64-bit real number
  2123. 	Const wbemCIMTypeString    =   8 'String
  2124. 	Const wbemCIMTypeBoolean   =  11 'Boolean value
  2125. 	Const wbemCIMTypeObject    =  13 'CIM object
  2126. 	Const wbemCIMTypeSint8     =  16 'Signed 8-bit integer
  2127. 	Const wbemCIMTypeUint8     =  17 'Unsigned 8-bit integer
  2128. 	Const wbemCIMTypeUint16    =  18 'Unsigned 16-bit integer
  2129. 	Const wbemCIMTypeUint32    =  19 'Unsigned 32-bit integer
  2130. 	Const wbemCIMTypeSint64    =  20 'Signed 64-bit integer
  2131. 	Const wbemCIMTypeUint64    =  21 'Unsigned 64-bit integer
  2132. 	Const wbemCIMTypeDatetime  = 101 'Date/time value
  2133. 	Const wbemCIMTypeReference = 102 'Reference to a CIM object
  2134. 	Const wbemCIMTypeChar16    = 103 '16-bit character
  2135. 	strCode = "' WMI query to list all properties and values of the \\" & Replace( gvaSettingsStr.Item( "NAMESPACE" ), "/", "\" ) & ":" & gvsClass & " class.\n" _
  2136. 	        & "' This VB .NET code was generated using the WMI Code Generator, Version " & WMIGen.Version & "\n" _
  2137. 	        & "' http://www.robvanderwoude.com/wmigen.php\n\n" _
  2138. 	        & "Imports System\n" _
  2139. 	        & "Imports System.Management\n\n" _
  2140. 	        & "Namespace WMIGen\n" _
  2141. 	        & "\tModule " & gvsClass & "_Query\n" _
  2142. 	        & "\t\tSub Main(ByVal ParamArray args() As String)\n" _
  2143. 	        & "\t\t\tDim computer As String = String.Empty\n" _
  2144. 	        & "\t\t\tTry\n" _
  2145. 	        & "\t\t\t\tIf args.Length > 0 Then\n" _
  2146. 	        & "\t\t\t\t\tcomputer = ""\\"" & args(0) & ""\""\n" _
  2147. 	        & "\t\t\t\tEnd If\n\n" _
  2148. 	        & "\t\t\t\tDim searcher As New ManagementObjectSearcher(computer & """ & Replace( gvaSettingsStr.Item( "NAMESPACE" ), "/", "\" ) & """, ""SELECT * FROM " & gvsClass & """)\n" _
  2149.             & "\t\t\t\tDim colItems = searcher.Get()\n" _
  2150. 	        & "\t\t\t\tDim arrPropertyInt() As UInt16\n" _
  2151. 	        & "\t\t\t\tDim arrPropertyStr() As String\n\n" _
  2152. 	        & "\t\t\t\tIf colItems.Count = 1 Then\n" _
  2153. 	        & "\t\t\t\t\tConsole.WriteLine(""1 instance:"")\n" _
  2154. 	        & "\t\t\t\tElse\n" _
  2155. 	        & "\t\t\t\t\tConsole.WriteLine(""{0} instances:"", colItems.Count)\n" _
  2156. 	        & "\t\t\t\tEnd If\n" _
  2157. 	        & "\t\t\t\tConsole.WriteLine()\n\n" _
  2158. 	        & "\t\t\t\tFor Each queryObj As ManagementObject In colItems\n"
  2159. 	For Each objProperty In gvoClass.Properties_
  2160. 		If objProperty.IsArray = True Then
  2161. 			intCIMType = objProperty.CIMType
  2162. 			strCIMType = "String"
  2163. 			strArrayPr = "arrPropertyStr"
  2164. 			If intCIMType < 8 Then strCIMType = "UInt16"
  2165. 			If intCIMType > 15 And intCIMType < 100 Then strCIMType = "UInt16"
  2166. 			If strCIMType = "UInt16" Then strArrayPr = "arrPropertyInt"
  2167. 			strCode = strCode _
  2168. 			        & "\t\t\t\t\tIf queryObj(""" & objProperty.Name & """) Is Nothing Then\n" _
  2169. 			        & "\t\t\t\t\t\tConsole.WriteLine(""" & CreateLine( objProperty.Name, gviMaxLen ) & " {0}"", queryObj(""" & objProperty.Name & """))\n" _
  2170. 			        & "\t\t\t\t\tElse\n" _
  2171. 			        & "\t\t\t\t\t\t" & strArrayPr & " = queryObj(""" & objProperty.Name & """)\n"
  2172. 			If strCIMType = "UInt16" Then
  2173. 				strCode = strCode _
  2174. 				        & "\t\t\t\t\t\tReDim arrPropertyStr(UBound(arrPropertyInt))\n" _
  2175. 				        & "\t\t\t\t\t\tFor i = 0 To UBound(arrPropertyInt)\n" _
  2176.                         & "\t\t\t\t\t\t\tarrPropertyStr(i) = CStr(arrPropertyInt(i))\n" _
  2177.                         & "\t\t\t\t\t\tNext\n"
  2178. 			End If
  2179. 			strCode = strCode _
  2180. 			        & "\t\t\t\t\t\tConsole.WriteLine(""" & CreateLine( objProperty.Name, gviMaxLen ) & " {0}"", Join(arrPropertyStr, "";""))\n" _
  2181. 			        & "\t\t\t\t\tEnd If\n"
  2182. 		Else
  2183. 			strCode = strCode & "\t\t\t\t\tConsole.WriteLine(""" & CreateLine( objProperty.Name, gviMaxLen ) & " {0}"", queryObj(""" & objProperty.Name & """))\n"
  2184. 		End If
  2185. 	Next
  2186. 	strCode = strCode _
  2187. 	        & "\t\t\t\t\tConsole.WriteLine()\n" _
  2188. 	        & "\t\t\t\tNext\n" _
  2189. 	        & "\t\t\t\tEnvironment.Exit(0)\n" _
  2190. 	        & "\t\t\tCatch err As ManagementException\n" _
  2191. 	        & "\t\t\t\tConsole.Error.WriteLine(""An error occurred while querying WMI: "" & err.Message)\n" _
  2192. 	        & "\t\t\t\tEnvironment.Exit(1)\n" _
  2193. 	        & "\t\t\tCatch err As System.Runtime.InteropServices.COMException\n" _
  2194. 	        & "\t\t\t\tConsole.Error.Write(""An error occurred"")\n" _
  2195. 	        & "\t\t\t\tIf Not String.IsNullOrEmpty(computer) Then\n" _
  2196. 	        & "\t\t\t\t\tConsole.Error.Write("" while connecting to computer "" & computer.Replace(""\"", String.Empty))\n" _
  2197. 	        & "\t\t\t\tEnd If\n" _
  2198. 	        & "\t\t\t\tConsole.Error.WriteLine("": "" & err.Message)\n" _
  2199. 	        & "\t\t\t\tEnvironment.Exit(1)\n" _
  2200. 	        & "\t\t\tEnd Try\n" _
  2201. 	        & "\t\tEnd Sub\n" _
  2202. 	        & "\tEnd Module\n" _
  2203. 	        & "End Namespace\n"
  2204. 	strCode = Replace( Replace( strCode, "\n", vbCrLf ), "\t", vbTab )
  2205. 	Code.value = strCode
  2206. 	ButtonState
  2207. End Sub
  2208.  
  2209.  
  2210. Sub ShowVBScriptCode( )
  2211. 	' IsArray an Join() functionality "borrowed" from Scriptomatic 2.0
  2212. 	' http://www.microsoft.com/downloads/details.aspx?FamilyID=09dfc342-648b-4119-b7eb-783b0f7d1178&DisplayLang=en
  2213. 	Dim objProperty, strCode
  2214. 	strCode = "' WMI query to list all properties and values of the " & gvaSettingsStr.Item( "NAMESPACE" ) & ":" & gvsClass & " class.\n" _
  2215. 	        & "' This VBScript code was generated using the WMI Code Generator, Version " & WMIGen.Version & "\n" _
  2216. 	        & "' http://www.robvanderwoude.com/wmigen.php\n\n"
  2217. 	If gvaSettingsBool.Item( "LOWRES" ) Then
  2218. 		strCode = strCode _
  2219. 		        & "Const wbemFlagReturnImmediately = &h10\n" _
  2220. 		        & "Const wbemFlagForwardOnly       = &h20\n\n"
  2221. 	End If
  2222. 	strCode = strCode _
  2223. 	        & "On Error Resume Next\n" _
  2224. 	        & "If WScript.Arguments.UnNamed.Count = 1 Then\n" _
  2225. 	        & "\tstrComputer = WScript.Arguments.UnNamed(0)\n" _
  2226. 	        & "Else\n" _
  2227. 	        & "\tstrComputer = "".""\n" _
  2228. 	        & "End If\n\n" _
  2229. 	        & "Set objWMIService = GetObject( ""winmgmts://"" & strComputer & ""/" & gvaSettingsStr.Item( "NAMESPACE" ) & """ )\n"
  2230. 	If gvaSettingsBool.Item( "LOWRES" ) Then
  2231. 		strCode = strCode & "Set colInstances = objWMIService.ExecQuery( ""SELECT * FROM " & gvsClass & """, ""WQL"", wbemFlagReturnImmediately + wbemFlagForwardOnly )\n\n"
  2232. 	Else
  2233. 		strCode = strCode _
  2234. 		        & "Set colInstances = objWMIService.ExecQuery( ""SELECT * FROM " & gvsClass & """ )\n\n" _
  2235. 		        & "If colInstances.Count = 1 Then\n" _
  2236. 		        & "\tWScript.Echo ""1 instance:""\n" _
  2237. 		        & "Else\n" _
  2238. 		        & "\tWScript.Echo colInstances.Count & "" instances:""\n" _
  2239. 		        & "End If\n" _
  2240. 		        & "WScript.Echo\n\n"
  2241. 	End if
  2242. 	strCode = strCode & "For Each objInstance In colInstances\n"
  2243. 	For Each objProperty In gvoClass.Properties_
  2244. 		If objProperty.IsArray = True Then
  2245. 			strCode = strCode _
  2246. 			        & "\tWScript.Echo """ & CreateLine( objProperty.Name, gviMaxLen ) & " "" & Join( objInstance." & objProperty.Name & ", "","" )\n"
  2247. 		Else
  2248. 			strCode = strCode _
  2249. 			        & "\tWScript.Echo """ & CreateLine( objProperty.Name, gviMaxLen ) & " "" & objInstance." & objProperty.Name & "\n"
  2250. 		End If
  2251. 	Next
  2252. 	strCode = strCode _
  2253. 	        & "\tWScript.Echo\n" _
  2254. 	        & "Next\n"
  2255. 	strCode = Replace( Replace( strCode, "\n", vbCrLf ), "\t", vbTab )
  2256. 	Code.value = strCode
  2257. 	ButtonState
  2258. End Sub
  2259.  
  2260.  
  2261. Function TextFromHTML( myURL )
  2262.     Dim objHTTP
  2263.     TextFromHTML = ""
  2264.     Set objHTTP = CreateObject( "WinHttp.WinHttpRequest.5.1" )
  2265.     objHTTP.Open "GET", myURL
  2266.     objHTTP.Send
  2267.     ' Check if the result was valid, and if so return the result
  2268.     If objHTTP.Status = 200 Then
  2269.     	TextFromHTML = objHTTP.ResponseText
  2270.     End If
  2271.     Set objHTTP = Nothing
  2272. End Function
  2273.  
  2274.  
  2275. Function ValidatedWindowSize( myVal )
  2276. 	Dim intHeight, intWidth
  2277. 	Dim objMatches, objRE
  2278. 	Dim strSize, strVal
  2279. 	strSize = ""
  2280. 	strVal  = Trim( LCase( myVal ) )
  2281. 	If Window_Size.value <> "" Then
  2282. 		Set objRE = New RegExp
  2283. 		objRE.Pattern = "^(\d{3,4})x(\d{3,4})$"
  2284. 		If objRE.Test( strVal ) Then
  2285. 			Set objMatches = objRE.Execute( strVal )
  2286. 			If objMatches.Count = 1 Then
  2287. 				If objMatches.Item(0).Submatches.Count = 2 Then
  2288. 					intWidth  = CInt( objMatches.Item(0).Submatches(0) )
  2289. 					intHeight = CInt( objMatches.Item(0).Submatches(1) )
  2290. 					intWidth  = Max( intWidth,  gviMinWidth  )
  2291. 					intHeight = Max( intHeight, gviMinHeight )
  2292. 					intWidth  = Min( intWidth,  window.screen.width  )
  2293. 					intHeight = Min( intHeight, window.screen.height )
  2294. 					strSize   = CStr( intWidth ) & "x" & CStr( intHeight )
  2295. 				End If
  2296. 			End If
  2297. 			Set objMatches = Nothing
  2298. 		End If
  2299. 		Set objRE = Nothing
  2300. 	End If
  2301. 	ValidatedWindowSize = strSize
  2302. End Function
  2303.  
  2304.  
  2305. Function ValidateSettings( )
  2306. 	Dim blnCheck, blnCopy, blnGen, blnRun, blnSave
  2307. 	Dim objFSO, objItem
  2308. 	ValidateSettings = True
  2309. 	If Not gvaDefaultsStr.Exists( "NAMESPACE" ) Then ConfigReadDefaults
  2310. 	blnCopy = gvaSettingsBool.Item( "COPY" )
  2311. 	blnGen  = gvaSettingsBool.Item( "GENERATE" )
  2312. 	blnRun  = gvaSettingsBool.Item( "RUN" )
  2313. 	blnSave = False
  2314. 	If gvaSettingsStr.Item( "SAVE" ) <> "" Then
  2315. 		Set objFSO = CreateObject( "Scripting.FileSystemObject" )
  2316. 		With objFSO
  2317. 			If .FolderExists( .GetParentFolderName( .GetAbsolutePathName( gvaSettingsStr.Item( "SAVE" ) ) ) ) Then
  2318. 				blnSave = True
  2319. 			Else
  2320. 				gvaSettingsStr.Item( "SAVE" ) = ""
  2321. 				ValidateSettings = False
  2322. 			End If
  2323. 		End With
  2324. 		Set objFSO = Nothing
  2325. 	End If
  2326. 	If blnRun And blnGen Then
  2327. 		ValidateSettings = False
  2328. 		Exit Function
  2329. 	End If
  2330. 	If blnCopy And blnSave Then
  2331. 		ValidateSettings = False
  2332. 		Exit Function
  2333. 	End If
  2334. 	If gvaSettingsStr.Item( "NAMESPACE" ) = "" Then
  2335. 		gvaSettingsStr.Item( "NAMESPACE" ) = gvaDefaultsStr.Item( "NAMESPACE" )
  2336. 	Else
  2337. 		blnCheck = False
  2338. 		For Each objItem In Namespaces.options
  2339. 			If UCase( objItem.value ) = UCase( gvaSettingsStr.Item( "NAMESPACE" ) ) Then
  2340. 				gvaSettingsStr.Item( "NAMESPACE" ) = objItem.value
  2341. 				blnCheck = True
  2342. 			End If
  2343. 		Next
  2344. 		If Not blnCheck Then 
  2345. 			ValidateSettings = False
  2346. 			Exit Function
  2347. 		End If
  2348. 	End If
  2349. 	If gvaSettingsStr.Item( "LANGUAGE" ) = "" Then
  2350. 		gvaSettingsStr.Item( "LANGUAGE" ) = gvaDefaultsStr.Item( "LANGUAGE" )
  2351. 	Else
  2352. 		blnCheck = False
  2353. 		For Each objItem In CodeLanguage.options
  2354. 			If UCase( objItem.value ) = UCase( gvaSettingsStr.Item( "LANGUAGE" ) ) Then
  2355. 				gvaSettingsStr.Item( "LANGUAGE" ) = objItem.value
  2356. 				blnCheck = True
  2357. 			End If
  2358. 		Next
  2359. 		If Not blnCheck Then 
  2360. 			ValidateSettings = False
  2361. 			Exit Function
  2362. 		End If
  2363. 	End If
  2364. 	If gvaSettingsStr.Item( "CLASS" ) = "" Then
  2365. 		gvaSettingsStr.Item( "CLASS" ) = gvaDefaultsStr.Item( "CLASS" )
  2366. 	Else
  2367. 		blnCheck = False
  2368. 		For Each objItem In WMIClasses.options
  2369. 			If UCase( objItem.value ) = UCase( gvaSettingsStr.Item( "CLASS" ) ) Then
  2370. 				gvaSettingsStr.Item( "CLASS" ) = objItem.value
  2371. 				blnCheck = True
  2372. 			End If
  2373. 		Next
  2374. 		If Not blnCheck Then 
  2375. 			ValidateSettings = False
  2376. 			Exit Function
  2377. 		End If
  2378. 	End If
  2379. End Function
  2380.  
  2381.  
  2382. Sub Window_Onload
  2383. 	Dim blnCheck
  2384. 	Dim objOption
  2385. 	Dim strCheckMsg
  2386. 	strCheckMsg = ""
  2387. 	If InStr( UCase( WMIGen.CommandLine ), "/BW" ) Then
  2388. 		BW.checked = True
  2389. 		HandleBWChange
  2390. 	End If
  2391. 	AppVersion.innerHTML     = WMIGen.Version
  2392. 	CopyrightsYear.innerHTML = gviCopyrightsYear
  2393. 	document.title           = "WMI Code Generator " & WMIGen.Version
  2394. 	HelpTitle.innerHTML      = "Help for WMI Code Generator " & WMIGen.Version
  2395. 	CreditsTitle.innerHTML   = "Credits for WMI Code Generator " & WMIGen.Version
  2396. 	PathToHTA.innerHTML      = Self.location.pathname
  2397. 	ButtonState
  2398. 	WindowSize
  2399. 	CheckWindowSize
  2400. 	If Not IsAdmin( True ) Then
  2401. 		Self.window.close
  2402. 		Exit Sub
  2403. 	End If
  2404. 	ConfigReadDefaults
  2405. 	ConfigSetDefaults
  2406. 	ConfigReadFile
  2407. 	ConfigReadCommandline
  2408. 	If Not gvaSettingsBool.Item( "NOUPD" ) Then setTimeout "CheckUpdate", 5000, "VBScript"
  2409. 	ConfigUpdateStatus
  2410. 	If ValidateSettings Then
  2411. 		If Not gvbInteractive Then
  2412. 			If gvbCommandlineValidate Then
  2413. 				If gvaSettingsBool.Item( "GENERATE" )  Then ShowCode
  2414. 				If gvaSettingsBool.Item( "RUN" )       Then RunCode
  2415. 				If gvaSettingsStr.Item( "SAVE" ) <> "" Then SaveCode
  2416. 				If gvaSettingsBool.Item( "COPY" )      Then CopyCode
  2417. 				Self.window.close
  2418. 			End If
  2419. 		End If
  2420. 	Else
  2421. 		strCheckMsg = "Invalid command line arguments"
  2422. 		If Not gvbNamespaceValidate Then
  2423. 			strCheckMsg = "Invalid Namespace """ & gvaSettingsStr.Item( "NAMESPACE" ) & """" & vbCrLf
  2424. 		End If
  2425. 		If Not gvbClassValidate Then
  2426. 			strCheckMsg = strCheckMsg & "Invalid Class """ & gvaSettingsStr.Item( "CLASS" ) & """" & vbCrLf
  2427. 		End If
  2428. 		If Not gvbLanguageValidate Then
  2429. 			strCheckMsg = strCheckMsg & "Invalid Language """ & gvaSettingsStr.Item( "LANGUAGE" ) & """" & vbCrLf
  2430. 		End If
  2431. 		MsgBox strCheckMsg, vbOKOnly, "Invalid Arguments"
  2432. 		Self.location.reload True
  2433. 	End If
  2434. 	If InStr( WMIGen.CommandLine, "?" ) Or InStr( UCase( WMIGen.CommandLine ), "/HELP" ) Then ShowHelp
  2435. End Sub
  2436.  
  2437.  
  2438. Sub WindowSize( )
  2439. 	Dim intHeight, intWidth, posVertical, posHorizontal, posX
  2440. 	If gvaSettingsStr.Item( "SIZE" ) = "" Then
  2441. 		intHeight = window.screen.height
  2442. 		intWidth  = window.screen.width
  2443. 	Else
  2444. 		posX = InStr( LCase( gvaSettingsStr.Item( "SIZE" ) ), "x" )
  2445. 		If posX > 0 Then
  2446. 			intWidth  = Int( Left( gvaSettingsStr.Item( "SIZE" ), posX - 1 ) )
  2447. 			intHeight = Int( Mid(  gvaSettingsStr.Item( "SIZE" ), posX + 1 ) )
  2448. 		End If
  2449. 	End If
  2450. 	If IsNumeric( intHeight ) And IsNumeric( intWidth ) Then
  2451. 		intHeight = Min( Max( intHeight, gviMinHeight ), window.screen.height )
  2452. 		intWidth  = Min( Max( intWidth,  gviMinWidth  ), window.screen.width  )
  2453. 		posHorizontal = Max( 0, Int( ( window.screen.width  - intWidth  ) / 2 ) )
  2454. 		posVertical   = Max( 0, Int( ( window.screen.height - intHeight ) / 2 ) )
  2455. 		If gvaSettingsStr.Item( "SIZE" ) <> "" And gvaSettingsStr.Item( "SIZE" ) <> CStr( Self.screen.width ) & "x" & CStr( Self.screen.height ) Then
  2456. 			window.resizeTo intWidth, intHeight
  2457. 			window.moveTo posHorizontal, posVertical
  2458. 		End If
  2459. 	End If
  2460. 	If gvaSettingsStr.Item( "SIZE" ) = "" Then
  2461. 		Window_Size.value = "maximize"
  2462. 	Else
  2463. 		Window_Size.value = gvaSettingsStr.Item( "SIZE" )
  2464. 	End If
  2465. 	CheckWindowSize
  2466. End Sub
  1. </script>
  2.  
  3. <body onresize="CheckWindowSize()" onhelp="ShowHelp()" onkeyup="CheckEscape()">
  4.  
  5. <div class="Center">
  6.  
  7. <div id="Main">
  8.  
  9. <table cellspacing="10">
  10. <tr class="Center">
  11.     <td colspan="2"><table style="width: 100%;">
  12.         <tr>
  13.             <th style="width: 33%; vertical-align: bottom; text-align: left;" title="Select a WMI class from this drop-down list, then select a scripting language and press the 'Generate Code' button to show the code for the selected WMI query and the selected scripting language in the lower text area" class="Left">Select a WMI Class:</th>
  14.             <th style="width: 33%; vertical-align: bottom;">Namespace: <select id="Namespaces" title="This list shows the available WMI namespaces" size="1" style="width: 15em;" onchange="HandleNamespaceChange" ></select></td>
  15.             <th style="width: 33%; vertical-align: bottom;">&nbsp;</th>
  16.         </tr>
  17.         </table></td>
  18. </tr>
  19. <tr class="Center">
  20.     <td colspan="2" title="Select a WMI class from this drop-down list, then select a scripting language and press the 'Generate Code' button to show the code for the selected WMI query and the selected scripting language in the lower text area"><select onchange="HandleClassChange" name="WMIClasses" id="WMIClasses" size="6" style="width: 100%"></select></th>
  21. </tr>
  22. <tr class="Center">
  23.     <th title="This list shows the available properties for the selected WMI class" class="Left">Properties:</th>
  24.     <th title="This list shows the available methods for the selected WMI class"    class="Left">Methods:</th>
  25. </tr>
  26. <tr class="Center">
  27.     <td style="width: 50%"><select id="Properties" title="This list shows the available properties for the selected WMI class" size="6" style="width: 100%"></select></td>
  28.     <td style="width: 50%"><select id="Methods"    title="This list shows the available methods for the selected WMI class"    size="6" style="width: 100%"></select></td>
  29. </tr>
  30. <tr class="Center">
  31.     <th id="CodeLabel" title="After pressing the 'Generate Code' button, the generated code to display the available properties and their values for the selected WMI class will be shown here" class="Left">Code:</th>
  32.     <th class="Right"><input id="MSDNHelpButton" onclick="GetMSDNHelp" type="submit" value="MSDN  Help" class="Button" title="Press this button to search and open the relevant MSDN page for the selected class, method and/or property"></th>
  33. </tr>
  34. <tr class="Center">
  35.     <td colspan="2"><textarea id="Code" rows="20" cols="70" readonly="readonly" wrap="off"></textarea></td>
  36. </tr>
  37. <tr class="Left">
  38.     <th colspan="2" title="Select a scripting language from this drop-down list and press the 'Generate Code' button to show the code for the selected WMI query and scripting language in the text area above" class="Left">Select a scripting language:
  39.         <select name="CodeLanguage" id="CodeLanguage" onchange="HandleLanguageChange" style="text-align: left; margin-left: 0">
  40.             <option value="Batch">Batch</option>
  41.             <option value="C#" style="background-color: #F0F0F0">C#</option>
  42.             <option value="Delphi">Delphi</option>
  43.             <option value="F#" style="background-color: #F0F0F0">F#</option>
  44.             <option value="Java">Java</option>
  45.             <option value="JScript" style="background-color: #F0F0F0">JScript</option>
  46.             <option value="KiXtart">KiXtart</option>
  47.             <option value="Lua" style="background-color: #F0F0F0">Lua</option>
  48.             <option value="ObjectPascal">Object Pascal</option>
  49.             <option value="ObjectRexx" style="background-color: #F0F0F0">Object Rexx</option>
  50.             <option value="Perl">Perl</option>
  51.             <option value="PowerShell" style="background-color: #F0F0F0">PowerShell</option>
  52.             <option value="Python">Python</option>
  53.             <option value="Ruby" style="background-color: #F0F0F0">Ruby</option>
  54.             <option value="VB.NET">VB .NET</option>
  55.             <option value="VBScript" style="background-color: #F0F0F0">VBScript</option>
  56.         </select></th>
  57. </tr>
  58. <tr class="Left">
  59.     <td colspan="2"><table class="Center">
  60.         <tr>
  61.             <td><input id="GenerateCodeButton" onclick="ShowCode"              type="submit" value="Generate Code"     class="Button" title="Generate the code that will display the properties and their values for the selected WMI class, in the selected scripting or programming language"></td>
  62.             <td><input id="RunCodeButton"      onclick="RunCode"               type="submit" value="Run WMI Code"      class="Button" title="Run the generated (VBSCript) code"></td>
  63.             <td><input id="CopyCodeButton"     onclick="CopyCode"              type="submit" value="Copy to Clipboard" class="Button" title="Copy the generated code to the clipboard"></td>
  64.             <td><input id="SaveCodeButton"     onclick="SaveCode"              type="submit" value="Save to File"      class="Button" title="Save the generated code to a file"></td>
  65.         </tr>
  66.         <tr><td colspan="4">&nbsp;</td></tr>
  67.         <tr>
  68.             <td><input id="ClearCodeButton"    onclick="ClearCode"             type="submit" value="Clear"             class="Button" title="Erase the generated code"></td>
  69.             <td><input id="SettingsButton"     onclick="OnClickButtonSettings" type="submit" value="Settings"          class="Button" title="Change the configuration"></td>
  70.             <td><input id="HelpButton"         onclick="ShowHelp"              type="submit" value="Help"              class="Button" title="Display the on-line command line help window"></td>
  71.             <td><input id="CreditsButton"      onclick="ShowCredits"           type="submit" value="Credits"           class="Button" title="Display the on-line credits window"></td>
  72.         </tr>
  73.         </table></td>
  74. </tr>
  75. </table>
  76.  
  77. </div><!-- End of "Main" block -->
  78.  
  79.  
  80.  
  81.  
  82. <div id="Settings" style="display: none; height: 100%;">
  83.  
  84. <p>&nbsp;</p>
  85.  
  86. <h1>Settings</h1>
  87.  
  88. <table cellspacing="10">
  89. <tr>
  90.     <td>&nbsp;</td>
  91.     <td>Configuration file content:</td>
  92. 	<td><input type="text" name="Command_Line" id="Command_Line" size="20" style="width: 19.5em;" readonly="readonly"></td>
  93. </tr>
  94. <tr>
  95.     <td>&nbsp;</td>
  96.     <td>Windows size (<strong><em class="Red">width</em>x<em class="Red">height</em></strong> or <strong class="Red">maximize</strong>)</td>
  97.     <td><input id="Window_Size" type="text" size="20" style="width: 19.5em;"></td>
  98. </tr>
  99. <tr>
  100.     <td>&nbsp;</td>
  101.     <td>Default output language</td>
  102.     <td><select id="Default_Language" size="1" style="width: 20em;">
  103.             <option value="Batch">Batch</option>
  104.             <option value="C#" style="background-color: #F0F0F0">C#</option>
  105.             <option value="Delphi">Delphi</option>
  106.             <option value="F#" style="background-color: #F0F0F0">F#</option>
  107.             <option value="Java">Java</option>
  108.             <option value="JScript" style="background-color: #F0F0F0">JScript</option>
  109.             <option value="KiXtart">KiXtart</option>
  110.             <option value="Lua" style="background-color: #F0F0F0">Lua</option>
  111.             <option value="ObjectPascal">Object Pascal</option>
  112.             <option value="ObjectRexx" style="background-color: #F0F0F0">Object Rexx</option>
  113.             <option value="Perl">Perl</option>
  114.             <option value="PowerShell" style="background-color: #F0F0F0">PowerShell</option>
  115.             <option value="Python">Python</option>
  116.             <option value="Ruby" style="background-color: #F0F0F0">Ruby</option>
  117.             <option value="VB.NET">VB .NET</option>
  118.             <option value="VBScript" style="background-color: #F0F0F0">VBScript</option>
  119.     	</select></td>
  120. </tr>
  121. <tr>
  122.     <td>&nbsp;</td>
  123.     <td>Default namespace</td>
  124.     <td><select id="Default_Namespace" size="1" style="width: 20em;"></select></td>
  125. </tr>
  126. <tr>
  127.     <td class="CheckBox"><input type="checkbox" name="Exclusive_Namespace" id="Exclusive_Namespace"></td>
  128.     <td class="CheckBoxLabel" colspan="2"><label for="Exclusive_Namespace">Use only the selected namespace (i.e. do not list namespaces at startup)</label></td>
  129. </tr>
  130. <tr>
  131.     <td class="CheckBox"><input type="checkbox" name="Win32_Only" id="Win32_Only"></td>
  132.     <td class="CheckBoxLabel" colspan="2"><label for="Win32_Only">List Win32 classes only</label></td>
  133. </tr>
  134. <tr>
  135.     <td class="CheckBox"><input type="checkbox" name="Exclude_Perf" id="Exclude_Perf"></td>
  136.     <td class="CheckBoxLabel" colspan="2"><label for="Exclude_Perf">Exclude Win32_Perf classes</label></td>
  137. </tr>
  138. <tr>
  139.     <td class="CheckBox"><input type="checkbox" name="Resource_Friendly" id="Resource_Friendly"></td>
  140.     <td class="CheckBoxLabel" colspan="2"><label for="Resource_Friendly">Generate resource-friendly code (applies to JScript, KiXtart, Object Rexx, Perl, Python, Ruby and VBScript code only)</label></td>
  141. </tr>
  142. <tr>
  143.     <td class="CheckBox"><input type="checkbox" name="Use_Spaces" id="Use_Spaces"></td>
  144.     <td class="CheckBoxLabel" colspan="2"><label for="Use_Spaces">Use spaces in property descriptions (e.g. "SCSILogicalUnit" will be displayed as "SCSI  Logical  Unit")</label></td>
  145. </tr>
  146. <tr>
  147.     <td class="CheckBox"><input type="checkbox" name="Word_Wrap" id="Word_Wrap"></td>
  148.     <td class="CheckBoxLabel" colspan="2"><label for="Word_Wrap">Enable (soft) word wrap in code screen (does not affect saved code)</label></td>
  149. </tr>
  150. <tr>
  151.     <td class="CheckBox"><input type="checkbox" name="Update_Check" id="Update_Check"></td>
  152.     <td class="CheckBoxLabel" colspan="2"><label for="Update_Check">Check for program updates at startup</label></td>
  153. </tr>
  154. <tr>
  155.     <td class="CheckBox"><input type="checkbox" name="BW" id="BW" onclick="HandleBWChange"></td>
  156.     <td class="CheckBoxLabel" colspan="2"><label for="BW">High contrast black and white style (click to see the effect immediately)</label></td>
  157. </tr>
  158. </table>
  159.  
  160. <table cellspacing="10">
  161. <tr>
  162. 	<td><input id="ResetSettingsButton" onclick="OnClickButtonResetSettings" type="submit" value="Reset"  class="Button" title="Restore default settings"></td>
  163. 	<td><input id="EditSettingsButton"  onclick="OnClickButtonEditSettings"  type="submit" value="Edit"   class="Button" title="Edit the configuration file in Notepad"></td>
  164. 	<td><input id="SaveSettingsButton"  onclick="OnClickButtonSaveSettings"  type="submit" value="Save"   class="Button" title="Save the configuration changes and return to the main program"></td>
  165. 	<td><input id="CancelButton"        onclick="OnClickButtonCancel"        type="submit" value="Cancel" class="Button" title="Discard the configuration changes and return to the main program"></td>
  166. </tr>
  167. </table>
  168.  
  169. </div><!-- End of "Settings" block -->
  170.  
  171. <div id="Help" class="Help" style="display: none; height: 100%;">
  172.  
  173. <h1 id="HelpTitle">Help for WMI Code Generator</h1>
  174.  
  175. <table cellspacing="10" style="font-size: 10pt; text-align: left;">
  176. <tr>
  177. 	<th colspan="5">Generate source code in the selected scripting or programming language, for the selected WMI query</th>
  178. </tr>
  179. <tr><td colspan="5">&nbsp;</td></tr>
  180. <tr>
  181. 	<td colspan="5">Use this HTA to generate <a href="batchstart.php">Batch</a>,
  182. 		<a href="http://msdn.microsoft.com/en-us/vcsharp/aa336706">C#</a>,
  183. 		<a href="http://www.embarcadero.com/products/delphi">Delphi</a>,
  184. 		<a href="http://msdn.microsoft.com/en-gb/fsharp">F#</a>,
  185. 		<a href="http://en.wikipedia.org/wiki/Java_%28programming_language%29">Java</a>,
  186. 		<a href="http://msdn.microsoft.com/en-us/library/hbxc2t98(v=VS.85).aspx">JScript</a>,
  187. 		<a href="http://www.kixtart.org/">KiXtart</a>,
  188. 		<a href="http://www.lua.org/">Lua</a>,
  189. 		<a href="http://www.lazarus.freepascal.org/">Object Pascal</a>,
  190. 		<a href="http://www.oorexx.org/">(Open) Object Rexx</a>,
  191. 		<a href="http://www.perl.org/">Perl</a>,
  192. 		<a href="http://technet.microsoft.com/en-us/library/bb978526.aspx">PowerShell</a>,
  193. 		<a href="http://www.python.org/">Python</a>,
  194. 		<a href="http://www.ruby-lang.org/en/">Ruby</a>,
  195. 		<a href="http://msdn.microsoft.com/en-us/vbasic/ms789056">VB&nbsp;.NET</a> or
  196. 		<a href="http://msdn.microsoft.com/en-us/library/t0aew7h6(v=VS.85).aspx">VBScript</a>
  197. 		code for selected WMI queries.</td>
  198. </tr>
  199. <tr><td colspan="5">&nbsp;</td></tr>
  200. <tr>
  201. 	<th colspan="5">Interactive Usage</th>
  202. </tr>
  203. <tr><td colspan="5">&nbsp;</td></tr>
  204. <tr>
  205. 	<td colspan="5">First select a WMI namespace from the dropdown list, or stick with the default (<code>root/CIMV2</code>).<br>
  206. 		If a warning message, suggesting to abort the script, appears after selecting a namespace, click "No" to continue reading the list of available classes.</td>
  207. </tr>
  208. <tr>
  209. 	<td colspan="5" class="Center"><img src="http://www.robvanderwoude.com/pictures/wmigen_warning_454x229.jpg" width="454" height="229" alt="Warning message if the HTA temporarily uses too much resources."></td>
  210. </tr>
  211. <tr><td colspan="5">&nbsp;</td></tr>
  212. <tr>
  213. 	<td colspan="5">Next, select a class from the dropdown list marked "Select a WMI class".<br>
  214. 		The "Properties" and "Methods" fields will show the properties and methods available for the selected class, if any.</td>
  215. </tr>
  216. <tr>
  217. 	<td colspan="5">To get detailed information on a class or a method or property, select that class (and optionally a method or property) and click the "MSDN Help" button.<br>
  218. 		This will open your default browser with a list of relevant Google Search results.</td>
  219. </tr><tr>
  220. 	<td colspan="5">Select a scripting or programming language from the drop-down list and click the "Generate&nbsp;Code" button to generate the code that will display all properties of the selected class, and their values, in the scripting or programming language of your choice.</td>
  221. </tr>
  222. <tr>
  223. 	<td colspan="5">To test the selected query on your own computer, click the "Run&nbsp;WMI&nbsp;Code" button and wait for the result to appear on screen.
  224. 		Click "Generate&nbsp;Code" once more to redisplay the code in the selected scripting language.</td>
  225. </tr>
  226. <tr>
  227. 	<td colspan="5">Click "Save" to save the generated code (or query result) to a file, or "Copy" to copy it to the clipboard.</td>
  228. </tr>
  229. <tr><td colspan="5">&nbsp;</td></tr>
  230. <tr>
  231. 	<th colspan="5">Command Line Usage</th>
  232. </tr>
  233. <tr><td colspan="5">&nbsp;</td></tr>
  234. <tr class="Top">
  235. 	<td><strong>Usage:</strong></td>
  236. 	<td>&nbsp;</td>
  237. 	<td colspan="3"><code>WMIGEN.HTA  [ options ]  [ switches ]</code></td>
  238. </tr>
  239. <tr><td colspan="5">&nbsp;</td></tr>
  240. <tr class="Top">
  241. 	<th class="Left">Options:</th>
  242. 	<th>&nbsp;</th>
  243. 	<th class="Left" colspan="3">The following options can be set in the configuration file or on the command line<br>
  244. 		(in case of conflicts, the command line overrules the configuration file)</th>
  245. </tr>
  246. <tr class="Top">
  247. 	<td colspan="2">&nbsp;</td>
  248. 	<td class="Code">/NAMESPACE:<em>namespace</em></td>
  249. 	<td>&nbsp;</td>
  250. 	<td>Specifies the initial WMI namespace to be opened (default: <code>root/CIMV2</code>)</td>
  251. </tr>
  252. <tr class="Top">
  253. 	<td colspan="2">&nbsp;</td>
  254. 	<td class="Code">/WIN32</td>
  255. 	<td>&nbsp;</td>
  256. 	<td>List <code>Win32_*</code> classes only</td>
  257. </tr>
  258. <tr class="Top">
  259. 	<td colspan="2">&nbsp;</td>
  260. 	<td class="Code">/NOPERF</td>
  261. 	<td>&nbsp;</td>
  262. 	<td>Exclude <code>Win32_Perf*</code> classes</td>
  263. </tr>
  264. <tr class="Top">
  265. 	<td colspan="2">&nbsp;</td>
  266. 	<td class="Code">/FAST</td>
  267. 	<td>&nbsp;</td>
  268. 	<td>Skip the query to populate the namespaces list, an "populate" this list with the value specified by the <code>/NAMESPACE:<em>namespace</em></code> option only</td>
  269. </tr>
  270. <tr class="Top">
  271. 	<td colspan="2">&nbsp;</td>
  272. 	<td class="Code">/LANGUAGE:<em>language</em></td>
  273. 	<td>&nbsp;</td>
  274. 	<td>Specifies the initial programming or script language; <code><em>language</em></code> value as listed in drop-down box, but <em>without spaces</em> (default: <code>Batch</code>)</td>
  275. </tr>
  276. <tr class="Top">
  277. 	<td colspan="2">&nbsp;</td>
  278. 	<td class="Code">/LOWRES</td>
  279. 	<td>&nbsp;</td>
  280. 	<td>Generate code that uses less resources, at the cost of the results being "read-once" only (ignored for C#, F#, Java, Lua, PowerShell and VB.NET)</td>
  281. </tr>
  282. <tr class="Top">
  283. 	<td colspan="2">&nbsp;</td>
  284. 	<td class="Code">/SPACES</td>
  285. 	<td>&nbsp;</td>
  286. 	<td>Insert spaces in property name descriptions, e.g. "<code>SCSI&nbsp;Logical&nbsp;Unit</code>" instead of "<code>SCSILogicalUnit</code>" (ignored for Batch)</td>
  287. </tr>
  288. <tr class="Top">
  289. 	<td colspan="2">&nbsp;</td>
  290. 	<td class="Code">/WRAP</td>
  291. 	<td>&nbsp;</td>
  292. 	<td>Enable (soft) word wrap in the generated code field (does not affect saved code)</td>
  293. </tr>
  294. <tr class="Top">
  295. 	<td colspan="2">&nbsp;</td>
  296. 	<td class="Code">/SIZE:WxH</td>
  297. 	<td>&nbsp;</td>
  298. 	<td>Center window and resize to W x H pixels<br>
  299. 		(e.g. <code>/SIZE:1024x768</code>)</td>
  300. </tr>
  301. <tr class="Top">
  302. 	<td colspan="2">&nbsp;</td>
  303. 	<td class="Code">/BW</td>
  304. 	<td>&nbsp;</td>
  305. 	<td>Use high contrast black and white style for this HTA window</td>
  306. </tr>
  307. <tr class="Top">
  308. 	<td colspan="2">&nbsp;</td>
  309. 	<td class="Code">/NOUPD</td>
  310. 	<td>&nbsp;</td>
  311. 	<td>Skip check for updates at startup</td>
  312. </tr>
  313. <tr><td colspan="5">&nbsp;</td></tr>
  314. <tr class="Top">
  315. 	<th class="Left">Switches:</th>
  316. 	<th>&nbsp;</th>
  317. 	<th class="Left" colspan="3">The following options can only be set on the command line</th>
  318. </tr>
  319. <tr class="Top">
  320. 	<td colspan="2">&nbsp;</td>
  321. 	<td class="Code">/CLASS:<em>class</em></td>
  322. 	<td>&nbsp;</td>
  323. 	<td>Specifies the WMI class to be selected</td>
  324. </tr>
  325. <tr class="Top">
  326. 	<td colspan="2">&nbsp;</td>
  327. 	<td class="Code">/GENERATE</td>
  328. 	<td>&nbsp;</td>
  329. 	<td>Generate the code immediately<br>
  330. 		(requires <code>/CLASS</code> and, optionally, <code>/LANGUAGE</code> and <code>/NAMESPACE</code>)</td>
  331. </tr>
  332. <tr class="Top">
  333. 	<td colspan="2">&nbsp;</td>
  334. 	<td class="Code">/RUN</td>
  335. 	<td>&nbsp;</td>
  336. 	<td>Run the generated VBScript code immediately<br>
  337. 		(requires <code>/CLASS</code> and, optionally, <code>/NAMESPACE</code>)</td>
  338. </tr>
  339. <tr class="Top">
  340. 	<td colspan="2">&nbsp;</td>
  341. 	<td class="Code">/COPY</td>
  342. 	<td>&nbsp;</td>
  343. 	<td>Copy the generated code or result to the clipboard<br>
  344. 		(requires <code>/GENERATE</code> or <code>/RUN</code>)</td>
  345. </tr>
  346. <tr class="Top">
  347. 	<td colspan="2">&nbsp;</td>
  348. 	<td class="Code">/SAVE:"<em>filename</em>"</td>
  349. 	<td>&nbsp;</td>
  350. 	<td>Save the generated code or result to a file<br>
  351. 		(requires <code>/GENERATE</code> or <code>/RUN</code>; existing files will be overwritten without confirmation)</td>
  352. </tr>
  353. <tr class="Top">
  354. 	<td colspan="2">&nbsp;</td>
  355. 	<td><code>/?</code> or <code>/HELP</code></td>
  356. 	<td>&nbsp;</td>
  357. 	<td>Show this message</td>
  358. </tr>
  359. <tr><td colspan="5">&nbsp;</td></tr>
  360. <tr class="Top">
  361. 	<td><strong>Notes:</strong></td>
  362. 	<td><strong>&nbsp;1:&nbsp;</strong></td>
  363. 	<td colspan="3">The optional configuration file is named "WMIGen.cfg", and must be located in the same folder where this HTA is located.<br>
  364. 		"WMIGen.cfg" is formated as a single command line, e.g. <code>/WIN32 /NOPERF /LANGUAGE:C#</code></td>
  365. </tr>
  366. <tr class="Top">
  367. 	<td>&nbsp;</td>
  368. 	<td><strong>&nbsp;2:&nbsp;</strong></td>
  369. 	<td colspan="3">Command line arguments will always prevail over "WMIGen.cfg" settings!</td>
  370. </tr>
  371. <tr class="Top">
  372. 	<td>&nbsp;</td>
  373. 	<td><strong>&nbsp;3:&nbsp;</strong></td>
  374. 	<td colspan="3">To run without <em>any</em> user interaction requires one of the following combinations of command line arguments:
  375. 		<ul>
  376. 			<li class="Code">/CLASS:"<em>class</em>" /GENERATE /COPY</li>
  377. 			<li class="Code">/CLASS:"<em>class</em>" /GENERATE /SAVE:"<em>filename</em>"</li>
  378. 			<li class="Code">/CLASS:"<em>class</em>" /RUN /COPY</li>
  379. 			<li class="Code">/CLASS:"<em>class</em>" /RUN /SAVE:"<em>filename</em>"</li>
  380. 		</ul>
  381. 		<code>/NAMESPACE:"<em>namespace</em>"</code> and <code>/LANGUAGE:"<em>language</em>"</code> are optional, their default values <code>root/CIMV2</code> and <code>Batch</code> will be used if not specified.</td>
  382. </tr>
  383. <tr class="Top">
  384. 	<td>&nbsp;</td>
  385. 	<td><strong>&nbsp;4:&nbsp;</strong></td>
  386. 	<td colspan="3">If the extension of <code><em>filename</em></code> is "<code>.*</code>", it will be replaced by an extension based on the selected language, i.e. "<code>.bat</code>" for Batch, "<code>.cs</code>" for C#, etcetera, or by "<code>.txt</code>" for WMI query results.</td>
  387. </tr>
  388. <tr class="Top">
  389. 	<td>&nbsp;</td>
  390. 	<td><strong>&nbsp;5:&nbsp;</strong></td>
  391. 	<td colspan="3">On startup, the HTA checks if it is running with elevated privileges, and displays an error message if not.<br>
  392. 		On 64-bit systems, HTAs may be incorrectly associated with the 32-bit MSHTA.EXE (<code>%windir%\<strong>SysWOW64</strong>\mshta.exe</code>).
  393. 		As a result, you would get the error message regardless of privileges.<br>
  394. 		In that case, add the path to the proper (64-bit) MSHTA to this HTA's command line:<br>
  395. 		<br>
  396. 		<code>%windir%\<strong>system32</strong>\mshta.exe "<span id="PathToHTA">d:\path\WMIGen.hta</span>" [ options ]</code></td>
  397. </tr>
  398. <tr class="Top">
  399. 	<td>&nbsp;</td>
  400. 	<td><strong>&nbsp;6:&nbsp;</strong></td>
  401. 	<td colspan="3">Also on startup, the HTA checks if an update is available, and will prompt you to download it if so.</td>
  402. </tr>
  403. <tr><td colspan="5">&nbsp;</td></tr>
  404. <tr class="Top">
  405. 	<td><strong>Examples:</strong></td>
  406. 	<td>&nbsp;</td>
  407. 	<td colspan="3" class="Code Nowrap">WMIGEN.HTA /WIN32 /NOPERF /SIZE:1024x768</td>
  408. </tr>
  409. <tr class="Top">
  410. 	<td colspan="2">&nbsp;</td>
  411. 	<td colspan="3" class="Code Nowrap">WMIGEN.HTA /NAMESPACE:root/SecurityCenter2</td>
  412. </tr>
  413. <tr class="Top">
  414. 	<td colspan="2">&nbsp;</td>
  415. 	<td colspan="3" class="Code Nowrap">WMIGEN.HTA /NAMESPACE:root/WMI /CLASS:WmiMonitorID /GENERATE /SAVE:"monitor_inventory.bat"</td>
  416. </tr>
  417. <tr class="Top">
  418. 	<td colspan="2">&nbsp;</td>
  419. 	<td colspan="3" class="Code Nowrap">WMIGEN.HTA /NAMESPACE:root/WMI /CLASS:WmiMonitorID /RUN /COPY<br>
  420. 	    <a href="http://www.robvanderwoude.com/csharpexamples.php#Paste">PASTE.EXE</a> &gt;&gt; monitor_inventory.txt</td>
  421. </tr>
  422. <tr class="Top">
  423. 	<td colspan="2">&nbsp;</td>
  424. 	<td colspan="3" class="Code Nowrap">WMIGEN.HTA /CLASS:Win32_BIOS /LANGUAGE:C# /GENERATE /SAVE:"bios_query.cs"</td>
  425. </tr>
  426. <tr><td colspan="5">&nbsp;</td></tr>
  427. <tr>
  428. 	<td class="Center" colspan="5"><input onclick="OnClickButtonCancel" type="submit" value="Back" class="Button" title="Return to the main program"></td>
  429. </tr>
  430. </table>
  431.  
  432. </div><!-- End of "Help" block -->
  433.  
  434. <div id="Credits" class="Help" style="display: none; height: 100%;">
  435.  
  436. <h1 id="CreditsTitle">Credits for WMI Code Generator</h1>
  437.  
  438. <p>&nbsp;</p>
  439.  
  440. <p>Based on the Microsoft TechNet ScriptCenter article <a href="http://www.microsoft.com/technet/scriptcenter/resources/guiguy/default.mspx">Scripting Eye for the GUI Guy</a>.</p>
  441.  
  442. <p>Created with the help of <a href="http://technet.microsoft.com/en-us/library/cc785775%28v=ws.10%29.aspx" class="Code">WBEMTEST</a>, the Scripting Guys' <a href="http://www.microsoft.com/technet/scriptcenter/tools/scripto2.mspx">Scriptomatic</a> and <a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=231D8143-F21B-4707-B583-AE7B9152E6D9">HTA Helpomatic</a> tools, and Adersoft's <a href="http://www.htaedit.com/">HTAEdit</a>.</p>
  443.  
  444. <p>Java code based on NickDMax's <a href="http://www.dreamincode.net/code/snippet3297.htm">JACOB sample</a> on DreamInCode.net.</p>
  445.  
  446. <p>Lua code based on "test_wmi.lua" example that comes with the <a href="https://code.google.com/p/luaforwindows/">Lua for Windows</a> installation package.</p>
  447.  
  448. <p>Object Pascal (Delphi &trade;) code based on <a href="http://theroadtodelphi.wordpress.com/2010/12/01/accesing-the-wmi-from-pascal-code-delphi-oxygene-freepascal/#Lazarus">sample WMI code</a> from "The Road To Delphi"; adapted for, and tested in, <a href="http://www.lazarus.freepascal.org/">Lazarus IDE</a>.</p>
  449.  
  450. <p>Object Rexx code based on the Rexx script samples found at Microsoft's <a href="http://www.microsoft.com/technet/scriptcenter/scripts/rexx/default.mspx?mfr=true">Script Repository</a>; tested with <a href="http://www.oorexx.org/">Open Object Rexx</a>.</p>
  451.  
  452. <p>Ruby code based on David Mullet's <a href="http://rubyonwindows.blogspot.com/2007/07/using-ruby-wmi-to-get-win32-process.html">Using Ruby & WMI to Get Win32 Process Information</a>.</p>
  453.  
  454. <p>MSDN Help search function based on <a href="http://www.google.com/">Google Search</a> and completed with help from <a href="http://www.seroundtable.com/archives/015944.html">Search Engine Roundtable</a>.</p>
  455.  
  456. <p>Check for <a href="http://www.robvanderwoude.com/clevertricks.php#Elevated2">elevated privileges</a> by Denis St-Pierre.</p>
  457.  
  458. <p>&nbsp;</p>
  459.  
  460. <p class="Center"><input onclick="OnClickButtonCancel" type="submit" value="Back" class="Button" title="Return to the main program"></p>
  461.  
  462. </div><!-- End of "Credits" block -->
  463.  
  464. <div class="Center" style="color: black;">
  465. <p><span style="font-size: 12pt">WMI Code Generator,&nbsp; Version <span id="AppVersion">0.00</span></span><br>
  466. &copy; 2006 - <span id="CopyrightsYear">2013</span> Rob van der Woude<br>
  467. <a href="http://www.robvanderwoude.com/wmigen.php">http://www.robvanderwoude.com/wmigen.php</a></p>
  468. </div>
  469.  
  470. </div><!-- End of "Center" style block -->
  471.  
  472. </body>
  473. </html>