Thanks for the responses!
They are all helpful.
I also need to count the apps running on the server if my app is running the program off the server. Is there any way of doing that, since enumwindows only seems to enumerate the apps on the current machine?
Best Regards
Jim
------------------
Jim Seekamp
[This message has been edited by Jim Seekamp (edited April 26, 2001).]
Announcement
Collapse
No announcement yet.
App Copies Open
Collapse
X
-
well, if what you want is the current usage count of a specific program and that program is yours, you could add a memory-mapped file object to the program.
you can use this to limit instances of the program which may be running.
i'd also look at semaphores, as then windows will limit the number of users (albeit by queuing in perpetuity 'extra' requests).
i wrote an article on memory-mapped files for basically speaking, and the code in there - which is public domain - has an example of using a memory-mapped file.
i'll put a couple of brief notes in there and post the code here in the next couple of days.
(unless i find someone has an example already posted in the source code forum).
** update***
posted in source code forum at:
http://www.powerbasic.com/support/pb...ad.php?t=23001
------------------
michael mattias
racine wi usa
[email protected]
[this message has been edited by michael mattias (edited april 26, 2001).]
Leave a comment:
-
-
In 16-bit, you could use the GetModuleUsage() API... there does not seem to be any equivalent 32-bit API.
Borje's suggestion is 'echoed' in MSDN, but I'd rather use EnumWindows(). For those inclined, please check out http://support.microsoft.com/support.../Q167/8/43.ASP
------------------
Lance
PowerBASIC Support
mailto:[email protected][email protected]</A>
Leave a comment:
-
-
Maybe by enumerating all open window and comparing their titles?
Maybe there is a better way, but following also should work:
Code:'¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ ' Example of getting appCount via enumeration of all open windows '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ #COMPILE EXE #INCLUDE "WIN32API.INC" GLOBAL gWhatApp AS STRING, gAppCount AS LONG DECLARE CALLBACK FUNCTION DlgProc() AS LONG DECLARE FUNCTION EnumWindowsProc(BYVAL hWnd AS LONG, BYVAL lParam AS LONG) AS LONG '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ ' Create dialog and controls, etc '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ FUNCTION PBMAIN () AS LONG LOCAL hDlg AS LONG DIALOG NEW 0, "PB appCount..",,, 128, 22, %WS_CAPTION OR %WS_SYSMENU, 0 TO hDlg CONTROL ADD BUTTON, hDlg, 10, "&Get count", 4, 4, 60, 14 CONTROL ADD BUTTON, hDlg, 11, "E&xit", 64, 4, 60, 14 DIALOG SHOW MODAL hDlg CALL DlgProc END FUNCTION '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ ' Main callback '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ CALLBACK FUNCTION DlgProc() AS LONG IF CBMSG = %WM_COMMAND THEN IF CBCTL = 10 THEN gAppCount = 0 gWhatApp = "powerbasic 32-bit dll compiler" '<- start of title to find (change to your liking) EnumWindows CODEPTR(EnumWindowsProc), 0 MSGBOX FORMAT$(gAppCount) & " occurrence(s) of PB/DLL 6 running" ELSEIF CBCTL = 11 THEN DIALOG END CBHNDL END IF END IF END FUNCTION '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ ' Enumerate open windows and compare titles '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ FUNCTION EnumWindowsProc(BYVAL hWnd AS LONG, BYVAL lParam AS LONG) AS LONG LOCAL zTitle AS ASCIIZ * %MAX_PATH GetWindowText hWnd, zTitle, %MAX_PATH '<- get window title IF UCASE$(LEFT$(zTitle, LEN(gWhatApp))) = UCASE$(gWhatApp) THEN INCR gAppCount FUNCTION = 1 '<- return value to contuine with next, return zero to break action END FUNCTION
------------------
Leave a comment:
-
-
App Copies Open
Is there any way to tell in Windows how many copies of an application are open on the machine the program is running on? (server or stand-alone)
Thanks,
Jim
------------------
Jim SeekampTags: None
-
Leave a comment: