Software metering provides the server-side SMS_MonthlyUsageSummary WMI class, which is created to hold monthly summary information for metered files. An instance of SMS_MonthlyUsageSummary provides information about items such as who used a metered file, how many times it was used, where it was used, and how long it was used.
Other classes are required for extracting further information from SMS_MonthlyUsageSummary. For example, SMS_MeteredUser provides the user name and SMS_R_System provides the computer name.
The following script obtains monthly usage summary data and shows how instances of SMS_MonthyUsageSummary and other WMI classes can be read to extract monthly summary information.
For additional information about using monthly usage summary data in WMI, see the SMS 2003 SDK.
Example
On Error Resume Next Dim objSWbemServices Dim ProviderLoc Dim Location Dim strMeteredFilesClass Dim strMeteredUsersClass Dim strMonthlyUsageSummaryClass Dim strComputerNamesClass Dim colMeteredUsers Dim colMonthlyUsageSummaries Dim colMeteredFiles Dim colComputerNames Dim objSummary Dim objMeteredUser Dim objMeteredFile Dim objComputer strMeteredFilesClass="SMS_MeteredFiles" strMonthlyUsageSummaryClass="SMS_MonthlyUsageSummary" strMeteredUsersClass="SMS_MeteredUser" strComputerNamesClass="SMS_R_System" Set ProviderLoc = GetObject("winmgmts:{impersonationLevel=impersonate}!root/sms:SMS_ProviderLocation") If err.number<>0 Then wscript.echo "Could not get SMS Provider" wscript.quit End If For Each Location In ProviderLoc.Instances_ If Location.ProviderForLocalSite = True Then Set objSWbemServices = GetObject("winmgmts:" & Location.NamespacePath) Exit For End If Next 'Get SMS_MeteredFiles--used to match FileID to a file name. Set colMeteredFiles=objSWbemServices.InstancesOf(strMeteredFilesClass) If err.number<>0 Then wscript.echo "Could not get Metered Files" wscript.quit End If 'Get SMS_MeteredUsers. Set colMeteredUsers=objSWbemServices.InstancesOf(strMeteredUsersClass) If err.number<>0 Then wscript.echo "Couldn't get Metered Users" wscript.quit End If 'Get the summarized files. Set colMonthlyUsageSummaries = objSWbemServices.InstancesOf(strMonthlyUsageSummaryClass) If err.number<>0 Then wscript.echo "Could not get Summarized files" wscript.quit End If 'Get computer names. Set colComputerNames = objSWbemServices.InstancesOf(strComputerNamesClass) If err.number<>0 Then wscript.echo "Could not get Summarized files" wscript.quit End If For Each objSummary In colMonthlyUsageSummaries wscript.echo "got into summaries" For Each objMeteredFile In colMeteredFiles If objMeteredFile.MeteredFileID=objSummary.FileID Then wscript.echo "File Name:" & objMeteredFile.FileName Exit For End If Next For Each objMeteredUser In colMeteredUsers If objMeteredUser.MeteredUserID=objSummary.MeteredUserID Then wscript.echo "User Name: " & objMeteredUser.FullName Exit For End If Next wscript.echo "Usage Count:" & objSummary.UsageCount wscript.echo "Terminal Service Usage Count:" & objSummary.TSUsageCount For Each objComputer In colComputerNames If objComputer.ResourceId=ObjSummary.ResourceID Then wscript.echo "Computer:" & objComputer.Name Exit For End If Next wscript.echo Next |
Compiling the Code
- Requires Windows 2000 Server SP2 or later.
- You must run this sample on an SMS 2003 primary site
server.