AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Win32/Win64 API (native code) limiting number of instances in Windows terminal server
Thema durchsuchen
Ansicht
Themen-Optionen

limiting number of instances in Windows terminal server

Ein Thema von imadam · begonnen am 4. Jun 2019 · letzter Beitrag vom 5. Jun 2019
Antwort Antwort
Seite 2 von 3     12 3      
Schokohase
(Gast)

n/a Beiträge
 
#11

AW: limiting number of instances in Windows terminal server

  Alt 5. Jun 2019, 09:10
We were able limit this to one instance of the app on Windows Desktop.
I guess you use a mutex for that.

For Terminal Server (or even in generell) do not use a global mutex as this would be for the whole system.

For an application with one instance you need one mutex.
For an application with two instances you need two mutexes.
...
  Mit Zitat antworten Zitat
Klaus01

Registriert seit: 30. Nov 2005
Ort: München
5.767 Beiträge
 
Delphi 10.4 Sydney
 
#12

AW: limiting number of instances in Windows terminal server

  Alt 5. Jun 2019, 09:14
.. but whith muutexes you have to decide how many instances can be started - at design time.
These settings are then based on application level - not on user level.

best regards
Klaus
Klaus
  Mit Zitat antworten Zitat
mjustin

Registriert seit: 14. Apr 2008
3.006 Beiträge
 
Delphi 2009 Professional
 
#13

AW: limiting number of instances in Windows terminal server

  Alt 5. Jun 2019, 09:20
Did you try TJvAppInstances already? It is designed for limiting app instances, and it allows to set the maximum number of simultaneous instances using the property MaxInstances. I am not soure however if it is also suited for a TS.
Michael Justin
habarisoft.com
  Mit Zitat antworten Zitat
Benutzerbild von Dalai
Dalai

Registriert seit: 9. Apr 2006
1.682 Beiträge
 
Delphi 5 Professional
 
#14

AW: limiting number of instances in Windows terminal server

  Alt 5. Jun 2019, 09:22
.. but whith muutexes you have to decide how many instances can be started - at design time.
Uh, no. A Mutex is based on a name, a string, and strings can be built at runtime. Example from one of my projects where the mutex name is based on a concatenation of several strings:hMutex:= CreateMutex(nil, True, PRODUCTNAME + PRODUCTNAME + PRODUCTCOPYRIGHT); Using usernames and an appended counter instead is trivial. Reading the information that user A can start the application X times and user B can start it only once is trivial, too (Registry, INI, XML, whatever). Use that in conjunction with a for-loop that tries to create mutexes until either all of them already exist, or the maximum allowed instances are reached, and you have reached your goal.

Regards
Dalai
  Mit Zitat antworten Zitat
imadam

Registriert seit: 4. Jun 2019
12 Beiträge
 
#15

AW: limiting number of instances in Windows terminal server

  Alt 5. Jun 2019, 09:28
.. but whith muutexes you have to decide how many instances can be started - at design time.
Uh, no. A Mutex is based on a name, a string, and strings can be built at runtime. Example from one of my projects where the mutex name is based on a concatenation of several strings:hMutex:= CreateMutex(nil, True, PRODUCTNAME + PRODUCTNAME + PRODUCTCOPYRIGHT); Using usernames and an appended counter instead is trivial. Reading the information that user A can start the application X times and user B can start it only once is trivial, too (Registry, INI, XML, whatever). Use that in conjunction with a for-loop that tries to create mutexes until either all of them already exist, or the maximum allowed instances are reached, and you have reached your goal.

Regards
Dalai
So far, my research gave me:
- I have to list processes in TS session
- I have to get username from TS enviroment which is logged in
and simple compare number of instances in question with number of those processes already running.
Is this wrong approach ?
Yet to figure out how to read logged user and processes over Win32 API .
  Mit Zitat antworten Zitat
Benutzerbild von Dalai
Dalai

Registriert seit: 9. Apr 2006
1.682 Beiträge
 
Delphi 5 Professional
 
#16

AW: limiting number of instances in Windows terminal server

  Alt 5. Jun 2019, 09:40
Yes, reading the number of processes running as user X is another possible approach. Unfortunately I don't know how to read the user a process runs as, even less when TS is involved.

Regards
Dalai
  Mit Zitat antworten Zitat
hoika

Registriert seit: 5. Jul 2006
Ort: Magdeburg
8.273 Beiträge
 
Delphi 10.4 Sydney
 
#17

AW: limiting number of instances in Windows terminal server

  Alt 5. Jun 2019, 09:52
Hello,
use a GUID as (global) Mutex-Name with _1, _2 and so on.

if _1 is used, use _2.
if _x is used, you have your maximum instances ...

quick&dirty


or just said: use JEDI JvAppInst.pas
hey use some form of hidden window for each instance
Heiko

Geändert von hoika ( 5. Jun 2019 um 09:56 Uhr)
  Mit Zitat antworten Zitat
mjustin

Registriert seit: 14. Apr 2008
3.006 Beiträge
 
Delphi 2009 Professional
 
#18

AW: limiting number of instances in Windows terminal server

  Alt 5. Jun 2019, 10:00
Yes, reading the number of processes running as user X is another possible approach. Unfortunately I don't know how to read the user a process runs as, even less when TS is involved.
It is easy to count the instances running in the current session. Example in .Net:

Code:
private static int CountApplicationInstances()
    {
        var currentProcess = Process.GetCurrentProcess();
        var processes = Process.GetProcessesByName(currentProcess.ProcessName);

        // test if there's another process running in current session.
        var intTotalRunningInCurrentSession = processes.Count(prc => prc.SessionId == currentProcess.SessionId);

        return intTotalRunningInCurrentSession;
    }
(based on https://stackoverflow.com/a/36210660/80901)
Michael Justin
habarisoft.com
  Mit Zitat antworten Zitat
imadam

Registriert seit: 4. Jun 2019
12 Beiträge
 
#19

AW: limiting number of instances in Windows terminal server

  Alt 5. Jun 2019, 10:13
Did you try TJvAppInstances already? It is designed for limiting app instances, and it allows to set the maximum number of simultaneous instances using the property MaxInstances. I am not soure however if it is also suited for a TS.
We tested this: http://www.delphidabbler.com/articles?article=13&part=4 and this works on Windows 10 limiting to 1 instance. But it doesn't work on TS. It actually on TS allows only one user to run only once instance. Whom ever get first to it
  Mit Zitat antworten Zitat
mjustin

Registriert seit: 14. Apr 2008
3.006 Beiträge
 
Delphi 2009 Professional
 
#20

AW: limiting number of instances in Windows terminal server

  Alt 5. Jun 2019, 10:20
Did you try TJvAppInstances already? It is designed for limiting app instances, and it allows to set the maximum number of simultaneous instances using the property MaxInstances. I am not soure however if it is also suited for a TS.
We tested this: http://www.delphidabbler.com/articles?article=13&part=4 and this works on Windows 10 limiting to 1 instance. But it doesn't work on TS. It actually on TS allows only one user to run only once instance. Whom ever get first to it
Ok, the code on (http://www.delphidabbler.com/articles?article=13) does not use the JVCL TJvAppInstances, but good to know

I also posted another suggestion (see #18)
Michael Justin
habarisoft.com
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 2 von 3     12 3      

 

Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 14:40 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz