Working with Windows 8.1 Control Panel Applets

Introduction

I've always been intrigued by the Control Panel; what are those items in the Control Panel? Are they programs? What makes them appear? With this article, I will show you how to run all the various Control Panel applets from your own program.

Control Panel Applets Explained

Control Panel Applets are special purpose Dynamic Link Libraries (DLLs) that let users configure the environment of Microsoft Windows.

The primary responsibility of any Control Panel Applet is to display a window (typically a dialog box or property sheet) and to carry out any tasks specified by the user. Despite this responsibility, Control Panel Applets do not provide menus or other direct means for users to access their dialog boxes. Instead, these applications operate under the control of another application and launch their subprograms only when requested by the controlling application.

Behind the Scenes in Executing these Applets

To open or run these applets, we could use a Windows utility named RunDll32. RunDll32 enables you to call functions exported from a 32-bit DLL. These functions must have the following syntax:

void CALLBACK EntryPoint(
   HWND hwnd,        // handle to owner window
   HINSTANCE hinst,  // instance handle for the DLL
   LPTSTR lpCmdLine, // string the DLL will parse
   int nCmdShow      // show state
);

Now, I'm not going to go into the details of the physical contents these files need to have, but I'm just quickly going to explain how the RunDll32 utility works. Rundll32 loads the specified DLL using LoadLibrary, obtains the address of the function using the GetProcAddress function, and calls the function with the specified arguments, if any. When the function returns, Rundll32 unloads the DLL and exits.

It is possible to create a Unicode version of the function. Rundll32 first tries to find a function named EntryPointW. If it cannot find this function, it tries EntryPointA, then EntryPoint.

Executing the Control Panel Applets

To make use of the RunDll32 utility in our program, we need to have a look at the Process class. This class provides access to local and remote processes and enables you to start and stop local system processes.

A Process object provides access to a process that is running on a computer. A process, in the simplest terms, is a running application. A thread is the basic unit to which the operating system allocates processor time.

To start a Process, we can use the Start method from the Process class; we can also include the StartInfo parameter that can be used to duplicate the functionality of the Run dialog box of the Windows Start menu.

Our Project

Design your VB Windows Form application to resemble Figure 1.

ConPanApp
Figure 1: Our design

Running the Add or Remove Programs

Private Sub btnAddRemoveProgs_Click(ByVal sender As System.Object, _
   ByVal e As System.EventArgs) Handles btnAddRemoveProgs.Click

   'add & remove programs
   Process.Start("rundll32.exe", _
      "shell32.dll,Control_RunDLL appwiz.cpl,,1")

End Sub

Running the Date & Time Settings

Private Sub btnDateTime_Click(ByVal sender As System.Object, _
   ByVal e As System.EventArgs) Handles btnDateTime.Click

   'date & time
   Process.Start("rundll32.exe", _
      "shell32.dll,Control_RunDLL timedate.cpl,,1")

End Sub

Running the Display

Private Sub btnDisplay_Click(ByVal sender As System.Object, _
   ByVal e As System.EventArgs) Handles btnDisplay.Click

   'display
    Process.Start("rundll32.exe", _
      "shell32.dll,Control_RunDLL desk.cpl,,1")
End Sub

Running the Game Controls

Private Sub btnGame_Click(ByVal sender As System.Object, _
   ByVal e As System.EventArgs) Handles btnGame.Click

   'game controllers
   Process.Start("rundll32.exe", _
      "shell32.dll,Control_RunDLL joy.cpl")
End Sub

With this applet, there aren't any additional tabs.

Running the Internet Options

Private Sub btnInternet_Click(ByVal sender As System.Object, _
   ByVal e As System.EventArgs) Handles btnInternet.Click

   'internet options
   Process.Start("rundll32.exe", _
      "shell32.dll,Control_RunDLL inetcpl.cpl,,1")
End Sub

Running the Keyboard

Private Sub btnKeyboard_Click(ByVal sender As System.Object, _
   ByVal e As System.EventArgs) Handles btnKeyboard.Click

   'keyboard
   Process.Start("rundll32.exe", _
     "shell32.dll,Control_RunDLL main.cpl,@1,1")
