473,320 Members | 1,900 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

OpenMutex fails with ERROR_ACCESS_DENIED

Accepting the fact that .NET 1.x is lacking support for named events, and
windows security manipulation, we end up using interop and the platform SDK,
and functions like CreateMutex and OpenMutex. And it's with OpenMutex that
I'm having a problem.

In summary: I'm creating a mutex and then trying to 'open' it. I always get
ERROR_ACCESS_DENIED which seems odd as the same process just created it
moments before.

This example is actually a much simplified example of my production
suituation where I'm using named events as well (which .NET doesn't support).

Incidentally if I use the managed .NET new Mutex() to create the mutex then
open it with OpenMutex then I have the same problem. But if I use the Win32
API CreateMutex, and then managed .NET's new Mutex() to open the existing
named mutex then I don't have a problem... so the problem surely lies with
OpenMutex, ...I would think.

I've also looked at creating Security Descriptors, which scare the living
daylights out of me, but if I understand it correctly, by passing 'Nothing'
into The CreateMutex() Security Decsriptor parameter I'm telling it to use
the default descriptor which should be fine for the purposes of multiple
Windows VB App's being run on the same machine by the same user, and in the
case of our test case below should certainly be fine given that it's even the
same process thats asking for SYNCHRONIZE access.

I have a complete chunk of sample code you should be able to paste into a
newly created blank form VB.NET project, to test. The code fire's on the form
load so just run it to reproduce the problem. I anxiously await your reply.

'CreateMutex
<System.Runtime.InteropServices.DllImport("Kernel3 2",
SetLastError:=True, _
CharSet:=System.Runtime.InteropServices.CharSet.Au to)> _
Public Shared Function CreateMutex( _
ByRef lpEventAttributes As IntPtr, _
ByVal bInitialOwner As Boolean, ByVal lpName As String) As
IntPtr
End Function

'OpenMutex
<System.Runtime.InteropServices.DllImport("Kernel3 2",
SetLastError:=True, _
CharSet:=System.Runtime.InteropServices.CharSet.Au to)> _
Public Shared Function OpenMutex( _
ByRef dwDesiredAccess As Integer, ByVal bInheritHandle As
Boolean, _
ByVal lpName As String) As IntPtr
End Function

Public Const SYNCHRONIZE = &H100000&
Public Const ERROR_ACCESS_DENIED = 5

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

' create a named mutex using Win32 API
Dim myWin32Mutex As IntPtr
myWin32Mutex = CreateMutex(Nothing, True, "test2_MUTEX")
If myWin32Mutex.Equals(IntPtr.Zero) Then
Throw New Exception("3")
End If

' get a reference to an existing named mutex using Win32 API
Dim tempWin32Mutex As IntPtr = OpenMutex(SYNCHRONIZE, True,
"test2_MUTEX")
If tempWin32Mutex.Equals(IntPtr.Zero) Then
If System.Runtime.InteropServices.Marshal.GetLastWin3 2Error() =
ERROR_ACCESS_DENIED Then
Throw New Exception("4") ' <--- IT DIES HERE
End If
Throw New Exception("5")
End If
Throw New Exception("6")
End Sub
Jul 21 '05 #1
0 2133

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: active | last post by:
Any idea why this fails with an OpenPrinter exited with code : 5 Message is: Access is denied. I have Adminstrative rights Public Structure PRINTER_DEFAULTS Dim pDatatype As Integer 'String ...
0
by: trayguy | last post by:
Accepting the fact that .NET 1.x is lacking support for named events, and windows security manipulation, we end up using interop and the platform SDK, and functions like CreateMutex and OpenMutex....
6
by: kenneth fleckenstein nielsen | last post by:
Hi guru's It runs ok on my developmaschine, and on the test server that i've set up. but fails after installing on the customers server. I made a XML webservice that does these steps: a) access a...
7
by: SevDer | last post by:
Hi I have a class library that needs to download the HTML in a specific page of ours with provided querystring. When I open this URL with any browser, it loads fine. When I do WebRequest from Web...
1
by: comp.lang.php | last post by:
Consider my code: if ($this->isSuccessful && is_file($_FILES)) { // STEP 6: MOVE RESUME TO DIRECTORY $uuid = $this->sfug->getUUID(); if (!$uuid) $this->sfug->setUUID(); $uuid =...
2
by: Richard Hsu | last post by:
// code #include "stdio.h" int status(FILE * f) { printf("ftell:%d, feof:%s\n", ftell(f), feof(f) != 0 ? "true" : "false"); } int case1() { FILE * f = fopen("c:\\blah", "wb+"); int i = 5;
2
by: Anbu | last post by:
Sorry for cross posting the query. But I need a resolution as early as possible. I have developed an application to authenticate the user based on LDAP Search and authentication. The Windows...
12
by: Jim Rodgers | last post by:
I have a big asp file that has an error under certain conditions -- totally repeatable. However, it only fails when I set response.buffer = True at the top. WHen I set it False in order to debug...
2
by: su haiqing | last post by:
Hi All, I am trying to use NetGroupAdd() to create a group on my computer, but it always return ERROR_ACCESS_DENIED. Do you guys know how to resolve the problem? (Windows Xp sp3) ///code...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.