|
Comments
Did you read today's front page stories & breaking news?
SYS-CON.TV
|
Product Reviews Informative Screen Savers
Informative Screen Savers
By: Larry Perry
Apr. 28, 2003 12:00 AM
Have you ever needed to know the status of a user's computer, only to discover that the user had stepped away from his/her desk and locked the computer? Sometimes tracking down a user is difficult, and with today's tight schedules, we do not always have time to wait. Using the System.Management namespace and Microsoft Visual Studio .NET, we can help eliminate the long waits by creating a screen saver that will display the information we are seeking. Windows Management Instrumentation (WMI) has been around since the later versions of Microsoft Windows 95. Since WMI runs as a service in Windows, we can look at the task manager to see the service. It normally appears as "WinMgt.exe." Since literally everything we do on a computer is considered an object, we need an interface to query for information on the objects that concern us. The Common Information Model Object Manager (CIMOM) organizes the many objects available to Windows. Since WMI first appeared, Microsoft has continued to evolve the interfaces available to developers. With the introduction of the .NET Framework, Microsoft has given developers a simple interface for querying and obtaining information from the WMI repository, the System.Management namespace. This namespace is part of the .NET Framework and is used to access objects stored in the WMI Repository. Using management objects, you can query CIMOM to obtain the information you need. The screen saver I will show you how to create will demonstrate just how simple the interface has become. To learn more about WMI, System.Management, and the WMI repository, please visit Microsoft's Web site (www.microsoft.com) and search on "WMI." Now that you have a brief background on what the System.Management namespace represents, let's write a screen saver that will display the following information about a local computer: the currently running operating system and service pack level; the processor and the current load on the processor; and a listing of all accessible drives.
Getting Started
For this example, we need only a few objects from the toolbar. So let's add four labels and a timer control. Just click and drag them onto the Windows Form. Once you have placed them on the form, you will need to make some adjustments.
Now that you have your form set up, you can start writing your code. Begin by double-clicking on the Windows Form itself. Visual Studio will open a code window. This code window will display an empty Load event. For now, just ignore this event. To create your screen saver, follow these steps:
using System.Management;
and press enter.
public const int TIMER_COUNT = 10;
4. After the main method, static void Main(), ends with a closing curly brace (}), add a new method called GetInfo(). The code in Listing 1 defines the GetInfo() method.
GetInfo();
These two lines enable the timer and make the initial call to get your display information.
private void frmWMI_MouseDown
8. To complete your new informative screen saver, add a new class to your solution. To do this, go to the Solution Explorer on the right side of the screen, and right-click on the project name. Choose Add, then New Item from the menu that comes up. When the New Item Window appears, click on "class" in the window and give your class a name, then select Open or press the enter key.
Final Steps Once the code has been successfully compiled, you need to test it. Using Windows Explorer, navigate to the bin\debug (or bin\release) directory of your project. On my machine I have all of my projects under C:\VSPROJ\; however, you may have used the default, C:\Visual Studio Projects. Locate your solution directory and navigate to its bin\debug (or bin\release) directory. In the debug (or release) directory, you will find the .EXE file, which represents your compiled assembly. You need to rename the file from .EXE to .SCR, and copy it into the WinNT\System32 directory to test it out. Once you have copied the assembly, right-click on your desktop and select properties (see Figure 1). Now select the Screen Saver tab and choose your project from the dropdown menu. Try clicking on the settings and preview buttons. We did not create a Settings screen for this example, and instead chose to use a Message box, so a Message box displays (see Figure 2). When you click the preview button, the screen saver will run (see Figure 3). The screen saver may take a few seconds to display initially, since this is the first call to the WMI repository.
Conclusion There is an enormous amount of information available through the System.Management namespace. To see what other types of information are available, you can visit Microsoft's Web site. Microsoft has created a script database of commonly accessed information. The WQL queries and properties are all accessible through the use of the System.Management namespace. Therefore, it is up to you as the developer to determine what is useful for your organization. Reader Feedback: Page 1 of 1
Latest Cloud Developer Stories
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
|
SYS-CON Featured Whitepapers
Most Read This Week
|
||||||||||||||||||||||||||||||||||||||||||||||||