Угадал параметр для GetLastError Вот он ERROR_ACCESS_DENIED The handle to the SCM database does not have the SC_MANAGER_CREATE_SERVICE access right. Какие права? Почему не могу создать сервис? Исходник Код (Text): #include <windows.h> int __stdcall WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow) { SC_HANDLE SCManager; SC_HANDLE CreateServis; char DriverPath[MAX_PATH]; char *NamePath; SCManager = OpenSCManager(0, 0, SC_MANAGER_CONNECT ); if(SCManager) MessageBox(0,"OpenSCManager","Открыли OpenSCManager ",0); GetFullPathName("beep.sys", sizeof(DriverPath), DriverPath, &NamePath); MessageBox(0,DriverPath,NamePath,0); CreateServis = CreateService(SCManager,"beep1","Nice Melody Beeper",SERVICE_START, SERVICE_KERNEL_DRIVER, SERVICE_DEMAND_START, SERVICE_ERROR_IGNORE, DriverPath, 0, 0, 0, 0, 0); if(CreateServis) MessageBox(0,"Nice Melody Beeper","Nice Melody Beeper",0); else { if (GetLastError() == ERROR_ACCESS_DENIED) MessageBox(0,0,0,0); } return 0; } MessageBox для проверки
А SC_MANAGER_CONNECT и ошибка не намекают? Тогда почитай http://msdn.microsoft.com/en-us/library/windows/desktop/ms685981%28v=vs.85%29.aspx
http://wasm.ru/article.php?article=drvw2k02 Код (Text): .386 .model flat, stdcall option casemap:none ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ; I N C L U D E F I L E S ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: include \masm32\include\windows.inc include \masm32\include\kernel32.inc include \masm32\include\user32.inc include \masm32\include\advapi32.inc includelib \masm32\lib\kernel32.lib includelib \masm32\lib\user32.lib includelib \masm32\lib\advapi32.lib include \masm32\Macros\Strings.mac ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ; C O D E ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: .code start proc LOCAL hSCManager:HANDLE LOCAL hService:HANDLE LOCAL acDriverPath[MAX_PATH]:CHAR invoke OpenSCManager, NULL, NULL, SC_MANAGER_CREATE_SERVICE .if eax != NULL mov hSCManager, eax push eax invoke GetFullPathName, $CTA0("beep.sys"), sizeof acDriverPath, addr acDriverPath, esp pop eax invoke CreateService, hSCManager, $CTA0("beep"), $CTA0("Nice Melody Beeper"), \ SERVICE_START + DELETE, SERVICE_KERNEL_DRIVER, SERVICE_DEMAND_START, \ SERVICE_ERROR_IGNORE, addr acDriverPath, NULL, NULL, NULL, NULL, NULL .if eax != NULL mov hService, eax invoke StartService, hService, 0, NULL invoke DeleteService, hService invoke CloseServiceHandle, hService .else invoke MessageBox, NULL, $CTA0("Can't register driver."), NULL, MB_ICONSTOP .endif invoke CloseServiceHandle, hSCManager .else invoke MessageBox, NULL, $CTA0("Can't connect to Service Control Manager."), \ NULL, MB_ICONSTOP .endif invoke ExitProcess, 0 start endp ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ; ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: end start