![]() |
Service auf Manuell setzen?
Also ich hab jetzt schon nen Weilchen gesucht hab aber noch nichts gefunden was mit einen Service auf Manuell setzen kann ... Hat da jemand was?
|
Re: Service auf Manuell setzen?
Hi,
Du brauchst dazu die ChangeServiceConfig API + SERVICE_DEMAND_START. Habe ein Beispiel in der MSDN gefunden. Brauchst es nur noch nach Delphi zu übersetzen und evtl. ein wenig abzuändern... 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.
Code:
#include <windows.h>
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); } |
Re: Service auf Manuell setzen?
Du kannst das auch über die Registry machen. Dafür musst du einfach beim gewünschten dienst nen Wert ersetzen, ich Schau mal nach, wo das genau ist, und mit was man dass ersetzen muss.
Werd aber erst morgen dazu kommen, musst alo noch etwas geduld haben |
Re: Service auf Manuell setzen?
Hallo,
ich hab gerade mal nachgesehen: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Servic es unter dem Wert "Start" des diensteentsprechenden Schlüssels: 2 - automatisch 3 - manuell 4 - deaktiviert Unter "DisplayName" ist der Name des Dienstes verzeichnet. Gruß Pascal |
Re: Service auf Manuell setzen?
Hi,
[cl="Service"]Die Suche[/cl], kann Wunder helfen: ![]() Das nächste mal erst Suchen und dann fragen, okay? ;) Chris |
Alle Zeitangaben in WEZ +1. Es ist jetzt 17:00 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz