473,473 Members | 1,888 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 2149

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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.