PDA

View Full Version : Application detection with mutex option



NewsArchive
06-19-2010, 01:51 AM
Has anyone gotten application detection with mutex option to work?

I get a correct return when I use the OpenMutexA() API in a Clarion
EXE with MutexACL 20000h but a zero when trying the same mutex in SB.
The application can be detected by filename, but not by mutex.

If it's of any importance the application is running as a service.

OpenMutex( MutexACL, 0, lpMutexName ) is what I'm using in Clarion.

I would prefer to detect using the mutex if someone could point me in
the right direction. Any ideas?

--
Lee White

Enroll Today at http://CWaddons.com

Reports....: http://www.cwaddons.com/products/rpm/
Free Review: http://www.clarionmag.com/cmag/v11/v11n06rpm.html
Faxing.....: http://www.cwaddons.com/products/afe/

NewsArchive
06-21-2010, 01:18 AM
Hi Lee,

> I would prefer to detect using the mutex if someone could point me in
> the right direction. Any ideas?

I have developed and uploaded (with source codes) a small Mutex demo for
you.

www.lindersoft.com/projects/MutexDemo.zip

Start coolapp.exe (compiled from coolapp1.clw and an equivalent to your app)
creates a mutex. Mutex.exe (compiled from mutex.sb7 and an equivalent to
your install) checks for an existing named mutex object and can detect an
active application.

Does this help?

Friedrich

--
Friedrich Linder
Lindersoft
www.lindersoft.com
+1.954.252.3910

SetupBuilder is Windows 7 installation -- "point. click. ship"

-- Official Comodo Code Signing and SSL Certificate Partner

NewsArchive
06-21-2010, 01:18 AM
Friedrich,

> Does this help?

I'll dig into it shortly, thanks.

--
Lee White

Enroll Today at http://CWaddons.com

Reports....: http://www.cwaddons.com/products/rpm/
Free Review: http://www.clarionmag.com/cmag/v11/v11n06rpm.html
Faxing.....: http://www.cwaddons.com/products/afe/

NewsArchive
06-21-2010, 01:19 AM
Friedrich,

> I have developed and uploaded (with source codes) a small Mutex demo for
> you.

Using your example, yes, it finds the mutex you created. But<g>,
changing it to look for the mutex I need to find gives the same
results - not found.

Can I assume, under the covers, SB is using OpenMutex?

If it is I'm stumped since using that in Clarion finds the mutex I'm
looking for but neither SB script finds it. "FaxMan4Svr" is what I'm
looking for.

I just changed the value my Clarion program was looking for to the
mutex your example generated - it finds it - go figure!<g>

If you don't mind I'll get some stuff together later, ZIP it and email
you a link to download. Maybe you can figure out what's going on - I
sure can't... obviously!<g>

--
Lee White

Enroll Today at http://CWaddons.com

Reports....: http://www.cwaddons.com/products/rpm/
Free Review: http://www.clarionmag.com/cmag/v11/v11n06rpm.html
Faxing.....: http://www.cwaddons.com/products/afe/

NewsArchive
06-21-2010, 01:20 AM
Lee,

> Using your example, yes, it finds the mutex you created. But<g>,
> changing it to look for the mutex I need to find gives the same
> results - not found.

I have changed the Mutex to "FaxMan4Svr" (in both the application and the
installer) and it works without any problem on all machines here.

I have uploaded the modified code with the "FaxMan4Svr" mutex.
www.lindersoft.com/projects/FaxMan4Svr.zip

BTW, yes, the installer runtime is using OpenMutex

Friedrich

NewsArchive
06-21-2010, 01:20 AM
Friedrich,

> I have changed the Mutex to "FaxMan4Svr" (in both the application and the
> installer) and it works without any problem on all machines here.

That all works fine... the problem is that it still will not find the
mutex created by FaxMan. My Clarion program finds it but not the SB
script. That's the puzzler!

I can provide the files necessary if you have the time to test them.
If you do just let me know and I'll send you a download link.

