Advertisement
Guest User

Untitled

a guest
Apr 18th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 33.76 KB | None | 0 0
  1. 'ident simple coders
  2.  
  3. Imports Kai.Classes.Processes.Structures
  4. Imports Kai.Classes.Services.Structures
  5.  
  6. Namespace Classes
  7.     Friend Class NativeMethods
  8.         ''' <summary>
  9.         '''     Retrieves information about the specified process.
  10.         ''' </summary>
  11.         ''' <param name="processHandle">
  12.         '''     A handle to the process for which information is to be retrieved.
  13.         ''' </param>
  14.         ''' <param name="processInformationClass">
  15.         '''     The type of process information to be retrieved. This parameter can be one of the following values from the
  16.         '''     PROCESSINFOCLASS enumeration.
  17.         ''' </param>
  18.         ''' <param name="processInformation">
  19.         '''     A pointer to a buffer supplied by the calling application into which the function writes the requested information.
  20.         '''     The size of the information written varies depending on the data type of the ProcessInformationClass parameter:
  21.         ''' </param>
  22.         ''' <param name="processInformationLength">
  23.         '''     The size of the buffer pointed to by the ProcessInformation parameter, in bytes.
  24.         ''' </param>
  25.         ''' <param name="returnLength">
  26.         '''     A pointer to a variable in which the function returns the size of the requested information. If the function was successful,
  27.         '''     this is the size of the information written to the buffer pointed to by the ProcessInformation parameter,
  28.         '''     but if the buffer was too small, this is the minimum size of buffer needed to receive the information successfully.
  29.         ''' </param>
  30.         ''' <returns>
  31.         '''     The function returns an NTSTATUS success or error code.
  32.         '''
  33.         '''     The forms and significance of NTSTATUS error codes are listed in the Ntstatus.h header file available in the DDK, and are
  34.         '''     described in the DDK documentation under Kernel-Mode Driver Architecture / Design Guide / Driver Programming Techniques /
  35.         '''     Logging Errors.
  36.         ''' </returns>
  37.         <DllImport("ntdll.dll")>
  38.         Friend Shared Function NtQueryInformationProcess(processHandle As IntPtr,
  39.                                                            processInformationClass As Integer,
  40.                                                           ByRef processInformation As ProcessBasicInformation,
  41.                                                            processInformationLength As IntPtr,
  42.                                                           ByRef returnLength As Integer) As IntPtr
  43.         End Function
  44.  
  45.         ''' <summary>
  46.         '''
  47.         ''' </summary>
  48.         ''' <returns></returns>
  49.         <DllImport("Kernel32.dll", SetLastError:=True)>
  50.         Friend Shared Function GetConsoleWindow() As IntPtr
  51.         End Function
  52.  
  53.         ''' <summary>
  54.         '''     The ConvertSidToStringSid function converts a security identifier (SID) to a string format suitable for
  55.         '''     display, storage, or transmission.
  56.         ''' </summary>
  57.         ''' <param name="sid">
  58.         '''     A pointer to the SID structure to be converted.
  59.         ''' </param>
  60.         ''' <param name="StringSid">
  61.         '''     A pointer to a variable that receives a pointer to a null-terminated SID string.
  62.         '''     To free the returned buffer, call the LocalFree function.
  63.         ''' </param>
  64.         ''' <returns>
  65.         '''     If the function succeeds, the return value is nonzero.
  66.         ''' </returns>
  67.         ''' <remarks>
  68.         '''     See https://msdn.microsoft.com/en-us/library/windows/desktop/aa376399(v=vs.85).aspx
  69.         ''' </remarks>
  70.         <DllImport("advapi32.dll", SetLastError:=True)>
  71.         Friend Shared Function ConvertSidToStringSid(sid As IntPtr,
  72.                                                      ByRef stringSid As String) As IntPtr
  73.         End Function
  74.  
  75.         ''' <summary>
  76.         '''     Retrieves a pseudo handle for the current process.
  77.         ''' </summary>
  78.         ''' <returns>
  79.         '''     The return value is a pseudo handle to the current process.
  80.         ''' </returns>
  81.         ''' <remarks>
  82.         '''     A pseudo handle is a special constant, currently (HANDLE)-1, that is interpreted as the current process handle.
  83.         '''     For compatibility with future operating systems, it is best to call GetCurrentProcess instead of hard-coding this constant value.
  84.         '''     The calling process can use a pseudo handle to specify its own process whenever a process handle is required.
  85.         '''     Pseudo handles are not inherited by child processes.
  86.         '''    
  87.         '''     See https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-getcurrentprocess
  88.         ''' </remarks>
  89.         <DllImport("kernel32", SetLastError:=True)>
  90.         Friend Shared Function GetCurrentProcess() As IntPtr
  91.         End Function
  92.  
  93.         ''' <summary>
  94.         '''     The GetTokenInformation function retrieves a specified type of information about an access token.
  95.         '''     The calling process must have appropriate access rights to obtain the information.
  96.         ''' </summary>
  97.         ''' <param name="TokenHandle">
  98.         '''     A handle to an access token from which information is retrieved. If TokenInformationClass specifies TokenSource,
  99.         '''     the handle must have TOKEN_QUERY_SOURCE access. For all other TokenInformationClass values, the handle must have
  100.         '''     TOKEN_QUERY access.
  101.         ''' </param>
  102.         ''' <param name="tokenInformationClass">
  103.         '''     A pointer to a buffer the function fills with the requested information. The structure put into this buffer depends
  104.         '''     upon the type of information specified by the TokenInformationClass parameter.
  105.         ''' </param>
  106.         ''' <param name="tokenInformation">
  107.         '''     Specifies the size, in bytes, of the buffer pointed to by the TokenInformation parameter. If TokenInformation is NULL,
  108.         '''     this parameter must be zero.
  109.         ''' </param>
  110.         ''' <param name="tokenInformationLength">
  111.         '''     Specifies the size, in bytes, of the buffer pointed to by the TokenInformation parameter.
  112.         '''     If TokenInformation is NULL, this parameter must be zero.
  113.         ''' </param>
  114.         ''' <param name="returnLength">
  115.         '''     A pointer to a variable that receives the number of bytes needed for the buffer pointed to by the TokenInformation parameter.
  116.         '''     If this value is larger than the value specified in the TokenInformationLength parameter, the function fails and
  117.         '''     stores no data in the buffer.
  118.         ''' </param>
  119.         ''' <returns>
  120.         '''     If the function succeeds, the return value is nonzero.
  121.         ''' </returns>
  122.         ''' <remarks>
  123.         '''     See https://docs.microsoft.com/en-us/windows/desktop/api/securitybaseapi/nf-securitybaseapi-gettokeninformation
  124.         ''' </remarks>
  125.         <DllImport("advapi32.dll", SetLastError:=True)>
  126.         Friend Shared Function GetTokenInformation(tokenHandle As IntPtr,
  127.                                                     tokenInformationClass As TokenInformationClass.TokenInformation,
  128.                                                     tokenInformation As IntPtr,
  129.                                                     tokenInformationLength As IntPtr,
  130.                                                    ByRef returnLength As IntPtr) As IntPtr
  131.         End Function
  132.  
  133.         ''' <summary>
  134.         '''     Retrieves the full name of the executable image for the specified process.
  135.         ''' </summary>
  136.         ''' <param name="hProcess">
  137.         '''     A handle to the process. This handle must be created with the PROCESS_QUERY_INFORMATION or PROCESS_QUERY_LIMITED_INFORMATION access right.
  138.         ''' </param>
  139.         ''' <param name="dwFlags">
  140.         '''      This parameter can be one of the following values.
  141.         ''' </param>
  142.         ''' <param name="lpExeName">
  143.         '''         The path to the executable image. If the function succeeds, this string is null-terminated.
  144.         ''' </param>
  145.         ''' <param name="lpdwSize">
  146.         '''     On input, specifies the size of the lpExeName buffer, in characters. On success, receives the number of characters
  147.         '''     written to the buffer, not including the null-terminating character.
  148.         ''' </param>
  149.         ''' <returns>
  150.         '''     If the function succeeds, the return value is nonzero.
  151.         ''' </returns>
  152.         ''' <remarks>
  153.         '''     See https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-queryfullprocessimagenamea
  154.         ''' </remarks>
  155.         <DllImport("kernel32.dll", SetLastError:=True)>
  156.         Friend Shared Function QueryFullProcessImageName(hProcess As IntPtr,
  157.                                                           dwFlags As Integer,
  158.                                                           lpExeName As StringBuilder,
  159.                                                          ByRef lpdwSize As Integer) As Boolean
  160.         End Function
  161.  
  162.         ''' <summary>
  163.         '''     Terminates the specified process and all of its threads.
  164.         ''' </summary>
  165.         ''' <param name="hProcess">
  166.         '''     A handle to the process to be terminated. The handle must have the PROCESS_TERMINATE access right.
  167.         '''     For more information, see Process Security and Access Rights.
  168.         '''     https://msdn.microsoft.com/en-us/library/windows/desktop/ms684880(v=vs.85).aspx
  169.         ''' </param>
  170.         ''' <param name="exitCode">
  171.         '''     The exit code to be used by the process and threads terminated as a result of this call. Use the
  172.         '''     GetExitCodeProcess function to retrieve a process's exit value. Use the GetExitCodeThread function
  173.         '''     to retrieve a thread's exit value.
  174.         ''' </param>
  175.         ''' <returns>
  176.         '''     If the function succeeds, the return value is nonzero.
  177.         ''' </returns>
  178.         ''' <remarks>
  179.         '''     See https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-terminateprocess
  180.         ''' </remarks>
  181.         <DllImport("kernel32.dll", SetLastError:=True, EntryPoint:="TerminateProcess")>
  182.         Friend Shared Function Terminate(<[In]()> hProcess As IntPtr,
  183.                                          <[In]()> exitCode As Integer) As UInteger
  184.         End Function
  185.  
  186.         ''' <summary>
  187.         '''     The OpenProcessToken function opens the access token associated with a process.
  188.         ''' </summary>
  189.         ''' <param name="ProcessHandle">
  190.         '''     A handle to the process whose access token is opened.
  191.         '''     The process must have the PROCESS_QUERY_INFORMATION access permission.
  192.         ''' </param>
  193.         ''' <param name="DesiredAccess">
  194.         '''     Specifies an access mask that specifies the requested types of access to the access token.
  195.         '''     These requested access types are compared with the discretionary access control list (DACL) of the token to
  196.         '''     determine which accesses are granted or denied.
  197.         ''' </param>
  198.         ''' <param name="TokenHandle">
  199.         '''     A pointer to a handle that identifies the newly opened access token when the function returns.
  200.         ''' </param>
  201.         ''' <returns>
  202.         '''     If the function succeeds, the return value is nonzero.
  203.         ''' </returns>
  204.         ''' <remarks>
  205.         '''     See https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-openprocesstoken
  206.         ''' </remarks>
  207.         <DllImport("advapi32.dll", SetLastError:=True)>
  208.         Friend Shared Function OpenProcessToken(processHandle As IntPtr,
  209.                                                 desiredAccess As Integer,
  210.                                                 ByRef tokenHandle As IntPtr) As IntPtr
  211.         End Function
  212.  
  213.         ''' <summary>
  214.         '''     Closes an open object handle.
  215.         ''' </summary>
  216.         ''' <param name="hObject">
  217.         '''     A valid handle to an open object.
  218.         ''' </param>
  219.         ''' <returns>
  220.         '''     If the function succeeds, the return value is nonzero.
  221.         ''' </returns>
  222.         ''' <remarks>
  223.         '''     See https://msdn.microsoft.com/en-us/library/windows/desktop/ms724211(v=vs.85).aspx
  224.         ''' </remarks>
  225.         <DllImport("kernel32.dll", SetLastError:=True)>
  226.         Friend Shared Function CloseHandle(<[In]()> hObject As IntPtr) As <MarshalAs(UnmanagedType.Bool)> Boolean
  227.         End Function
  228.  
  229.         ''' <summary>
  230.         '''     Opens an existing local process object.
  231.         ''' </summary>
  232.         ''' <param name="dwDesiredAccess">
  233.         '''     The access to the process object. This access right is checked against the
  234.         '''     security descriptor for the process. This parameter can be one or more of the process access rights.
  235.         ''' </param>
  236.         ''' <param name="bInheritHandle">
  237.         '''     If this value is TRUE, processes created by this process will inherit the handle.
  238.         '''     Otherwise, the processes do not inherit this handle.
  239.         ''' </param>
  240.         ''' <param name="dwProcessId">
  241.         '''     The identifier of the local process to be opened.
  242.         ''' </param>
  243.         ''' <returns>
  244.         '''     If the function succeeds, the return value is an open handle to the specified process.
  245.         '''     If the function fails, the return value is NULL.
  246.         ''' </returns>
  247.         ''' <remarks>
  248.         '''     See https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-openprocess
  249.         ''' </remarks>
  250.         <DllImport("kernel32.dll", SetLastError:=True)>
  251.         Friend Shared Function OpenProcess(<[In]()> dwDesiredAccess As ProcessSecurityAccessRights.SecurityFlags,
  252.                                            <[In]()> bInheritHandle As Boolean,
  253.                                            <[Out]()> dwProcessId As Integer) As IntPtr
  254.         End Function
  255.  
  256.         ''' <summary>
  257.         '''     Retrieves the termination status of the specified process.
  258.         ''' </summary>
  259.         ''' <param name="hProcess">
  260.         '''     A handle to the process.
  261.         ''' </param>
  262.         ''' <param name="lpExitCode">
  263.         '''     A pointer to a variable to receive the process termination status. For more information, see Remarks.
  264.         ''' </param>
  265.         ''' <returns>
  266.         '''     If the function succeeds, the return value is nonzero.
  267.         ''' </returns>
  268.         ''' <remarks>
  269.         '''     See https://msdn.microsoft.com/en-us/library/windows/desktop/ms683189(v=vs.85).aspx
  270.         ''' </remarks>
  271.         <DllImport("kernel32.dll", SetLastError:=True)>
  272.         Friend Shared Function GetExitCodeProcess(<[In]()> hProcess As IntPtr,
  273.                                                   <[Out]()> ByRef lpExitCode As UInt32) As Boolean
  274.         End Function
  275.  
  276.         ''' <summary>
  277.         '''     Sends a control code to a service.
  278.         ''' </summary>
  279.         ''' <param name="hService">
  280.         '''     A handle to the service. This handle is returned by the OpenService or CreateService function.
  281.         '''     The access rights required for this handle depend on the dwControl code requested.
  282.         ''' </param>
  283.         ''' <param name="dwControl">
  284.         '''     This parameter can be one of the following control codes.
  285.         ''' </param>
  286.         ''' <param name="lpServiceStatus">
  287.         '''     A pointer to a SERVICE_STATUS structure that receives the latest service status information.
  288.         '''     The information returned reflects the most recent status that the service reported to the service control manager.
  289.         ''' </param>
  290.         ''' <returns>
  291.         '''     If the function succeeds, the return value is nonzero.
  292.         ''' </returns>
  293.         ''' <remarks>
  294.         '''     See https://docs.microsoft.com/en-us/windows/desktop/api/winsvc/nf-winsvc-controlservice
  295.         ''' </remarks>
  296.         <DllImport("advapi32.dll", SetLastError:=True)>
  297.         Friend Shared Function ControlService(hService As IntPtr,
  298.                                               dwControl As ServiceControlManager.ServiceControlManagerType,
  299.                                               ByRef lpServiceStatus As ServiceStatusProcess) As Boolean
  300.         End Function
  301.  
  302.         ''' <summary>
  303.         '''     Starts a service.
  304.         ''' </summary>
  305.         ''' <param name="hService">
  306.         '''     A handle to the service. This handle is returned by the OpenService or CreateService function,
  307.         '''     and it must have the SERVICE_START access right. For more information, see Service Security and Access Rights.
  308.         ''' </param>
  309.         ''' <param name="dwNumServiceArgs">
  310.         '''     The number of strings in the lpServiceArgVectors array. If lpServiceArgVectors is NULL, this parameter can be zero.
  311.         ''' </param>
  312.         ''' <param name="lpServiceArgVectors">
  313.         '''     The null-terminated strings to be passed to the ServiceMain function for the service as arguments. If there are no arguments, this parameter can be NULL.
  314.         '''     Otherwise, the first argument (lpServiceArgVectors[0]) is the name of the service, followed by any additional arguments (lpServiceArgVectors[1] through
  315.         '''     lpServiceArgVectors[dwNumServiceArgs-1]).
  316.         ''' </param>
  317.         ''' <returns>
  318.         '''     If the function succeeds, the return value is nonzero.
  319.         ''' </returns>
  320.         ''' <remarks>
  321.         '''     See https://docs.microsoft.com/en-us/windows/desktop/api/winsvc/nf-winsvc-startservicea
  322.         ''' </remarks>
  323.         <DllImport("advapi32", SetLastError:=True)>
  324.         Friend Shared Function StartService(hService As IntPtr,
  325.                                             dwNumServiceArgs As Integer,
  326.                                             lpServiceArgVectors() As String) As <MarshalAs(UnmanagedType.Bool)> Boolean
  327.         End Function
  328.  
  329.         ''' <summary>
  330.         '''     Marks the specified service for deletion from the service control manager database.
  331.         ''' </summary>
  332.         ''' <param name="hService">
  333.         '''     A handle to the service. This handle is returned by the OpenService or CreateService function,
  334.         '''     and it must have the DELETE access right. For more information, see Service Security and Access Rights.
  335.         ''' </param>
  336.         ''' <returns>
  337.         '''     If the function succeeds, the return value is nonzero.
  338.         ''' </returns>
  339.         ''' <remarks>
  340.         '''     See https://docs.microsoft.com/en-us/windows/desktop/api/winsvc/nf-winsvc-deleteservice
  341.         ''' </remarks>
  342.         <DllImport("advapi32.dll", SetLastError:=True)>
  343.         Friend Shared Function DeleteService(hService As IntPtr) As <MarshalAs(UnmanagedType.Bool)> Boolean
  344.         End Function
  345.  
  346.         ''' <summary>
  347.         '''     Opens an existing service.
  348.         ''' </summary>
  349.         ''' <param name="hScManager">
  350.         '''     A handle to the service control manager database. The OpenSCManager function returns this handle. For more information, see Service Security
  351.         '''     and Access Rights.
  352.         ''' </param>
  353.         ''' <param name="lpServiceName">
  354.         '''     The name of the service to be opened. This is the name specified by the lpServiceName parameter of
  355.         '''     the CreateService function when the service object was created, not the service display name that is shown by user interface
  356.         '''     applications to identify the service.
  357.         ''' </param>
  358.         ''' <param name="dwDesiredAccess">
  359.         '''     The access to the service.
  360.         ''' </param>
  361.         ''' <returns>
  362.         '''     If the function succeeds, the return value is a handle to the service.
  363.         ''' </returns>
  364.         ''' <remarks>
  365.         '''     See https://docs.microsoft.com/en-us/windows/desktop/api/winsvc/nf-winsvc-openservicea
  366.         ''' </remarks>
  367.         <DllImport("advapi32.dll", SetLastError:=True, CharSet:=CharSet.Auto)>
  368.         Friend Shared Function OpenService(hScManager As IntPtr,
  369.                                            lpServiceName As String,
  370.                                            dwDesiredAccess As Int32) As IntPtr
  371.         End Function
  372.  
  373.         ''' <summary>
  374.         '''     Retrieves the calling thread's last-error code value. The last-error code is maintained on
  375.         '''     a per-thread basis. Multiple threads do not overwrite each others last-error code.
  376.         ''' </summary>
  377.         ''' <returns>
  378.         '''     The return value is the calling thread's last-error code.
  379.         ''' </returns>
  380.         ''' <remarks>
  381.         '''     See https://msdn.microsoft.com/en-us/library/windows/desktop/ms679360(v=vs.85).aspx
  382.         ''' </remarks>
  383.         <DllImport("kernel32.dll")>
  384.         Friend Shared Function GetLastError() As Integer
  385.         End Function
  386.  
  387.         ''' <summary>
  388.         '''     Closes a handle to a service control manager or service object.
  389.         ''' </summary>
  390.         ''' <param name="hScObject">
  391.         '''     A handle to the service control manager object or the service object to close. Handles to service control manager objects are
  392.         '''     returned by the OpenSCManager function, and handles to service objects are returned by either the OpenService or CreateService
  393.         '''     function.
  394.         ''' </param>
  395.         ''' <returns>
  396.         '''     If the function succeeds, the return value is nonzero.
  397.         ''' </returns>
  398.         ''' <remarks>
  399.         '''     See https://docs.microsoft.com/en-us/windows/desktop/api/winsvc/nf-winsvc-closeservicehandle
  400.         ''' </remarks>
  401.         <DllImport("advapi32.dll", SetLastError:=True)>
  402.         Friend Shared Function CloseServiceHandle(hScObject As IntPtr) As Boolean
  403.         End Function
  404.  
  405.         ''' <summary>
  406.         '''     Establishes a connection to the service control manager on the specified computer and opens the specified service control manager database.
  407.         ''' </summary>
  408.         ''' <param name="lpMachineName">
  409.         '''     The name of the target computer. If the pointer is NULL or points to an empty string, the function connects to the service control
  410.         '''     manager on the local computer.
  411.         ''' </param>
  412.         ''' <param name="lpDatabaseName">
  413.         '''     The name of the service control manager database. This parameter should be set to SERVICES_ACTIVE_DATABASE. If it is NULL, the
  414.         '''     SERVICES_ACTIVE_DATABASE database is opened by default.
  415.         ''' </param>
  416.         ''' <param name="dwDesiredAccess">
  417.         '''     The access to the service control manager. For a list of access rights, see Service Security and Access Rights.
  418.         ''' </param>
  419.         ''' <returns>
  420.         '''     If the function succeeds, the return value is a handle to the specified service control manager database.
  421.         ''' </returns>
  422.         ''' <remarks>
  423.         '''     See https://docs.microsoft.com/en-us/windows/desktop/api/winsvc/nf-winsvc-openscmanagera
  424.         ''' </remarks>
  425.         <DllImport("advapi32.dll", CharSet:=CharSet.Auto, SetLastError:=True)>
  426.         Friend Shared Function OpenSCManager(lpMachineName As String,
  427.                                              lpDatabaseName As String,
  428.                                              dwDesiredAccess As Int32) As IntPtr
  429.         End Function
  430.  
  431.         ''' <summary>
  432.         '''     Creates a service object and adds it to the specified service control manager database.
  433.         ''' </summary>
  434.         ''' <param name="hScManager">
  435.         '''     A handle to the service control manager database. This handle is returned by the OpenSCManager function and must have the
  436.         '''     SC_MANAGER_CREATE_SERVICE access right.
  437.         ''' </param>
  438.         ''' <param name="lpServiceName">
  439.         '''     The name of the service to install. The maximum string length is 256 characters. The service control manager database preserves
  440.         '''     the case of the characters, but service name comparisons are always case insensitive. Forward-slash (/) and backslash () are
  441.         '''     not valid service name characters.
  442.         ''' </param>
  443.         ''' <param name="lpDisplayName">
  444.         '''     The display name to be used by user interface programs to identify the service. This string has a maximum length of 256 characters.
  445.         '''     The name is case-preserved in the service control manager. Display name comparisons are always case-insensitive.
  446.         ''' </param>
  447.         ''' <param name="dwDesiredAccess">
  448.         '''     The access to the service. Before granting the requested access, the system checks the access token of the calling process. For a list
  449.         '''     of values, see Service Security and Access Rights.
  450.         ''' </param>
  451.         ''' <param name="dwServiceType">
  452.         '''     The service type. This parameter can be one of the following values.
  453.         ''' </param>
  454.         ''' <param name="dwStartType">
  455.         '''     The service start options. This parameter can be one of the following values.
  456.         ''' </param>
  457.         ''' <param name="dwErrorControl">
  458.         '''     The severity of the error, and action taken, if this service fails to start. This parameter can be one of the following values.
  459.         ''' </param>
  460.         ''' <param name="lpBinaryPathName">
  461.         '''     The fully qualified path to the service binary file. If the path contains a space, it must be quoted so that it is correctly interpreted.
  462.         ''' </param>
  463.         ''' <param name="lpLoadOrderGroup">
  464.         '''     The names of the load ordering group of which this service is a member. Specify NULL or an empty string if the service does not belong to a group.
  465.         ''' </param>
  466.         ''' <param name="lpdwTagId">
  467.         '''     A pointer to a variable that receives a tag value that is unique in the group specified in the lpLoadOrderGroup parameter.
  468.         '''     Specify NULL if you are not changing the existing tag.
  469.         ''' </param>
  470.         ''' <param name="lpDependencies">
  471.         '''     A pointer to a double null-terminated array of null-separated names of services or load ordering groups that the system must start before
  472.         '''     this service. Specify NULL or an empty string if the service has no dependencies.
  473.         ''' </param>
  474.         ''' <param name="lpServiceStartName">
  475.         '''     The name of the account under which the service should run. If the service type is SERVICE_WIN32_OWN_PROCESS, use an account name in the
  476.         '''     form DomainName UserName.
  477.         ''' </param>
  478.         ''' <param name="lpPassword">
  479.         '''     The password to the account name specified by the lpServiceStartName parameter.
  480.         ''' </param>
  481.         ''' <returns>
  482.         '''     If the function succeeds, the return value is a handle to the service.
  483.         ''' </returns>
  484.         ''' <remarks>
  485.         '''     See https://docs.microsoft.com/en-us/windows/desktop/api/winsvc/nf-winsvc-createservicea
  486.         ''' </remarks>
  487.         <DllImport("advapi32.dll", SetLastError:=True, CharSet:=CharSet.Auto)>
  488.         Friend Shared Function CreateService(hScManager As IntPtr, lpServiceName As String,
  489.                                              lpDisplayName As String, dwDesiredAccess As Int32, dwServiceType As Int32,
  490.                                              dwStartType As Integer, dwErrorControl As Int32, lpBinaryPathName As String,
  491.                                              lpLoadOrderGroup As String, lpdwTagId As Int32, lpDependencies As String,
  492.                                              lpServiceStartName As String, lpPassword As String) As IntPtr
  493.         End Function
  494.  
  495.         ''' <summary>
  496.         '''     Enumerates services in the specified service control manager database. The name and status of each service are provided,
  497.         '''     along with additional data based on the specified information level.
  498.         ''' </summary>
  499.         ''' <param name="hScManager">
  500.         '''     A handle to the service control manager database. This handle is returned by the OpenSCManager function, and must have the SC_MANAGER_ENUMERATE_SERVICE access right.
  501.         '''     For more information, see Service Security and Access Rights.
  502.         ''' </param>
  503.         ''' <param name="infoLevel">
  504.         '''     The service attributes that are to be returned. Use SC_ENUM_PROCESS_INFO to retrieve the name and service status information for
  505.         '''     each service in the database.
  506.         ''' </param>
  507.         ''' <param name="dwServiceType">
  508.         '''     The type of services to be enumerated. This parameter can be one or more of the following values.
  509.         ''' </param>
  510.         ''' <param name="dwServiceState">
  511.         '''     The state of the services to be enumerated. This parameter can be one of the following values.
  512.         ''' </param>
  513.         ''' <param name="lpServices">
  514.         '''     A pointer to the buffer that receives the status information. The format of this data depends on the value of the InfoLevel parameter.
  515.         ''' </param>
  516.         ''' <param name="cbBufSize">
  517.         '''     The size of the buffer pointed to by the lpServices parameter, in bytes.
  518.         ''' </param>
  519.         ''' <param name="pcbBytesNeeded">
  520.         '''     A pointer to a variable that receives the number of bytes needed to return the remaining service entries, if the buffer is too small.
  521.         ''' </param>
  522.         ''' <param name="lpServicesReturned">
  523.         '''     A pointer to a variable that receives the number of service entries returned.
  524.         ''' </param>
  525.         ''' <param name="lpResumeHandle">
  526.         '''     A pointer to a variable that, on input, specifies the starting point of enumeration. You must set this value to zero the first time the
  527.         '''     EnumServicesStatusEx function is called.
  528.         ''' </param>
  529.         ''' <param name="pszGroupName">
  530.         '''     The load-order group name. If this parameter is a string, the only services enumerated are those that belong to the group that has the name
  531.         '''     specified by the string.
  532.         ''' </param>
  533.         ''' <returns>
  534.         '''     If the function succeeds, the return value is nonzero.
  535.         ''' </returns>
  536.         ''' <remarks>
  537.         '''  See https://docs.microsoft.com/en-us/windows/desktop/api/winsvc/nf-winsvc-enumservicesstatusexa
  538.         ''' </remarks>
  539.         <DllImport("advapi32.dll", SetLastError:=True, CharSet:=CharSet.Auto)>
  540.         Friend Shared Function EnumServicesStatusEx(hScManager As IntPtr, infoLevel As Integer,
  541.                                                       dwServiceType As Integer, dwServiceState As Integer,
  542.                                                       lpServices As IntPtr, cbBufSize As UInt32,
  543.                                                      ByRef pcbBytesNeeded As UInteger, ByRef lpServicesReturned As UInteger,
  544.                                                      ByRef lpResumeHandle As UInteger, pszGroupName As String) As IntPtr
  545.         End Function
  546.  
  547.         ''' <summary>
  548.         '''     Generates simple tones on the speaker. The function is synchronous; it performs an alertable wait and does not return control to its
  549.         '''     caller until the sound finishes.
  550.         ''' </summary>
  551.         ''' <param name="dwFreq">
  552.         '''     The frequency of the sound, in hertz. This parameter must be in the range 37 through 32,767 (0x25 through 0x7FFF).
  553.         ''' </param>
  554.         ''' <param name="dwDuration">
  555.         '''     The duration of the sound, in milliseconds.
  556.         ''' </param>
  557.         ''' <returns>
  558.         '''     If the function succeeds, the return value is nonzero.
  559.         ''' </returns>
  560.         ''' <remarks>
  561.         '''     See
  562.         ''' </remarks>
  563.         <DllImport("kernel32.dll", SetLastError:=True)>
  564.         Friend Shared Function Beep(dwFreq As UInteger, dwDuration As UInteger) As Boolean
  565.         End Function
  566.  
  567.         ''' <summary>
  568.         '''     Frees the specified local memory object and invalidates its handle.
  569.         ''' </summary>
  570.         ''' <param name="hMem">
  571.         '''     A handle to the local memory object. This handle is returned by either the LocalAlloc or LocalReAlloc function.
  572.         '''     It is not safe to free memory allocated with GlobalAlloc.
  573.         ''' </param>
  574.         ''' <returns>
  575.         '''     If the function fails, the return value is equal to a handle to the local memory object. To get extended error information, call GetLastError.
  576.         ''' </returns>
  577.         ''' <remarks>
  578.         '''     See https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-localfree
  579.         ''' </remarks>
  580.         <DllImport("kernel32.dll", SetLastError:=True)>
  581.         Friend Shared Function LocalFree(ByVal hMem As IntPtr) As IntPtr
  582.         End Function
  583.  
  584.         ''' <summary>
  585.         '''
  586.         ''' </summary>
  587.         ''' <param name="dwFlags"></param>
  588.         ''' <param name="lpSource"></param>
  589.         ''' <param name="dwMessageId"></param>
  590.         ''' <param name="dwLanguageId"></param>
  591.         ''' <param name="lpBuffer"></param>
  592.         ''' <param name="nSize"></param>
  593.         ''' <param name="Arguments"></param>
  594.         ''' <returns></returns>
  595.         <DllImport("kernel32.dll", SetLastError:=True)>
  596.         Friend Shared Function FormatMessage(dwFlags As FormatMessageFlags,
  597.                                              lpSource As IntPtr,
  598.                                              dwMessageId As UInteger,
  599.                                              dwLanguageId As UInteger,
  600.                                              ByRef lpBuffer As IntPtr,
  601.                                              nSize As UInteger,
  602.                                              Arguments As IntPtr) As IntPtr
  603.         End Function
  604.     End Class
  605.  
  606. End Namespace
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement