Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 01-09-2001, 10:20 PM
bizcom bizcom is offline
Junior Member
 
Join Date: Jan 2001
Posts: 1
Default Restricting users of an application in a network situation

SITUATION:
A small program located in shared file on a server, that file mapped as a network drive on 20 pc's. A shortcut to this file on users desktops.
PROBLEM:
I need to restrict the amount of users who can use the file simultaneously to 1.
SOLUTION:
Request one,

Does any one have any knowledge they would like to share to solve this problem. Is there a component out there that will simplify this process or does it need to be done programatically. Any input greatly appreciated.
Reply With Quote
  #2  
Old 01-09-2001, 11:56 PM
douglas douglas is offline
Senior Member
 
Join Date: Jul 2001
Posts: 7,695
Default RE: Restricting users of an application in a network situation

This would be a simple solution.

program OnlyOneOpen;

uses
Forms, SysUtils, classes, windows, dialogs,
uSingleRun in 'uSingleRun.pas' {Form1};

{$R *.RES}

var
MyFile: string;
FileHandle: Integer;

begin
MyFile := ExtractFilePath(Application.ExeName)+'running.now' ;
if FileExists(MyFile) then
begin
ShowMessage('Another user already has this software open');
exit;
end;

try
FileHandle := FileCreate(MyFile);
finally
FileClose(FileHandle);
end;

Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;

if FileExists(MyFile) then
DeleteFile(PChar(MyFile));
end.

You could choose to store the file in the temp directory, or somewhere else.

When someone runs the program it creates an empty file wherever you specify. When they close it then it deletes the file. If the file already exists, then it will show the message. I don't know if this is the most solid solution, but should work.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 11:49 PM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.