Dim UnArgs
Set UnArgs = WScript.Arguments.Unnamed
WScript.Echo UnArgs(0)
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colServiceList = objWMIService.ExecQuery("Associators of " _
& "{Win32_Service.Name='" & UnArgs(0) & "'} Where " _
& "AssocClass=Win32_DependentService " & "Role=Antecedent" )
for each s in colServiceList
WScript.Echo s.name
next
Function GetDep {
$mos = (new-object system.management.ManagementObjectSearcher)
$mos.Query = "Associators of {Win32_Service.Name='" + $Args[0] + "'} Where AssocClass=Win32_DependentService Role=Antecedent"
$mos.get()
}
then how to get the related class
a Get-Method on the Object revealed the GetRelated Property
hence ,
Function GetServiceDeps {($s = get-wmiObject win32_service -filter "Name = '$($args[0])'").GetRelated("win32_service")}
And Ready ..
Much more Clean, shorter and more MSH
but then again .....maybe NOT..... (c) LSL
I did forget the Role-part this does not matter for "lanmanserver" so I did not see it at first but this will give also the relations the service is dependend on.
OK, lets look again at that Method :
MSH G:\Monad> (get-wmiObject win32_service -filter "Name = 'lanmanserver'").GetRelated.OverloadDefinitions
System.Management.ManagementObjectCollection GetRelated()
System.Management.ManagementObjectCollection GetRelated(String relatedClass)
System.Management.ManagementObjectCollection GetRelated(String relatedClass, String relationshipClass, String relationshipQualifier, String relatedQualifier,String relatedRole, String thisRole, Boolean classDefinitionsOnly, EnumerationOptions options)
(I left out the ASync Methods)
Oops, IMNSHO that is not a nice Overload !!!
(Quiz Question : You know them All well enough to fill the 3th overload ?)
I do now ;-) (see later in post) and it seems that you can keep the ones you don't need empty.
it is :
MSH G:\Monad> (get-wmiObject win32_service -filter "Name = 'lanmanserver'").GetRelated($null,"Win32_DependentService",$null,$null,$null,"Antecedent",$false,$null)
after playing a bit I stopped at :
((($s = get-wmiObject win32_service -filter "Name = 'lanmanserver'").GetRelationships("win32_Dependentservice")) foreach {$_.dependent}).split("=")[1]What do you think ? , In this case I would more like the ".NET" solution ;-)
So I needed his brother-class : System.Management.RelatedObjectQuery(System.Management.RelatedObjectQuery is related to GetRelated
and RelationshipQuery to GetRelationships)
.So ... and what can we do with thos 2 classes ?
Translate WQL Query's to Properties and Back !!!
MSH G:\Monad> $roq = new-object System.Management.RelatedObjectQuery
MSH G:\Monad> $roq.QueryString = "associators of {Win32_Service.name='lanmanserver'} where resultclass = win32_service role = Antecedent"
MSH G:\Monad> $roq
IsSchemaQuery : False
SourceObject : Win32_Service.name='lanmanserver'
RelatedClass : win32_service
RelationshipClass :
RelatedQualifier :
RelationshipQualifier :
RelatedRole :
ThisRole : Antecedent
ClassDefinitionsOnly : False
QueryLanguage : WQL
QueryString : associators of {Win32_Service.name='lanmanserver'} wher
e resultclass = win32_service role = Antecedent
$roq = new-object System.Management.RelatedObjectQueryIn the MSHObjectviewer you can change the Properties (or the Query), and you will see the effect in the Query(or the properties). You have to change to another field to see the reaction.
ov($roq)
$mos = new-object system.management.ManagementObjectSearcher($roq)
October 2005 November 2005 December 2005 January 2006 February 2006 March 2006 April 2006 May 2006 June 2006 July 2006 August 2006 September 2006 October 2006 November 2006 December 2006