Articles   Members Online: 3
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to set the current screensaver Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
17-Jun-03
Category
System
Language
Delphi 2.x
Views
147
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			 

In my company each user needs to have a screensaver set with a specific timeout 
period, how can I do this?

Answer:

The following code sets up your desired screensave then shows it. For actual use 
this code needs to be changed to suite your needs i.e. remove ShowMessage dialogs, 
change name of screensaver, change timeout value and remove actual testing section. 

Tested under Windows XP but should work with earlier versions of Windows 

1   program SetupDefaultScrnSaver;
2   
3   uses
4     Windows, SysUtils, Forms, Dialogs, Registry;
5   
6   const
7     { from Windows.pas }
8     SPI_SETSCREENSAVEACTIVE = 17;
9     SPIF_SENDWININICHANGE = 2;
10    SPI_SETSCREENSAVETIMEOUT = 15;
11    { from Messages.pas }
12    WM_SYSCOMMAND = $0112;
13  
14    { From Project JEDI JCL library
15      http://www.delphi-jedi.org/Jedi:CODELIBJCL:22798 }
16  
17  function GetWindowsSysFolder: string;
18    procedure StrResetLength(var S: AnsiString);
19    begin
20      SetLength(S, StrLen(PChar(S)));
21    end;
22  var
23    Required: Cardinal;
24  begin
25    Result := '';
26    Required := GetSystemDirectory(nil, 0);
27    if Required <> 0 then
28    begin
29      SetLength(Result, Required);
30      GetSystemDirectory(PChar(Result), Required);
31      StrResetLength(Result);
32    end;
33  end;
34  
35  function SetScreenSave(const Name: string; const TimeOut: Integer = 30): Boolean;
36  const
37    SixtySeconds = 60;
38  var
39    Reg: TRegistry;
40  begin
41    if not FileExists(Name) then
42    begin
43      ShowMessage('ScreenSaver "' + Name + '" not located');
44      exit;
45    end;
46  
47    Reg := TRegistry.Create;
48    Reg.RootKey := HKEY_CURRENT_USER;
49    try
50      with Reg do
51      begin
52        if OpenKey('Control Panel\Desktop', False) then
53        begin
54          WriteString('SCRNSAVE.EXE', Name);
55          WriteString('ScreenSaverIsSecure', '1');
56          CloseKey;
57        end
58        else
59        begin
60          Result := False;
61          exit;
62        end;
63      end;
64    finally
65      Reg.Free;
66    end;
67  
68    SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, 1, nil, SPIF_SENDWININICHANGE);
69    SystemParametersInfo(SPI_SETSCREENSAVETIMEOUT, SixtySeconds * TimeOut,
70      nil, SPIF_SENDWININICHANGE);
71    Result := True;
72  end;
73  
74  begin
75    { -=CHANGE THE SCREENSAVER NAME TO ONE YOU WANT THE USER TO HAVE=- }
76    if SetScreenSave(GetWindowsSysFolder + '\ss3dfo.scr') then
77    begin
78      ShowMessage('Screensaver set, press OK to test (remember grace period)');
79      PostMessage(GetDesktopWindow, WM_SYSCOMMAND, SC_SCREENSAVE, 0);
80    end;
81  end.


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC