啟動windows服務成功

2021-06-16 18:49:12 字數 1575 閱讀 7044

這兩天一直在學習windows服務的知識,書上的和網上的程式,可以成功安裝服務,但是無法啟動,會出現1053的錯誤:

錯誤 1053: 服務沒有及時響應啟動或控制請求。

**如下:

#include #include tchar* servicename = text("beeper service");

service_status servicestatus;

service_status_handle servicestatushandle = 0;

handle stopserviceevent = 0;

void winapi servicecontrolhandler( dword controlcode )

setservicestatus( servicestatushandle, &servicestatus );

}void winapi servicemain( dword /*argc*/, tchar* /*argv*/ )

while ( waitforsingleobject( stopserviceevent, 5000 ) == wait_timeout );

// service was stopped

servicestatus.dwcurrentstate = service_stop_pending;

setservicestatus( servicestatushandle, &servicestatus );

// do cleanup here

closehandle( stopserviceevent );

stopserviceevent = 0;

// service is now stopped

servicestatus.dwcontrolsaccepted &= ~(service_accept_stop | service_accept_shutdown);

servicestatus.dwcurrentstate = service_stopped;

setservicestatus( servicestatushandle, &servicestatus ); }}

void runservice(),

}; startservicectrldispatcher( servicetable );

}void installservice()

closeservicehandle( servicecontrolmanager ); }}

void uninstallservice()

closeservicehandle( service );

} closeservicehandle( servicecontrolmanager ); }}

int _tmain( int argc, tchar* argv )

else if ( argc > 1 && lstrcmpi( argv[1], text("uninstall") ) == 0 )

else

return 0;

}

服務啟動後會電腦會發出聲音。

windows啟動redis服務

參考 2.使用如下命令可將redis註冊到windows服務 2 設定服務命令 redis server service install redis.windows service.conf loglevel verbose 此時還不能在windows的服務啟動redis 由於redis.windo...

指令碼啟動windows服務

echo off setlocal enabledelayedexpansion for f tokens delims i in sc query state inactive findstr findstr sql do echo i set tmpstr i echo tmpstr 13,1 ...

改變Windows服務的啟動順序

要改變windows服務的啟動順序,只要修改windows的登錄檔就可 以了。任何windows服務的註冊資訊可以在登錄檔的hkey local machine group值 乙個reg sz型別的值。它用來描述服務屬於那乙個服務組。如果服務沒有這一項,那麼它不屬於任何乙個服務組,系統則會預設的將其...