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

270 lines
11 KiB

  1. VERSION 1.0 CLASS
  2. BEGIN
  3. MultiUse = -1 'True
  4. END
  5. Attribute VB_Name = "Queries"
  6. Attribute VB_GlobalNameSpace = False
  7. Attribute VB_Creatable = True
  8. Attribute VB_PredeclaredId = False
  9. Attribute VB_Exposed = False
  10. Option Explicit
  11. 'Private wsoServices As DIWbemServices
  12. Private wsoServices As ISWbemServices
  13. Private numPasses As Integer
  14. Private numFails As Integer
  15. Private Passes As New Collection
  16. Private Fails As New Collection
  17. Private Sub AddPass(s As String)
  18. Passes.Add s, Trim(Str(numPasses))
  19. numPasses = numPasses + 1
  20. End Sub
  21. Private Sub AddFail(s As String)
  22. Fails.Add s, Trim(Str(numFails))
  23. numFails = numFails + 1
  24. End Sub
  25. Private Sub BuildList()
  26. AddPass "Monkeybutt!"
  27. AddPass "SELECT * FROM SMS_PropertyDisplayNode"
  28. AddPass "SELECT Nodename from SMS_PropertyDisplayNode"
  29. AddPass "SELECT Nodename from SMS_PropertyDisplayNode P"
  30. AddPass "SELECT P.Nodename from SMS_PropertyDisplayNode P"
  31. AddPass "SELECT Count(*) FROM SMS_PropertyDisplayNode"
  32. AddPass "SELECT Count(Nodename) FROM SMS_PropertyDisplayNode"
  33. AddPass "SELECT Count(SMS_PropertyDisplayNode.Nodename) FROM SMS_PropertyDisplayNode"
  34. AddPass "SELECT Count(P.Nodename) FROM SMS_PropertyDisplayNode P"
  35. AddPass "SELECT DISTINCT * FROM SMS_PropertyDisplayNode"
  36. AddPass "SELECT DISTINCT Nodename FROM SMS_PropertyDisplayNode"
  37. AddPass "SELECT DISTINCT SMS_PropertyDisplayNode.Nodename from SMS_PropertyDisplayNode"
  38. AddPass "SELECT DISTINCT P.Nodename from SMS_PropertyDisplayNode P"
  39. AddPass "SELECT * FROM SMS_Site, SMS_SiteControlFile"
  40. AddPass "SELECT SMS_Site.Sitename FROM SMS_Site, SMS_SiteControlFile"
  41. AddPass "SELECT P.Sitename FROM SMS_Site P,SMS_SiteControlFile"
  42. AddPass "SELECT P.Sitename FROM SMS_Site P,SMS_SiteControlFile R"
  43. AddPass "SELECT * FROM SMS_Site JOIN SMS_SiteControlFile ON SMS_Site.Sitecode=SMS_SiteControlFile.Sitecode"
  44. AddPass "SELECT * FROM SMS_Site P JOIN SMS_SiteControlFile ON P.Sitecode=SMS_SiteControlFile.Sitecode"
  45. AddPass "SELECT * FROM SMS_Site P JOIN SMS_SiteControlFile R ON P.Sitecode=R.Sitecode"
  46. AddPass "SELECT SMS_Site.Sitename FROM SMS_Site JOIN SMS_SiteControlFile ON SMS_Site.Sitecode=SMS_SiteControlFile.Sitecode"
  47. AddPass "SELECT P.Sitename FROM SMS_Site P JOIN SMS_SiteControlFile ON P.Sitecode=SMS_SiteControlFile.Sitecode"
  48. AddPass "SELECT P.Sitename FROM SMS_Site P JOIN SMS_SiteControlFile R ON P.Sitecode=R.Sitecode"
  49. AddPass "SELECT * FROM SMS_Site WHERE Sitecode=""ABC"""
  50. AddPass "SELECT * FROM SMS_Site WHERE Sitecode=""ABC"" AND Sitename=""blah"""
  51. AddPass "SELECT * FROM SMS_Site WHERE Sitecode=""ABC"" OR Sitename=""blah"""
  52. AddPass "SELECT * FROM SMS_Site WHERE NOT Sitecode=""ABC"""
  53. AddPass "SELECT * FROM SMS_Site WHERE NOT Sitecode=""ABC"" AND Sitename=""blah"""
  54. AddPass "SELECT * FROM SMS_Site WHERE NOT Sitecode=""ABC"" OR Sitename=""blah"""
  55. AddPass "SELECT * FROM SMS_Site WHERE NOT (Sitecode=""ABC"" AND Sitename=""blah"")"
  56. AddPass "SELECT * FROM SMS_Site WHERE NOT (Sitecode=""ABC"" OR Sitename=""blah"")"
  57. 'kludgey fast queries to satisfy some deep seated desire lamar had at this exact moment
  58. AddPass "SELECT * FROM SMS_PropertyDisplayNode Order By Nodekey"
  59. AddPass "SELECT * FROM SMS_PropertyDisplayNode Group By Nodekey"
  60. AddPass "SELECT * FROM SMS_PropertyDisplayNode Where Nodekey <= 7"
  61. AddPass "SELECT * FROM SMS_PropertyDisplayNode Where Nodekey < 7"
  62. AddPass "SELECT * FROM SMS_PropertyDisplayNode Where Nodekey >= 7"
  63. AddPass "SELECT * FROM SMS_PropertyDisplayNode Where Nodekey < 7"
  64. AddPass "SELECT * FROM SMS_PropertyDisplayNode Where Nodekey = 7"
  65. AddPass "SELECT * FROM SMS_PropertyDisplayNode Where Nodekey != 7"
  66. AddPass "SELECT * FROM SMS_PropertyDisplayNode Where Nodekey = 7 AND Classname=""SMS_G_System"""
  67. AddPass "SELECT * FROM SMS_PropertyDisplayNode Where Nodekey = 7 OR Classname=""SMS_G_System"""
  68. AddPass "SELECT * FROM SMS_PropertyDisplayNode Where Nodekey = 7 OR Classname=""SMS_G_System"" AND Nodekey=7"
  69. AddPass "SELECT * FROM SMS_PropertyDisplayNode Where (NOT Nodekey = 7 OR Classname=""SMS_G_System"") AND Nodekey=7"
  70. 'this should work! but it doesn't.
  71. 'AddPass "SELECT * FROM SMS_PropertyDisplayNode Where Classname like %SMS_G_System%"
  72. AddFail "SELECT Count(P.Sitename,R.BuildNumber) FROM SMS_Site P JOIN SMS_SiteControlFile R ON P.Sitecode=R.Sitecode"
  73. ''AddFail "SELECT PackageID FROM SMS_Package, SMS_Program"
  74. ''AddFail "SELECT PackageID FROM SMS_Package JOIN SMS_Program ON SMS_Package.PackageID=SMS_Program.PackageID"
  75. ''AddFail "SELECT PackageID FROM SMS_Package P JOIN SMS_Program ON P.PackageID=SMS_Program.PackageID"
  76. ''AddFail "SELECT PackageID FROM SMS_Package P JOIN SMS_Program R ON P.PackageID=R.PackageID"
  77. ''AddFail "SELECT P.Name FROM SMS_Package P JOIN SMS_Program R ON PackageID=PackageID"
  78. ''AddFail "SELECT P.Name FROM SMS_Package P JOIN SMS_Program R ON SMS_Package.PackageID=PackageID"
  79. 'AddFail "SELECT P.Name FROM SMS_Package P JOIN SMS_Program R ON P.PackageID=PackageID"
  80. 'AddFail "SELECT P.Name FROM SMS_Package P JOIN SMS_Program R ON R.PackageID=PackageID"
  81. End Sub
  82. Private Sub Class_Initialize()
  83. frmMain.lstModules.AddItem "Queries"
  84. frmMain.lstModules.Selected(frmMain.lstModules.ListCount - 1) = False
  85. numPasses = 0
  86. numFails = 0
  87. BuildList
  88. End Sub
  89. Public Function GetModuleInfo() As String
  90. GetModuleInfo = "Tests various WQL queries." & vbCrLf
  91. GetModuleInfo = GetModuleInfo & "Keep in mind that this module isn't fully functional as of 5/4/98"
  92. End Function
  93. Public Sub RegisterNodes()
  94. Dim i As Integer
  95. Dim s As String
  96. i = 0
  97. frmTest.AddNode "root", "qRoot", "Queries"
  98. frmTest.AddNode "qRoot", "qConnect", "Connect"
  99. 'frmTest.AddNode "qRoot", "qWarning", "Warning Message"
  100. frmTest.AddNode "qRoot", "qPass", "Queries that should succeed"
  101. frmTest.AddNode "qRoot", "qFail", "Queries that should fail"
  102. For i = 0 To numPasses - 1
  103. s = Passes(Trim(Str(i)))
  104. frmTest.AddNode "qPass", "qP" & Trim(Str(i)), s, False
  105. Tests.Add "Queries", "qP" & Trim(Str(i))
  106. Next i
  107. For i = 0 To numFails - 1
  108. s = Fails(Trim(Str(i)))
  109. frmTest.AddNode "qFail", "qF" & Trim(Str(i)), s, False
  110. Tests.Add "Queries", "qF" & Trim(Str(i))
  111. Next i
  112. End Sub
  113. Public Sub RegisterTests()
  114. Tests.Add "Queries", "qConnect"
  115. 'Tests.Add "Queries", "qWarning"
  116. 'Rest of the tests are registered in RegisterNodes. Inappropriate, but it really doesn't matter.
  117. End Sub
  118. Public Function Execute(n As Node) As Integer
  119. Select Case n.key
  120. Case "qConnect"
  121. Execute = qConnect(n)
  122. 'Case "qWarning"
  123. 'If Not frmTest.AllOfThesePassed("qConnect") Then
  124. ' Execute = 2
  125. 'Else
  126. ' Dim i As Integer
  127. ' i = MsgBox("These queries may crash CIMOM or the BVT. Continue?", vbYesNo + vbQuestion, "Warning")
  128. ' If i = vbNo Then
  129. ' Execute = 2
  130. ' Else
  131. ' Execute = 1
  132. ' End If
  133. 'End If
  134. 'Execute = 1
  135. Case Else
  136. If Left(n.key, 2) = "qP" Then
  137. Execute = ExecQuery(n, n.text)
  138. ElseIf Left(n.key, 2) = "qF" Then
  139. Execute = ExecQuery(n, n.text)
  140. If Execute = 0 Then
  141. Execute = 1
  142. Else
  143. Execute = 0
  144. End If
  145. Else
  146. Execute = 3
  147. End If
  148. End Select
  149. End Function
  150. Public Function ExecQuery(n As Node, query As String) As Integer
  151. On Error Resume Next
  152. If Not frmTest.AllOfThesePassed("qConnect") Then
  153. ExecQuery = 2
  154. Else
  155. 'Dim e As DIEnumWbemClassObject
  156. 'n.Tag = n.Tag & "ExecQuery: " & query & vbCrLf
  157. 'wsoServices.ExecQuery "wql", query, 0, Nothing, e
  158. 'If CheckError(Err.Number, n, query) Then Exit Function
  159. '
  160. 'Dim c As DWbemClassObject
  161. 'Dim s() As String
  162. 'Dim i As Integer
  163. 'Dim v As Variant
  164. 'Do While e.Next(-1, c) = 0
  165. ' c.GetNames vbNullString, WBEM_FLAG_KEYS_ONLY, vbNullString, s
  166. ' If CheckError(Err.Number, n, "Getnames Keys Only") Then Exit Function
  167. ' n.Tag = n.Tag & "Getnames UBound: " & UBound(s) & vbCrLf
  168. ' n.Tag = n.Tag & "Getnames LBound: " & LBound(s) & vbCrLf
  169. ' For i = LBound(s) To UBound(s)
  170. ' c.Get s(i), 0, v, 0, 0
  171. ' If CheckError(Err.Number, n, "Get " & s(i)) Then Exit Function
  172. ' n.Tag = n.Tag & s(i) & "=" & CStr(v) & vbCrLf & "----" & vbCrLf
  173. ' Next i
  174. 'Loop
  175. 'ExecQuery = 1
  176. '***************************
  177. 'catch the situation and debug it
  178. If n.key = "qP25" Then Stop
  179. '***************************
  180. Dim c As ISWbemObject
  181. Dim e As ISEnumWbemObject
  182. Dim p As ISWbemProperty
  183. Set e = wsoServices.ExecQuery(query, , 0)
  184. If CheckError(Err.Number, n, query) Then Exit Function
  185. For Each c In e
  186. If Err <> 0 Then
  187. Dim str1, str2, str3 As String
  188. str1 = Err.Description
  189. str2 = Err.Number
  190. str3 = Err.Source
  191. Else
  192. n.Tag = n.Tag & c.GetObjectText_ & vbCrLf
  193. For Each p In c.Properties_
  194. If VarType(p.Value) < 9 Then
  195. If CheckError(Err.Number, n, "Accessing results") Then
  196. Exit Function
  197. End If
  198. n.Tag = n.Tag & p.Name & " = " & p.Value & vbCrLf
  199. Else
  200. n.Tag = n.Tag & p.Name & " was skipped, weird type." & vbCrLf
  201. End If
  202. Next p
  203. n.Tag = n.Tag & "----" & vbCrLf
  204. End If
  205. Next c
  206. ExecQuery = 1
  207. End If
  208. End Function
  209. Private Function qConnect(n As Node) As Integer
  210. Dim wlo As New SWbemLocator
  211. Dim u As String
  212. Dim p As String
  213. Dim a As String
  214. If frmMain.chkUserid.Value Then
  215. u = vbNullString
  216. Else
  217. u = frmMain.txtUserid.text
  218. End If
  219. If frmMain.chkPassword.Value Then
  220. p = vbNullString
  221. Else
  222. p = frmMain.txtPassword.text
  223. End If
  224. If frmMain.chkAuthority.Value Then
  225. a = vbNullString
  226. Else
  227. a = frmMain.txtAuthority.text
  228. End If
  229. On Error Resume Next
  230. 'wlo.ConnectServer "\\" & frmMain.txtServer.text & "\root\sms\site_" & frmMain.txtSitecode.text, u, p, vbNullString, 0, a, Nothing, wsoServices
  231. Set wsoServices = wlo.ConnectServer(frmMain.txtServer.text, "root\sms\site_" & frmMain.txtSitecode.text, u, p)
  232. If CheckError(Err.Number, n, "Connecting to \\" & frmMain.txtServer.text & "\root\sms\site_" & frmMain.txtSitecode.text) Then Exit Function
  233. qConnect = 1
  234. End Function