1. Home
  2. Computing & Technology
  3. Delphi Programming
Computer restrictions with Delphi and Registry
How to enable your applications to make restrictions to what users can (and cannot) do with their computer using Delphi and the Registry.
 Win prizes by sharing code!
Do you have some Delphi code you want to share? Are you interested in winning a prize for your work?
Delphi Programming Quickies Contest
 Join the Discussion
"Post your views, comments, questions and doubts to this article."
Discuss!
 Related Resources
• Delphi and Registry Basics
• Monitoring Registry Changes
• Using the RunOnce Registry Key
 Elsewhere on the Web
• Registry Guide for Windows

If you ever wanted a quick and dirty way to disable (and enable) various Windows system configuration settings, and to disable a user from, for example, displaying the Control Panel, or shutting down the machine, this is the article for you!

What is Registry?
The Registry is simply a database that an application can use to store and retrieve configuration information (last window size and position, user options and information or any other configuration data). Registry also contains information about Windows and about your Windows configuration.

TRegistry
In Delphi, TRegistry class (defined in the registry unit) is a wrapper for the system registry and functions that operate on the registry. The "Delphi and Registry - an introduction" article explores the TRegistry class and discusses some basic techniques of editing the registry entries with Delphi.

Registry tweaks, tricks & hacks
Want to deny access to the Display Settings? Need to hide the Desktop? Interested in disabling the Shut Down button on the CTRL+ALT+DEL Security dialog?

Note: all the above restrictions can be done using the Registry editor tool that comes with Windows. Regedit.exe enables you to view, search and edit the data within the Registry. The simplest way to start the regedit is to click on the Start button, then select Run, and in the Open box type "regedit". I will not explain working with the Regedit here, be sure to check the "Registry Guide for Windows" site for more detailed explanations.

What we are interested here is how to implement all those *nice* system restrictions using Delphi.

Note! Editing the registry can cause very serious problems that may result in the reinstallation of your (or your users) operating system. Use the information provided in this article at your own risk!

Before we move to Delphi code, let's see how to remove the ShutDown button from the Start Menu.

  1. Start Regedit
  2. Go to HKEY_Current_User/Software/Microsoft/Windows/CurrentVersion/Policies. Several sub-keys like Explorer should already be created here.
  3. Open the Explorer key
  4. Add a "NoClose" (without the " marks) DWORD value and set it to 1. In all alike tweaks, data value of 0 is off and a data value of 1 is on.
  5. You may need to restart or log out of Windows for the change to take effect.
Registry tweaks, tricks & hacks using Delphi
Now, that we know what needs to be done manually to hide all the icons from the Desktop, let's see how to accomplish the same task using only Delphi code.

uses registry;
...
procedure Explorer_NoClose(const YesNo : boolean);
const 
  RegPolicies = 
    '\Software\Microsoft\Windows\CurrentVersion\Policies\';
  SubKey = 'Explorer\';
  YesNo10 : array[False .. True] of Word = (0, 1);
begin
  with TRegistry.Create do
  try
    RootKey:=HKEY_CURRENT_USER;
    if OpenKey(RegPolicies + SubKey, True) then
      WriteInteger('NoClose',YesNo10[YesNo]);
    CloseKey;
  finally
    Free;
  end;
end;

Yes that simple. No need to call the registry editor - all done using Delphi. Just call this procedure like Explorer_NoClose(True) and the ShutDown button on the Start menu is gone.

What follows is a list of some of the values you can add to registry to disable various system "operations":

Note: HKEY_Current_User/Software/Microsoft/Windows/CurrentVersion/Policies is the "root" key!

/Explorer
NoRunDisables Run command on the Start menu
NoLogoffDisable the Logoff button from the CTRL+ALT+DEL Security dialog
NoCloseRemove the Shutdown button from the Start menu
NoDesktopHide all Desktop icons
NoFindRemove the Find command from the Start Menu
NoNetConnectDisconnectRemoves the "Map Network Drive" and Disconnect Network Drive menu and right click options
NoSetFoldersHide Control Panel, Printers and My Computer on the Start Menu
NoControlPanelPrevents Control.exe, the Control Panel executable file, from starting. As a result, users cannot start Control Panel or run any Control Panel programs
NoDrivesTo hide a drive, turn on its' bit. For example to hide C: set a value of 4 to this key; to hide D: too, set the value to 12 (since D: is 8).
ResrictRunOnly programs that you define at: HKEY_CURRENT_USER\Software\Microsoft\Windows\ CurrentVersion\Policies\Explorer\RestrictRun can be run on the Workstation.
/System
DisableTaskMgrPrevents TaskMgr.exe from running
NoDispCPLDisables the Display option in Control Panel
NoDispBackgroundPageRemoves the ability to change wallpaper and background pattern from Control Panel.
/Network
NoWorkgroupContentsNetwork Neighborhood does not display computers in the local workgroup or domain
NoEntireNetworkRestrict Network Neighborhood from displaying or accessing computers outside the local workgroup or domain
NoFileSharingControlDisable file sharing controls
NoPrintSharingDisable print sharing controls

That's it. You can find the rest of the tweks on the "Registry Guide for Windows" site.

Explore Delphi Programming

More from About.com

  1. Home
  2. Computing & Technology
  3. Delphi Programming

©2008 About.com, a part of The New York Times Company.

All rights reserved.