Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for wmigen.hta

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

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