-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathSafeNativeMethods.cs
46 lines (36 loc) · 2.3 KB
/
SafeNativeMethods.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//------------------------------------------------------------------------------
// <copyright file="SafeNativeMethods.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.ServiceProcess {
using System;
using System.Text;
using System.Security;
using System.Security.Permissions;
using System.Runtime.InteropServices;
using System.Runtime.ConstrainedExecution;
[
ComVisible(false),
SuppressUnmanagedCodeSecurityAttribute()
]
internal static class SafeNativeMethods {
[DllImport(ExternDll.Advapi32, CharSet=System.Runtime.InteropServices.CharSet.Unicode, SetLastError=true)]
public extern static IntPtr OpenSCManager(string machineName, string databaseName, int access);
[
DllImport(ExternDll.Advapi32, CharSet=System.Runtime.InteropServices.CharSet.Unicode, SetLastError=true),
ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)
]
public extern static bool CloseServiceHandle(IntPtr handle);
[DllImport(ExternDll.Advapi32, CharSet=System.Runtime.InteropServices.CharSet.Unicode, SetLastError=false)]
public static extern int LsaClose(IntPtr objectHandle);
[DllImport(ExternDll.Advapi32, SetLastError=false)]
public static extern int LsaFreeMemory(IntPtr ptr);
[DllImport(ExternDll.Advapi32, CharSet=System.Runtime.InteropServices.CharSet.Unicode, SetLastError=false)]
public static extern int LsaNtStatusToWinError(int ntStatus);
[DllImport(ExternDll.Advapi32, CharSet=System.Runtime.InteropServices.CharSet.Unicode, SetLastError=true)]
public static extern bool GetServiceKeyName(IntPtr SCMHandle, string displayName, StringBuilder shortName, ref int shortNameLength);
[DllImport(ExternDll.Advapi32, CharSet=System.Runtime.InteropServices.CharSet.Unicode, SetLastError=true)]
public static extern bool GetServiceDisplayName(IntPtr SCMHandle, string shortName, StringBuilder displayName, ref int displayNameLength);
}
}