> BTW, yes, the installer runtime is using OpenMutex

I figured it was... makes the mystery even more bizarre!<g>

--
Lee White

Enroll Today at http://CWaddons.com

Reports....: http://www.cwaddons.com/products/rpm/
Free Review: http://www.clarionmag.com/cmag/v11/v11n06rpm.html
Faxing.....: http://www.cwaddons.com/products/afe/

NewsArchive
06-21-2010, 01:21 AM
Lee,

Make sure you are using CreateMutex in your program. OpenMutex just opens
an existing named mutex object!

See the coolapp1.clw Clarion source code. That's an equivalent to your
FaxMan. So just use the code from coolapp1.clw in your FaxMan and you are
done ;-)

Friedrich

NewsArchive
06-21-2010, 01:21 AM
Friedrich,

> Make sure you are using CreateMutex in your program.

FaxMan isn't my program<g> but it does create a mutex.

Out of curiosity what ACL are you using with OpenMutex?

In my test CLW I'm using READ_CONTROL 0x00020000L.

--
Lee White

Enroll Today at http://CWaddons.com

Reports....: http://www.cwaddons.com/products/rpm/
Free Review: http://www.clarionmag.com/cmag/v11/v11n06rpm.html
Faxing.....: http://www.cwaddons.com/products/afe/

NewsArchive
06-21-2010, 01:21 AM
Lee,

> FaxMan isn't my program<g> but it does create a mutex.

Aha, okay.

> Out of curiosity what ACL are you using with OpenMutex?
>
> In my test CLW I'm using READ_CONTROL 0x00020000L.

The installer runtime specifies the MUTEX_ALL_ACCESS to request full access
(the recommended way).

Friedrich

NewsArchive
06-21-2010, 01:21 AM
Friedrich,

> The installer runtime specifies the MUTEX_ALL_ACCESS to request full access
> (the recommended way).

Even when all you want to do is verify that the mutex exists? Wouldn't
that just be read?

From MSDN, MUTEX_ALL_ACCESS:
"All possible access rights for a mutex object. Use this right only if
your application requires access beyond that granted by the standard
access rights. Using this access right increases the possibility that
your application must be run by an Administrator."

It's the "beyond that granted by the standard access rights" that
would indicate to me that only READ_CONTROL is actually needed to
verify the existence... or am I reading that incorrectly?

The foreign mutex is not created with sufficient rights for this level
of access. That's the catch-22 with the built-in SB mutex detection -
at least in my case.<g>

I just tested and SYNCHRONIZE also works in my case.

--
Lee White

Enroll Today at http://CWaddons.com

Reports....: http://www.cwaddons.com/products/rpm/
Free Review: http://www.clarionmag.com/cmag/v11/v11n06rpm.html
Faxing.....: http://www.cwaddons.com/products/afe/

NewsArchive
06-21-2010, 01:22 AM
Lee,

See link to the MSDN example I posted <g>.

"The access parameter requests full access to the mutex object, which is
necessary for the handle to be used in any of the wait functions."

But I agree. "SYNCHRONIZE" should be enough for most scenarios. I'll see
if changing the access parameter to SYNCHRONIZE would result in negative
side effects.

Friedrich

NewsArchive
06-21-2010, 01:22 AM
Friedrich,

> See link to the MSDN example I posted <g>.

I had already been there, earlier.<g>

> "The access parameter requests full access to the mutex object, which is
> necessary for the handle to be used in any of the wait functions."

I think the problem I ran into was due to FaxMan not creating the
mutex with a default security descriptor. If I understand correctly
using MUTEX_ALL_ACCESS is requesting all access and failing due to
insufficient rights. All this stuff gives me a headache!<g>

SB easily detects the mutex I create in my ancillary programs but I
don't set any security on them.

> But I agree. "SYNCHRONIZE" should be enough for most scenarios. I'll see
> if changing the access parameter to SYNCHRONIZE would result in negative
> side effects.

