Comments
Richard Davies wrote: The UK has a good crop of technology pioneers in cloud computing - for example ElasticHosts, FlexiScale, Flexiant, OnApp - and also some strong government initiatives such as G-Cloud. We will have to see whether this kind of technical leadership converts into swift mass-market adoption or not.
Cloud Expo on Google News

SYS-CON.TV
Cloud Expo & Virtualization 2009 East
PLATINUM SPONSORS:
IBM
Smarter Business Solutions Through Dynamic Infrastructure
IBM
Smarter Insights: How the CIO Becomes a Hero Again
Microsoft
Windows Azure
GOLD SPONSORS:
Appsense
Why VDI?
CA
Maximizing the Business Value of Virtualization in Enterprise and Cloud Computing Environments
ExactTarget
Messaging in the Cloud - Email, SMS and Voice
Freedom OSS
Stairway to the Cloud
Sun
Sun's Incubation Platform: Helping Startups Serve the Enterprise
POWER PANELS:
Cloud Computing & Enterprise IT: Cost & Operational Benefits
How and Why is a Flexible IT Infrastructure the Key To the Future?
Click For 2008 West
Event Webcasts
Informative Screen Savers
Informative Screen Savers

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
To begin, you need to load the Visual Studio IDE. When the Start Page appears, select New Project. You will be creating a C# Windows Application. Select this and give your project a name. After a few moments, a solution appears, along with a blank Windows Form.

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.
1.   Arrange the labels vertically (Label1 should be at the top, Label2 on the next line, etc.).
2.   Click on the bottom label to select and expand it vertically. It needs to be more of a box shape to display our drive mappings.
3.   For all of the labels, set the font to bold and 10 point to make the text more legible. Also, set the Auto Size property to true and the ForeColor property to white.
4.   Change the timer control's interval property to 1000. Since the interval is in milliseconds, this will cause it to update every second, which is what we want.
5.   Click on the Windows Form and set the ControlBox property to false, the ForeColor property to black, and the WindowState to maximized.

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:
1.   Select the Project menu, then Add References... On the .NET tab, scroll down to System. Management and highlight the entry, then click the Select button, followed by the OK button.
2.   At the top of the code window is a series of namespaces included by default. After the last using statement add a new line and type the following:

using System.Management;

and press enter.
3.   Next, move down a little in the code window. After the class declaration (public class), you will see some variable declarations. After these declarations, you need to add the following lines:

public const int TIMER_COUNT = 10;
internal int tmrCount = TIMER_COUNT;
internal bool blnChangeColor = true;

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.
5. Do you remember the Load event I told you to ignore earlier? You need to add two lines of code to it now:

GetInfo();
timer1.Enabled = true;

These two lines enable the timer and make the initial call to get your display information.
6.   Now click on the tab containing the form you were working with (the tab with "[Design]" on it). Double-click on the timer you added to the form. This will return you to the code window. Place the cursor within a method called timer1_Tick. Place the code in Listing 2 into this method.
7.   To finish off your Windows Form, add a Mouse_Down and Mouse_Move event to the code window as follows:

private void frmWMI_MouseDown
(object sender, System.Windows
.Forms.MouseEventArgs e)
{

Application.Exit();
}
private void frmWMI_Mouse
Move(object sender,
System.Windows.Forms.
MouseEventArgs e)
{
Application.Exit();
}

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.
9.   Now add the lines in Listing 3 to the code window that appears. The code should be added just after the public Class1() constructor.
10.   You need to make sure that your new class has using System .Windows.Forms; as one of the included namespaces at the top of the code window. The message box that you are using requires this namespace.
11.   Finally, right-click on the project name in the Solution Explorer. Select the properties option and set the Startup Object property to Class1.

Final Steps
You have now finished coding your screen saver; the next step is to compile it. From the Build menu, select Build Solution. When Visual Studio has completed the compilation, it will return control to Visual Studio. Errors that occur during compilation will appear in your Task List. Correct any errors and recompile.

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
Congratulations are in order! Not only have you learned to create screen savers, but you have done it with Visual Studio .NET!

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.

About Larry Perry
Larry Perry has been a Microsoft developer for the past 10 years. Most of his work has centered on database development using the FoxPro/Visual FoxPro environment. Recently, however, he has been working with Visual Studio.NET and SQL Server 2000. Larry is a Microsoft Certified Application Developer for .NET and continues to learn more about Microsoft?s latest technologies, including XML and ASP.NET.

In order to post a comment you need to be registered and logged in.

Register | Sign-in

Reader Feedback: Page 1 of 1

Latest Cloud Developer Stories
Rackspace Hosting, the service leader in cloud computing, on Thursday announced its acquisition of SharePoint911, an industry leader in SharePoint consulting, training, and "JumpStart" services within SharePoint. The unification of both companies provides capabilities to deliver ...
With Cloud Expo 2012 New York (10th Cloud Expo) now under four months away, what better time to start introducing you in greater detail to the distinguished individuals in our incredible Speaker Faculty for the technical and strategy sessions at the conference... We have techn...
Nimble, the social CRM platform has announced the launch of Nimble 2.0, billed as the “most social” CRM platform on the market today. Nimble was designed entirely with social CRM in mind and is the first social business platform that empowers companies with the ability to get clo...
2011 was a year of rapid adoption for public and private cloud services. Instant and on-demand server provisioning was the driving force behind the massive growth. On top, cloud server templates and script automation simplified application installation for simple and pre-defined ...
"Having been in the IT field for many years, I believe the cloud computing chapter in the industry is an exciting one and I am proud to be a part of it," said National Reconaissance Office (NRO) Chief Information Officer Jill T. Singer Tuesday, as it was announced that she was on...
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021

SYS-CON Featured Whitepapers
ADS BY GOOGLE