Active Topics Memberlist Calendar Search Help | |
Register Login |
One Stop Testing Forum : Testing Tools @ OneStopTesting : QuickTest Pro @ OneStopTesting |
Topic: All About Windows Management Instrumentation (WMI) |
|
Author | Message |
Mithi25
Senior Member Joined: 23Jun2009 Online Status: Offline Posts: 288 |
Topic: All About Windows Management Instrumentation (WMI) Posted: 22Sep2009 at 12:52am |
What is Windows Management Instrumentation(WMI)?WMI provides a model to represent, store and query configuration and status information of computers running Windows operating system. You can use WMI to fetch information from your system or from any other system in your network. Where can we use WMI in QTP?You can use WMI to query and retrieve information from a computer where a QTP script is running. WMI can be used for tasks like – but not limited to – finding the time zone of a machine, retrieving information about the currently running processes that you see in Windows Task Manager (Ctrl – Shift – Esc), finding physical memory (RAM), current RAM (commit charge), CPU usage etc. Here is a sample script to find the time zone of a machine. 01. Dim oWMIService, oComputer, colComputer 02. Dim strComputer 03. 04. strComputer = "." 05. 06. Set oWMIService = GetObject( "winmgmts:" _ 07. & "{impersonationLevel=impersonate}!\\" _ 08. & strComputer & "\root\cimv2" ) 09. 10. Set colComputer = oWMIService.ExecQuery _ 11. ( "Select * from Win32_TimeZone" ) 12. 13. For Each oComputer in colComputer 14. 15. msgbox oComputer.Description 16. 17. Exit For 18. Next 19. 20. Set oComputer = Nothing 21. Set colComputer = Nothing 22. Set oWMIService = Nothing Let us see what the statements above mean:
Output for the script above would look something like this: You can copy the above code into a .vbs file to get the time zone of your machine. What do we mean by namespace?Namespace in WMI can be defined as a logical database of classes and their instances. The parent of all namespaces is the root. Here is a sample script to get all namespaces contained inside root. 1. Set objWMIService = GetObject( "winmgmts:\\.\root" ) 2. Set colNamespaces = objWMIService.InstancesOf( "__NAMESPACE" ) 3. 4. For Each objNamespace In colNamespaces 5. print objNamespace.Name 6. Next
root\CIMV2 is the default WMI namespace. So, the first script would work fine even with this statement: 1. Set oWMIService = GetObject( "winmgmts:" _ 2. & "{impersonationLevel=impersonate}!\\”) Which namespace is required for us?As QTP developer, we would be working with CIMV2 workspace. So, we can consider this part to remain the same while writing WMI scripts. 1. Set oWMIService = GetObject( "winmgmts:" _ 2. & "{impersonationLevel=impersonate}!\\" _ 3. & strComputer & "\root\cimv2" ) How to write scripts in WMI?
How to identify which class and which property we want?There is no straightforward answer for this question. Knowledge
about classes and corresponding properties comes with experience.
Having said that, the names assigned to various classes are quite
meaningful. One way is to think of what name you would assign to a
given class if you were the developer. |
|
Post Resume: Click here to Upload your Resume & Apply for Jobs |
|
IP Logged | |
Forum Jump |
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |
© Vyom Technosoft Pvt. Ltd. All Rights Reserved.