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