Only if it doesn't run the risk of creating its own problems. For my
use an option to specify the access level in the script would more
than suffice. Even if it was simply a "[] Read Only Access" checkbox.

But you already provided a way for me to detect the FaxMan mutex so I
can get back to work. Like I -wanted- to work this weekend!<g>

--
Lee White

Enroll Today at http://CWaddons.com

Reports....: http://www.cwaddons.com/products/rpm/
Free Review: http://www.clarionmag.com/cmag/v11/v11n06rpm.html
Faxing.....: http://www.cwaddons.com/products/afe/

NewsArchive
06-21-2010, 01:25 AM
BTW, it would not make sense to test it here. I can do it, but it would not
help <g>

The correct method is used in the demo I uploaded. The "coolapp1.clw" (an
equivalent to your FaxMan) creates the "FaxMan4Svr" mutex. The installer
checks if that "FaxMan4Svr" mutex exists.

This works fine in the (Clarion) demo, so there must be a problem in your
FaxMan code (IMO).

Friedrich

NewsArchive
06-21-2010, 01:25 AM
Here is an interesting Mutex example:
http://msdn.microsoft.com/en-us/library/ms686931(v=VS.85).aspx

Friedrich

NewsArchive
06-21-2010, 01:25 AM
Friedrich,

> The correct method is used in the demo I uploaded. The "coolapp1.clw" (an
> equivalent to your FaxMan) creates the "FaxMan4Svr" mutex. The installer
> checks if that "FaxMan4Svr" mutex exists.

I've attached the CLW that detects the mutex. As I mentioned earlier,
I don't create this mutex although it does exist. That's the reason I
wanted to send you the files necessary to create the mutex in an
effort to figure out why SB can't see it.

For now I'll just use filename detection.

--
Lee White

Enroll Today at http://CWaddons.com

Reports....: http://www.cwaddons.com/products/rpm/
Free Review: http://www.clarionmag.com/cmag/v11/v11n06rpm.html
Faxing.....: http://www.cwaddons.com/products/afe/

NewsArchive
06-21-2010, 01:26 AM
Lee,

>
> For now I'll just use filename detection.
>

Or use the "Call DLL" function to directly call the OpenMutex Windows API
;-)

Friedrich

NewsArchive
06-21-2010, 01:27 AM
And here is a "Call DLL" demo .sb7 project. The first parameter is set to
READ_CONTROL =
0x00020000L

Friedrich

NewsArchive
06-21-2010, 01:27 AM
Friedrich,

> And here is a "Call DLL" demo .sb7 project. The first parameter is set to
> READ_CONTROL =
> 0x00020000L

THAT works like a charm! Thank you.

--
Lee White

Enroll Today at http://CWaddons.com

Reports....: http://www.cwaddons.com/products/rpm/
Free Review: http://www.clarionmag.com/cmag/v11/v11n06rpm.html
Faxing.....: http://www.cwaddons.com/products/afe/

NewsArchive
06-24-2010, 01:47 AM
Lee,

>> But I agree. "SYNCHRONIZE" should be enough for most scenarios. I'll
>> see if changing the access parameter to SYNCHRONIZE would result in
>> negative side effects.
>
> Only if it doesn't run the risk of creating its own problems. For my
> use an option to specify the access level in the script would more
> than suffice. Even if it was simply a "[] Read Only Access" checkbox.

To be on the safe side <g>, we have added another "Mutex (SYNCHRONIZE)"
option now (see attached screenshot).

Friedrich

NewsArchive
06-24-2010, 01:49 AM
Friedrich,

> To be on the safe side <g>, we have added another "Mutex (SYNCHRONIZE)"
> option now (see attached screenshot).

Excellent! Thank you.

--
Lee White

Enroll Today at http://CWaddons.com

Reports....: http://www.cwaddons.com/products/rpm/
Free Review: http://www.clarionmag.com/cmag/v11/v11n06rpm.html
Faxing.....: http://www.cwaddons.com/products/afe/