Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "Основная";
Текущий архив: 2005.02.27;
Скачать: [xml.tar.bz2];

Вниз

Остановит службу   Найти похожие ветки 

 
dp200 ©   (2005-02-14 09:49) [0]

Остановить, запустить службу понятно
procedure TForm1.Button4Click(Sender: TObject);
var
shell:OleVariant;
begin
shell:=CreateOleObject("Shell.Application");
shell.ServiceStop("SmcService",false);
end;

procedure TForm1.Button5Click(Sender: TObject);
var shell:OleVariant;
begin
shell:=CreateOleObject("Shell.Application");
shell.ServiceStart("SmcService",true);
end;
По как изменить тип запуска (например с авто на отключенно)?


 
Fay ©   (2005-02-14 09:53) [1]

ChangeServiceConfig


 
dp200 ©   (2005-02-14 10:21) [2]

Ничего не выходит


 
Fay ©   (2005-02-14 10:22) [3]

Покажи код.


 
dp200 ©   (2005-02-14 10:25) [4]

procedure TForm1.Button5Click(Sender: TObject);
var shell:OleVariant;
begin
shell:=CreateOleObject("Shell.Application");
shell.ChangeServiceConfig("SmcService",true);
end;


 
Fay ©   (2005-02-14 10:29) [5]

Я не знаю Вашего шаманского способа. Вот пример из Platform SDK.

Changing a Service Configuration
In the following example, a service configuration program uses the ChangeServiceConfig and ChangeServiceConfig2 functions to change the configuration parameters of an installed service. The program first tries to lock the database, to prevent the SCM from starting a service while it is being reconfigured. If it successfully locks the database, the program opens a handle to the service object, modifies its configuration, unlocks the database, and then closes the service object handle. If the program does not successfully in lock the database, it uses the QueryServiceLockStatus function to retrieve information about the lock.

VOID ReconfigureSampleService(BOOL fDisable, LPSTR lpDesc)
{
   SC_LOCK sclLock;
   LPQUERY_SERVICE_LOCK_STATUS lpqslsBuf;
   SERVICE_DESCRIPTION sdBuf;
   DWORD dwBytesNeeded, dwStartType;

   // Need to acquire database lock before reconfiguring.

   sclLock = LockServiceDatabase(schSCManager);

   // If the database cannot be locked, report the details.

   if (sclLock == NULL)
   {
       // Exit if the database is not locked by another process.

       if (GetLastError() != ERROR_SERVICE_DATABASE_LOCKED)
           MyErrorExit("LockServiceDatabase");

       // Allocate a buffer to get details about the lock.

       lpqslsBuf = (LPQUERY_SERVICE_LOCK_STATUS) LocalAlloc(
           LPTR, sizeof(QUERY_SERVICE_LOCK_STATUS)+256);
       if (lpqslsBuf == NULL)
           MyErrorExit("LocalAlloc");

       // Get and print the lock status information.

       if (!QueryServiceLockStatus(
           schSCManager,
           lpqslsBuf,
           sizeof(QUERY_SERVICE_LOCK_STATUS)+256,
           &dwBytesNeeded) )
           MyErrorExit("QueryServiceLockStatus");

       if (lpqslsBuf->fIsLocked)
           printf("Locked by: %s, duration: %d seconds\n",
               lpqslsBuf->lpLockOwner,
               lpqslsBuf->dwLockDuration);
       else
           printf("No longer locked\n");

       LocalFree(lpqslsBuf);
       MyErrorExit("Could not lock database");
   }

   // The database is locked, so it is safe to make changes.

   // Open a handle to the service.

   schService = OpenService(
       schSCManager,           // SCManager database
       "Sample_Srv",           // name of service
       SERVICE_CHANGE_CONFIG); // need CHANGE access
   if (schService == NULL)
       MyErrorExit("OpenService");

   dwStartType = (fDisable) ? SERVICE_DISABLED :
                           SERVICE_DEMAND_START;

   // Make the changes.

   if (! ChangeServiceConfig(
       schService,        // handle of service
       SERVICE_NO_CHANGE, // service type: no change
       dwStartType,       // change service start type
       SERVICE_NO_CHANGE, // error control: no change
       NULL,              // binary path: no change
       NULL,              // load order group: no change
       NULL,              // tag ID: no change
       NULL,              // dependencies: no change
       NULL,              // account name: no change
       NULL,              // password: no change
       NULL) )            // display name: no change
   {
       MyErrorExit("ChangeServiceConfig");
   }
   else
       printf("ChangeServiceConfig SUCCESS\n");

   sdBuf.lpDescription = lpDesc;

   if( !ChangeServiceConfig2(
       schService,                // handle to service
       SERVICE_CONFIG_DESCRIPTION // change: description
       &sdBuf) )                  // value: new description
   {
       MyErrorExit("ChangeServiceConfig2");
   }
   else
       printf("ChangeServiceConfig2 SUCCESS\n");

   // Release the database lock.

   UnlockServiceDatabase(sclLock);

   // Close the handle to the service.

   CloseServiceHandle(schService);
}


 
Fay ©   (2005-02-14 10:30) [6]

И вАщЕ... Не забывайте про MSDN, и солнце будет Вам светить значительно чаще.



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

Форум: "Основная";
Текущий архив: 2005.02.27;
Скачать: [xml.tar.bz2];

Наверх





Память: 0.47 MB
Время: 0.035 c
1-1107787392
Tack
2005-02-07 17:43
2005.02.27
TSpeedButton, WinXP, XPManifest


1-1107977800
Fassssss
2005-02-09 22:36
2005.02.27
Как изменять значание в тексте ComboBox если Style csDropDownList


1-1108440520
HF-Trade
2005-02-15 07:08
2005.02.27
Как в переменной задать перечисляемый тип компонентам


1-1108016916
Apostol
2005-02-10 09:28
2005.02.27
Не распознает запятую в качестве системного разделителя...


1-1108069277
Porecla
2005-02-11 00:01
2005.02.27
Получить параметры из реестра





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский