|
|
 |
 |
 |
|
Join the Discussion
|
"Post your views, comments, questions and doubts to this article."
Discuss!
|
|
 |
 |
|
|
 |
 |
 |
|
|
 |
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.
- Start Regedit
- Go to HKEY_Current_User/Software/Microsoft/Windows/CurrentVersion/Policies. Several sub-keys like Explorer should already be created here.
- Open the Explorer key
- 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.
- 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 |
| NoRun | Disables Run command on the Start menu |
| NoLogoff | Disable the Logoff button from the CTRL+ALT+DEL Security dialog |
| NoClose | Remove the Shutdown button from the Start menu |
| NoDesktop | Hide all Desktop icons |
| NoFind | Remove the Find command from the Start Menu |
| NoNetConnectDisconnect | Removes the "Map Network Drive" and Disconnect Network Drive menu and right click options |
| NoSetFolders | Hide Control Panel, Printers and My Computer on the Start Menu |
| NoControlPanel | Prevents Control.exe, the Control Panel executable file, from starting. As a result, users cannot start Control Panel or run any Control Panel programs |
| NoDrives | To 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). |
| ResrictRun | Only programs that you define at:
HKEY_CURRENT_USER\Software\Microsoft\Windows\
CurrentVersion\Policies\Explorer\RestrictRun
can be run on the Workstation. |
| /System |
| DisableTaskMgr | Prevents TaskMgr.exe from running |
| NoDispCPL | Disables the Display option in Control Panel |
| NoDispBackgroundPage | Removes the ability to change wallpaper and background pattern from Control Panel.
|
| /Network |
| NoWorkgroupContents | Network Neighborhood does not display computers in the local workgroup or domain |
| NoEntireNetwork | Restrict Network Neighborhood from displaying or accessing computers outside the local workgroup or domain |
| NoFileSharingControl | Disable file sharing controls |
| NoPrintSharing | Disable print sharing controls |
That's it. You can find the rest of the tweks on the "Registry Guide for Windows" site.
|