All,

I have the below code, previously in VB.NET 1.0/2002. It is (as far as I
understand) creating a mutex and then removing ACL/security information.

I get a warning in VB.NET 2.0/2005 stating I should use SafeWaitHandle
rather than Handle.

I have read a few blogs about the benefits of SafeWaitHandle vs Handle, but
am not sure exactly the nature of the change I should be making.
SetSecurityInfo seems to need an IntPtr, so it won't let me pass in a
SafeWaitHandle to it (understandably). I could call
SafeWaitHandle.DangerousGetHandle but it seems dangerous (pun intended).

Can anyone give me some pointers? Note I am keen to solve this specific
problem, but am also interested in the more general issue (since there
seems to be other handle usage in our app) of how to convert Handle usage
to SafeHandle usage.

Public Class NoSecurityMutex

    Private mutex As mutex

    Public Sub New(ByVal initiallyOwned As Boolean, ByVal name As String,
ByRef createdNew As Boolean)
        Me.mutex = New mutex(initiallyOwned, name, createdNew)
        DeleteDefaultDaclForKernelObject(Me.mutex.Handle)
    End Sub

    Public Shared Sub DeleteDefaultDaclForKernelObject(ByVal handle As
IntPtr)
        AdvApi32.SetSecurityInfo(handle, _
            AdvApi32.SE_OBJECT_TYPE.SE_KERNEL_OBJECT, _
            AdvApi32.DACL_SECURITY_INFORMATION, 0, 0, 0, 0)
    End Sub

    <DllImport("Advapi32.dll", CharSet:=CharSet.Auto, EntryPoint:=
"SetSecurityInfo", SetLastError:=True)> _
    Friend Shared Function SetSecurityInfo(ByVal handle As System.IntPtr, _
                                            ByVal ObjectType As
SE_OBJECT_TYPE, _
                                            ByVal SecurityInfo As
System.Int32, _
                                            ByVal psidOwner As
System.Int32, _
                                            ByVal psidGroup As
System.Int32, _
                                            ByVal pDacl As System.Int32, _
                                            ByVal pSacl As System.Int32) As
Int32

        'No implementation
    End Function

Thanks
Matthew Wills @ MLC
Senior Analyst Programmer
(w) 02 9957 8183
(email) [EMAIL PROTECTED]



______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email
______________________________________________________________________

===================================
This list is hosted by DevelopMentor®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

This e-mail is sent by or on behalf of the named sender identified above.
If:

(a) you do not wish to receive any e-mail marketing material from this
person in the future, please forward the contents of this email to
[EMAIL PROTECTED] with the word "unsubscribe" in the
subject box.

(b) you wish to unsubscribe from all central e-mail marketing lists
used by our business, please forward the contents of this e-mail to
[EMAIL PROTECTED] with the message "unsubscribe
from all central e-mail marketing lists" in the subject box.

If you do not forward the contents of this e-mail with your
unsubscription then it may not be able to be implemented.

The information contained in this e-mail communication may be
confidential. You should only read, disclose, re-transmit, copy,
distribute, act in reliance on or commercialise the information if you
are authorised to do so. If you are not the intended recipient of this
e-mail communication, please immediately notify us by e-mail to
[EMAIL PROTECTED], or reply by e-mail direct to the sender and then
destroy any electronic and paper copy of this message. Any views
expressed in this e-mail communication are those of the individual
sender, except where the sender specifically states them to be the views
of a member of the National Australia Bank Group of companies. Any
advice contained in this e-mail has been prepared without taking into
account your objectives, financial situation or needs. Before acting on
any advice in this e-mail, National Australia Bank Limited recommends
that you consider whether it is appropriate for your circumstances. If
this e-mail contains reference to any financial products, the National
recommends you consider the Product Disclosure Statement (PDS) or other
disclosure document before making any decisions regarding any products.
The National Australia Bank Group of companies does not represent,
warrant or guarantee that the integrity of this communication has been
maintained nor that the communication is free of errors, virus or
interference.

===================================
This list is hosted by DevelopMentor®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to