mutex - VB6: Single-instance application across all user sessions -
i have application needs single-instance app across user sessions on windows pc. research far has centered around using mutex accomplish this, having issue not sure issue, best-practice question believe.
here's code first of all:
private const appver = "global\uniquename" ' not using name unique public sub main() dim mutexvalue long mutexvalue = createmutex(byval 0&, 1, appver) if (err.lastdllerror = error_already_exists) savetitle$ = app.title app.title = "... duplicate instance." msgbox "a duplicate instance of program exists." closehandle mutexvalue exit sub end if ' else keep on truckin'
now, based on this article believe understand passing null pointer createmutex function above i'm assigning whatever security descriptor associated logged in user.
if means think (i may need more guidance here) tells me other users log in not able "see" mutex created under original user's session, nor able create mutex same name.
now, emperical evidence seems up. used message box pop "lastdllerror" receiving, , when user attempted launch application (while running under user account) receive error_access_denied code. ok testing against along error_already_exists code , exiting on either/or. however, feels sort of hackish , i'm wondering if can suggest alternative. "right" thing seems to pass proper pointer createmutex function such user has proper permissions view existing mutexes (mutices?), i'm not sure possible without logged in user being admin (which unacceptible). assistance/guidance appreciated. in advance!
i looking similar solution in vb6 late last year. @ time unable find examples of vb6 apps communicating across user boundary, had write own.
see: interprocess communication via semaphores
you can use class create , check global semaphore tell if app running under user. didn't @ mutex apis usage similar. getsecuritydescriptor function you'll want transpose if you've got mutex code written.
Comments
Post a Comment