End Sub

Running the Mouse

Private Sub btnMouse_Click(ByVal sender As System.Object, _
   ByVal e As System.EventArgs) Handles btnMouse.Click

   'mouse
   Process.Start("rundll32.exe", _
       "shell32.dll,Control_RunDLL main.cpl,@0,1")
End Sub

Running the System

Private Sub btnSystem_Click(ByVal sender As System.Object, _
   ByVal e As System.EventArgs) Handles btnSystem.Click

   'system
   Process.Start("rundll32.exe", _
      "shell32.dll,Control_RunDLL sysdm.cpl,@1,1")
End Sub

Running the Sounds and Audio

Private Sub btnSounds_Click(ByVal sender As System.Object, _
   ByVal e As System.EventArgs) Handles btnSounds.Click

    'sounds & audio
   Process.Start("rundll32.exe", _
      "shell32.dll,Control_RunDLL mmsys.cpl,,1")
End Sub

Running the Add Printer Wizard

Private Sub btnPrinters_Click(ByVal sender As System.Object, _
   ByVal e As System.EventArgs) Handles btnPrinters.Click

   'open add printer wizard
   Process.Start("rundll32.exe", _
      "shell32.dll,SHHelpShortcuts_RunDLL AddPrinter")
End Sub

Here, we used SHHelpShortcuts_RunDLL as the Entrypoint in the shell32.dll.

Running the Regional and Language Options

Private Sub btnRegional_Click(ByVal sender As System.Object, _
   ByVal e As System.EventArgs) Handles btnRegional.Click

   'regional settings
   Process.Start("rundll32.exe", _
      "shell32.dll,Control_RunDLL intl.cpl,,1")
End Sub

Running the Taskbar and Start Menu

Private Sub btnTaskbarStart_Click(ByVal sender As System.Object, _
   ByVal e As System.EventArgs) Handles btnTaskbarStart.Click

   'taskbar & start menu
   Process.Start("rundll32.exe", _
      "shell32.dll,Options_RunDLL 1")
End Sub

Here, we used Options_RunDLL as the Entrypoint.

Opening the Folder Options dialog

Private Sub btnFolder_Click(ByVal sender As System.Object, _
   ByVal e As System.EventArgs) Handles btnFolder.Click

   'folder options
   Process.Start("rundll32.exe", _
      "shell32.dll,Options_RunDLL 0")
End Sub

We also used Options_RunDLL here as our Entrypoint, but this time, we passed 0 to it.

Opening the Control Panel

Private Sub btnControl_Click(ByVal sender As System.Object, _
   ByVal e As System.EventArgs) Handles btnControl.Click

   'open the control panel
   Process.Start("rundll32.exe", _
      "shell32.dll,Control_RunDLL")
End Sub

Just using the Control_RunDLL Entrypoint, without any arguments, opens the Control Panel.

Running the Power Settings

Private Sub btnPower_Click(ByVal sender As System.Object, _
   ByVal e As System.EventArgs) Handles btnPower.Click

   'power settings
   Process.Start("rundll32.exe", _
      "shell32.dll,Control_RunDLL powercfg.cpl")
End Sub

Running the Add Hardware Wizard

Private Sub btnHardware_Click(ByVal sender As System.Object, _
   ByVal e As System.EventArgs) Handles btnHardware.Click

   'add hardware wizard
   Process.Start("rundll32.exe", _
      "shell32.dll,Control_RunDLL hdwwiz.cpl")
End Sub

Opening the Fonts folder

Private Sub btnFonts_Click(ByVal sender As System.Object, _
   ByVal e As System.EventArgs) Handles btnFonts.Click

   'open the fonts folder
   Process.Start("RUNDLL32.EXE", _
   "shell32.dll,SHHelpShortcuts_RunDLL FontsFolder")
End Sub

We used SHHelpShortcuts_RunDLL as the Entrypoint into shell32.dll again (just as we did when opening the Add Printer Wizard earlier). This time, however, we passed FontsFolder to the function.

Opening the Administrative Tools folder

