Вниз
Скачать: CL | DM;

Тип запуска службы   Найти похожие ветки 

 
Дмитрий Ботвин   (2004-08-13 19:14) [0]

Люди, подскажите в чём ошибка. Есть функция, получающая
структуру типа:

  _QUERY_SERVICE_CONFIGA = record
   dwServiceType: DWORD;
   dwStartType: DWORD;
   dwErrorControl: DWORD;
   lpBinaryPathName: PAnsiChar;
   lpLoadOrderGroup: PAnsiChar;
   dwTagId: DWORD;
   lpDependencies: PAnsiChar;
   lpServiceStartName: PAnsiChar;
   lpDisplayName: PAnsiChar;
 end;

из неё я хочу узнать тип запуска службы. При вызове функции
QueryServiceConfig выдается ошибка. Вот кусок кода:

function GetServiceConfig(ServiceName: String): DWORD;
  var
    SCManager, Service: SC_HANDLE;
    BytesNeeded: DWORD;
    buf: PQueryServiceConfig;
  begin
    buf:=nil;
    TypeStart:=0;
    SCManager := OpenSCManager(PChar(Form1.CompName.Text), nil, GENERIC_READ);
    if SCManager <> 0 then
    try
      Service := OpenService(SCManager, PChar(ServiceName), SERVICE_QUERY_CONFIG);
      if Service <> 0 then
        try
          begin
            QueryServiceConfig(Service, buf, 4096, BytesNeeded);
            if buf<>nil then
              begin
                Result:=buf^.dwStartType;
              end;
          end;
        finally
          CloseServiceHandle(Service);
        end;
      else Result:=0;
     finally
        CloseServiceHandle(SCManager);
     end
    else Result:=0;
  end;


 
VMcL ©   (2004-08-14 01:52) [1]

Память Пушкин будет выделять?

1. Вызываешь QueryServiceConfig(Service, nil, 0, BytesNeeded); Таким образом узнаешь, скока функция хочет памяти.
2. GetMem(buf, BytesNeeded); или buf := AllocMem(BytesNeeded);
3. Потом QueryServiceConfig(Service, buf, BytesNeeded, BytesNeeded);
4. FreeMem(buf);


 
Дмитрий Ботвин   (2004-08-14 09:19) [2]

Спасибо, VMcL!!! Тупанул немного, забыл про выделение памяти.



Страницы: 1 вся ветка

Скачать: CL | DM;



Память: 0.45 MB
Время: 0.026 c
1-1097517111
jj
2004-10-11 21:51
2004.10.24
Понимают ли друг друга api ShowWindow и свойство Visible?


11-1081912814
nsvi
2004-04-14 07:20
2004.10.24
Помогите разобраться с формой


1-1097143505
Unknown user
2004-10-07 14:05
2004.10.24
TMethod


1-1097505154
Relaxxx
2004-10-11 18:32
2004.10.24
Глупый вопрос, но я не могу сделать...как мне установить опции ..


4-1095408289
gs
2004-09-17 12:04
2004.10.24
Данные системы




   Наверх