Initial commit
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace Lithnet.CredentialProvider.Interop
|
||||
{
|
||||
internal struct LsaHandle : IDisposable
|
||||
{
|
||||
public IntPtr Handle;
|
||||
|
||||
public LsaHandle(IntPtr handle)
|
||||
{
|
||||
this.Handle = handle;
|
||||
}
|
||||
|
||||
public static implicit operator LsaHandle(IntPtr handle) => new LsaHandle(handle);
|
||||
public static implicit operator IntPtr(LsaHandle handle) => handle.Handle;
|
||||
|
||||
public static LsaHandle ConnectUntrusted()
|
||||
{
|
||||
var result = PInvoke.LsaConnectUntrusted(out var handle);
|
||||
|
||||
if (result != 0)
|
||||
{
|
||||
throw new Win32Exception((int)result);
|
||||
}
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
||||
public bool IsValid()
|
||||
{
|
||||
return this.Handle != IntPtr.Zero;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
PInvoke.LsaDeregisterLogonProcess(this.Handle);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user