Private Sub btnAdminTools_Click(ByVal sender As System.Object, _
   ByVal e As System.EventArgs) Handles btnAdminTools.Click

   'administration tools
   Process.Start("control.exe", _
      "admintools")
End Sub

This time, we didn't run RunDll32.exe at all, but Control.exe instead. Control.exe is another utility, included with Windows®, that also can run Control Panel applets. The nice thing about Control.exe is that it recognises special names for commonly used Control Panel items. This means we can execute an item such as AdminTools just by using its special name, instead of the corresponding .cpl file.

Running the Windows Firewall

Private Sub btnFirewall_Click(ByVal sender As System.Object, _
   ByVal e As System.EventArgs) Handles btnFirewall.Click

   'firewall settings
   Process.Start("RunDll32.exe", _
      "shell32.dll,Control_RunDLL firewall.cpl")
End Sub

Running Automatic Updates

Private Sub btnUpdates_Click(ByVal sender As System.Object, _
   ByVal e As System.EventArgs) Handles btnUpdates.Click

   'Automatic updates
   Process.Start("RunDll32.exe", _
      "shell32.dll,Control_RunDLL wuaucpl.cpl")
End Sub

Opening the Network Connections folder

Private Sub btnNetworkConn_Click(ByVal sender As System.Object, _
   ByVal e As System.EventArgs) Handles btnNetworkConn.Click

   'network connections
   Process.Start("RunDll32.exe", _
      "shell32.dll,Control_RunDLL ncpa.cpl")
End Sub

Opening User Accounts

Private Sub btnUsers_Click(ByVal sender As System.Object, _
   ByVal e As System.EventArgs) Handles btnUsers.Click

   'users
   Process.Start("RunDll32.exe", _
      "shell32.dll,Control_RunDLL nusrmgr.cpl")
End Sub

Opening the Scheduled Tasks folder

Private Sub btnTasks_Click(ByVal sender As System.Object, _
   ByVal e As System.EventArgs) Handles btnTasks.Click

'scheduled tasks
   Process.Start("control.exe", _
      "schedtasks")
End Sub

Running the Security Center

Private Sub btnSecurity_Click(ByVal sender As System.Object, _
   ByVal e As System.EventArgs) Handles btnSecurity.Click

   'security settings
   Process.Start("RunDll32.exe", _
      "shell32.dll,Control_RunDLL wscui.cpl")
End Sub

Opening the ODBC Data Source Administrator

Private Sub btnODBC_Click(ByVal sender As System.Object, _
   ByVal e As System.EventArgs) Handles btnODBC.Click

   'Open ODBC dialog box
   Process.Start("RunDll32.exe", _
      "shell32.dll,Control_RunDLL odbccp32.cpl")
End Sub

Opening Opens With

Private Sub btnOpenWith_Click(ByVal sender As System.Object, _
   ByVal e As System.EventArgs) Handles btnOpenWith.Click

   'Opens the Open With dialog box (the dialog box when
   'you right-click a file, and select Open With)
   Process.Start("RunDll32.exe", _
      "shell32.dll,OpenAs_RunDLL test.abd")
End Sub

This is actually quite handy when you have to set File Associations for unknown file types on the system. In the preceding example, I've use a filename of test with an .abd extension, with the use of executing this box from within our program, we can set up the necessary file association. I also made use of the OpenAs Entrypoint into Shell32.dll.

Opening Safely Remove Hardware

Private Sub btnSafe_Click(ByVal sender As System.Object, _
   ByVal e As System.EventArgs) Handles btnSafe.Click


   'Opens the Safely remove Hardware dialog, to remove,
   'for example, your USB stick
   Process.Start("RunDll32.exe", _
      "shell32.DLL,Control_RunDLL HotPlug.dll")
End Sub

With the preceding code, I used the Control_RunDLL Entrypoint, to run the DLL file named HotPlug.dll. This produces the Safely Remove Hardware dialog box.

Conclusion

I hope you have enjoyed reading this article!



Related Articles

Downloads

Comments

  • There are no comments yet. Be the first to comment!

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date