| 12
 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
 46
 47
 48
 49
 50
 51
 52
 53
 
 |  
function MyQueryServiceConfig(hService: IntPtr;
  lpServiceConfig: IntPtr; cbBufSize: DWORD;
  out pcbBytesNeeded: DWORD): BOOL;
function MyOpenSCManager(lpMachineName, lpDatabaseName: string;
  dwDesiredAccess: DWORD): IntPtr;
function MyOpenService(hSCManager: IntPtr; lpServiceName: string;
  dwDesiredAccess: DWORD): IntPtr;
 
implementation
uses Borland.Vcl.WinSvc,
     system.runtime.InteropServices,
     system.security;
{$R *.nfm}
 
[SuppressUnmanagedCodeSecurity, DllImport(advapi32, CharSet = CharSet.Auto, SetLastError = True, EntryPoint = 'QueryServiceConfig')]
function MyQueryServiceConfig; external;
[SuppressUnmanagedCodeSecurity, DllImport(advapi32, CharSet = CharSet.Auto, SetLastError = True, EntryPoint = 'OpenSCManager')]
function MyOpenSCManager; external;
[SuppressUnmanagedCodeSecurity, DllImport(advapi32, CharSet = CharSet.Auto, SetLastError = True, EntryPoint = 'OpenService')]
function MyOpenService; external;
 
function TconfDlg.Execute: Boolean;
var
  newSize:Cardinal;
  config:TQueryServiceConfig;
  conPtr:IntPtr;
  ScH2, SH2: IntPtr;
begin
  ScH2:=MyOpenSCManager('',nil,SC_MANAGER_ALL_ACCESS);
  try
    SH2:=MyOpenService(ScH2,'MySQL',SERVICE_ALL_ACCESS);
    try
      conPtr:=nil;
      MyQueryServiceConfig(SH2,conPtr,0,newsize);
      conPtr:=Marshal.AllocHGlobal(newSize);
      if MyQueryServiceConfig(SH2,conPtr,newSize,newSize) then
      begin
        config:=TQueryServiceConfig(marshal.PtrToStructure(conPtr,typeof(TQueryServiceConfig)));
        if config.dwStartType=SERVICE_DEMAND_START then
          rdModeStart.ItemIndex:=0
        else if config.dwStartType=SERVICE_AUTO_START then
          rdModeStart.ItemIndex:=1;
      end;
    finally
      Marshal.FreeHGlobal(conPtr);
      CloseServiceHandle(SH2);
    end;
  finally
    CloseServiceHandle(ScH2);
  end;
  Result := showModal=mrOK;
end; | 
Partager