Tag Archives: system

List USB devices in C#

This program uses WMI (Windows Management Instrumentation) to query for USB devices. To use WMI, add a references to System.Management and add a using System.Management directive. When it starts, this example uses the following code to list USB devices. // … Continue reading

Posted in system | Tagged , , , , , , , | Leave a comment

Activate another running program in C#

This is actually quite simple. First add a reference to the Microsoft.VisualBasic library. Then call Microsoft.VisualBasic.Interaction.AppActivate, passing it the title of the program that you want to activate as in the following code. using Microsoft.VisualBasic; … // Activate the program. … Continue reading

Posted in miscellany, system | Tagged , , , , , , , , , , | Leave a comment

Use System.Threading.Timer to make a countdown timer in C#

The post Make a countdown timer in C# uses a Timer control to count down the time until some deadline. This example does something similar but it uses a Timer object from the System.Threading namespace. The basic idea is similar: … Continue reading

Posted in miscellany, system | Tagged , , , , , , , , , , , , | Leave a comment

Suspend or hibernate the system in C#

The Application.SetSuspendState method lets an application make the system suspend or hibernate. A suspended system enters a low power mode. A hibernating system saves its memory contents to disk and then enters low power mode. Because it doesn’t need to … Continue reading

Posted in system | Tagged , , , , , , , , , , , , | Leave a comment

List controls on a form in C#

There are several ways you can list controls on a form. At design time, you can open the form and then use the dropdown at the top of the Properties window. You can also look inside the file Form1.Designer.cs. At … Continue reading

Posted in controls, forms, system | Tagged , , , , , , , , , | Leave a comment

Display the Astronomy Picture of the Day on the desktop in C#

This example combines the techniques from the following two posts: Download the Astronomy Picture of the Day in C# Set the Windows desktop picture in C# This example uses two settings, LastLoadTime and LastUrl, to determine whether it is a … Continue reading

Posted in graphics, image processing, internet, system | Tagged , , , , , , , , , , , , , , | Leave a comment

Randomly change the desktop picture in C#

The example Set the Windows desktop picture in C# shows how to display an image on the desktop. This example periodically changes the desktop picture to a randomly selected image file picked from a directory. Note that recent versions of … Continue reading

Posted in API, graphics, image processing, interoperability, system | Tagged , , , , , , , , , , , , , , , | Leave a comment

Set the Windows desktop picture in C#

This example sets the Windows desktop picture much as you can manually in Windows 10. (I can’t guarantee that it will work without any changes in other versions of Windows.) Exactly how you set the desktop picture manually depends on … Continue reading

Posted in API, graphics, interoperability, system | Tagged , , , , , , , , , , , , , , , | Leave a comment

See what processes have a file locked in C#

In older versions of Windows, it was impossible to determine what processes had a file locked. The system kept track of the number of locks on a file and processes were responsible for incrementing and decrementing the count to represent … Continue reading

Posted in files, system | Tagged , , , , , , , , , | 1 Comment

See if a file is locked in C#

Some applications lock files so you cannot write, read, delete, or otherwise mess with them. For example, when you open a file in Microsoft Word, it locks the file so you cannot delete it or open it for writing with … Continue reading

Posted in files, system | Tagged , , , , , , , , , , , , , , | 3 Comments