Archived from groups: microsoft.public.windowsnt.registry (
More info?)
Dave,
Thanks for your reply.
That turned out to be not enough
(but a useful step)
I just found the solution : a call
to ChangeServiceConfig (see program
below), follow by a net stop / net
start.
Also, the serice is apache, which I can
restart in two ways :
apache -n "Apache" -k restart
net stop Apache & net start Apache
Only the second combined with ChangeServiceConfig
does the trick for me.
-- Benoit
"Dave Patrick" <mail@NoSpam.DSPatrick.com> wrote in message news:<#JyW3r5IEHA.2144@TK2MSFTNGP12.phx.gbl>...
> From a command prompt
> net start "service name"
>
> --
> Regards,
>
> Dave Patrick ....Please no email replies - reply in newsgroup.
> Microsoft Certified Professional
> Microsoft MVP [Windows]
>
http://www.microsoft.com/protect
>
// Use at your own risk
// SAID stands for Service, Allow Interaction with Desktop
// based on
http://msdn.microsoft.com/library/default.asp?url=/libr...
#include <windows.h>
#include <stdio.h>
// BOOL ChangeServiceConfig(
// SC_HANDLE hService // handle to service
// DWORD dwServiceType, // type of service
// DWORD dwStartType, // when to start service
// DWORD dwErrorControl, // severity if service fails to start
// LPCTSTR lpBinaryPathName, // pointer to service binary file name
// LPCTSTR lpLoadOrderGroup, // pointer to load ordering group name
// LPDWORD lpdwTagId, // pointer to variable to get tag
identifier
// LPCTSTR lpDependencies, // pointer to array of dependency
names
// LPCTSTR lpServiceStartName,
// // pointer to account name of service
// LPCTSTR lpPassword, // pointer to password for service account
// LPCTSTR lpDisplayName // pointer to display name
// );
#ifdef _WIN32
char* traceFileNameS = "C:\\temp\\said-trace.txt" ;
#else
char* traceFileNameS = "/tmp/said-trace.txt" ;
#endif
extern "C" void saidTrace (char* string, ...)
{
char str[4096] ;
char *strP = str ;
va_list args ;
va_start (args, string) ;
vsprintf (strP, string, args) ;
FILE* traceFileP = fopen (traceFileNameS, "a+") ;
if (traceFileP != 0) {
fprintf (traceFileP, "%s\n", str) ;
fflush (traceFileP) ;
fclose (traceFileP) ;
}
va_end (args) ;
}
int ServiceAllowInteractionWithDesktop (SC_HANDLE schSCManager, char*
serviceName)
{
SC_HANDLE schService;
SERVICE_STATUS ssStatus;
DWORD dwOldCheckPoint;
DWORD dwStartTickCount;
DWORD dwWaitTime;
saidTrace ("%s:%i: opening service %s", __FILE__, __LINE__,
serviceName) ;
schService = OpenService(
schSCManager, // SCM database
serviceName, // service name
SERVICE_ALL_ACCESS);
if (schService == NULL)
{
saidTrace ("%s:%i: problem opening service '%s'", __FILE__, __LINE__,
serviceName) ;
return -1 ;
}
saidTrace ("%s:%i: SAID %i %i %i", __FILE__, __LINE__
, SERVICE_WIN32_OWN_PROCESS , SERVICE_INTERACTIVE_PROCESS
, SERVICE_WIN32_OWN_PROCESS |
SERVICE_INTERACTIVE_PROCESS
) ;
saidTrace ("%s:%i: changing service %s interactivity", __FILE__,
__LINE__, serviceName) ;
int ret = ChangeServiceConfig (schService, 272
, /* dwStartType */ SERVICE_NO_CHANGE
, /* dwErrorControl */ SERVICE_NO_CHANGE
, /* lpBinaryPathName */ 0
, /* ldLoadOrderGroup */ 0
, /* lddwTagID */ 0
, /* lpDependencies */ 0
, /* lpServiceStartName */ 0
, /* lpPassword */ 0
, /* ldDisplayName */ 0
) ;
if (ret == 0) {
LPVOID lpMsgBuf;
if (!FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL ))
{
// Handle the error.
saidTrace ("%s:%i: Failed to change registry setting (%i)",
GetLastError());
return -2 ;
}
saidTrace ("%s:%i: Failed to change registry setting (%i, %s)",
__FILE__, __LINE__, GetLastError(), lpMsgBuf);
LocalFree( lpMsgBuf );
return -3 ;
}
saidTrace ("%s:%i: closing service %s", __FILE__, __LINE__,
serviceName) ;
CloseServiceHandle (schService) ;
return 0 ;
#ifdef IGNORE_THIS
if (!StartService(
schService, // handle to service
0, // number of arguments
NULL) ) // no arguments
{
return 0;
}
else
{
saidTrace("Service start pending.");
}
// Check the status until the service is no longer start pending.
if (!QueryServiceStatus(
schService, // handle to service
&ssStatus) ) // address of status information structure
{
return 0;
}
// Save the tick count and initial checkpoint.
dwStartTickCount = GetTickCount();
dwOldCheckPoint = ssStatus.dwCheckPoint;
while (ssStatus.dwCurrentState == SERVICE_START_PENDING)
{
// Do not wait longer than the wait hint. A good interval is
// one tenth the wait hint, but no less than 1 second and no
// more than 10 seconds.
dwWaitTime = ssStatus.dwWaitHint / 10;
if( dwWaitTime < 1000 )
dwWaitTime = 1000;
else if ( dwWaitTime > 10000 )
dwWaitTime = 10000;
Sleep( dwWaitTime );
// Check the status again.
if (!QueryServiceStatus(
schService, // handle to service
&ssStatus) ) // address of structure
break;
if ( ssStatus.dwCheckPoint > dwOldCheckPoint )
{
// The service is making progress.
dwStartTickCount = GetTickCount();
dwOldCheckPoint = ssStatus.dwCheckPoint;
}
else
{
if(GetTickCount()-dwStartTickCount > ssStatus.dwWaitHint)
{
// No progress made within the wait hint
break;
}
}
}
CloseServiceHandle(schService);
if (ssStatus.dwCurrentState == SERVICE_RUNNING)
{
saidTrace("StartService SUCCESS.");
return 1;
}
else
{
saidTrace("\nService not started. ");
saidTrace(" Current State: %d", ssStatus.dwCurrentState);
saidTrace(" Exit Code: %d", ssStatus.dwWin32ExitCode);
saidTrace(" Service Specific Exit Code: %d",
ssStatus.dwServiceSpecificExitCode);
saidTrace(" Check Point: %d", ssStatus.dwCheckPoint);
saidTrace(" Wait Hint: %d", ssStatus.dwWaitHint);
return 0;
}
#endif
}
int main (int argc, char* argv[])
{
if (argc != 2) {
saidTrace ("%s:%i: Usage %s <quoted service name>", __FILE__,
__LINE__, argv[1]) ;
return -1 ;
}
saidTrace ("%s:%i: Opening service-controller manager", __FILE__,
__LINE__) ;
SC_HANDLE schSCManager ;
schSCManager = OpenSCManager ("", SERVICES_ACTIVE_DATABASE,
SC_MANAGER_ALL_ACCESS) ;
if (schSCManager == 0) {
saidTrace ("%s:%i: Problem opening service-controller manager",
__FILE__, __LINE__) ;
return -2 ;
}
int ret = ServiceAllowInteractionWithDesktop (schSCManager,
argv[1]) ;
if (ret != 0) {
return (-3 + ret) ;
}
saidTrace ("%s:%i: Closing service-controller manager", __FILE__,
__LINE__) ;
CloseServiceHandle (schSCManager) ;
return 0 ;
}