ERLEDIGT
NEIN
NEIN
ANTWORTEN
0
0
ZUGRIFFE
236
236
EMPFEHLEN
-
09.04.09 19:20 #1
Ich hab folgenden Code irgendwo im INet gefunden und hab ihn erstmal zum rumtüfteln und ausprobieren übernommen.
So, nun kann ich das auch kompilieren und alles. Es piept auch schön wenn man es als Service startet. Nur mein keybd_event wird nicht ausglöst. Genauso geht auch nicht DrawText und so weiter. Wie kann ich das lösen?Code :1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
#include <windows.h> #include <tchar.h> #include <string> using namespace std; TCHAR* serviceName = TEXT("Beeper Service"); SERVICE_STATUS serviceStatus; SERVICE_STATUS_HANDLE serviceStatusHandle = 0; HANDLE stopServiceEvent = 0; void WINAPI ServiceControlHandler( DWORD controlCode ) { switch ( controlCode ) { case SERVICE_CONTROL_INTERROGATE: break; case SERVICE_CONTROL_SHUTDOWN: case SERVICE_CONTROL_STOP: serviceStatus.dwCurrentState = SERVICE_STOP_PENDING; SetServiceStatus( serviceStatusHandle, &serviceStatus ); SetEvent( stopServiceEvent ); return; case SERVICE_CONTROL_PAUSE: break; case SERVICE_CONTROL_CONTINUE: break; default: if ( controlCode >= 128 && controlCode <= 255 ) // user defined control code break; else // unrecognised control code break; } SetServiceStatus( serviceStatusHandle, &serviceStatus ); } void WINAPI ServiceMain( DWORD /*argc*/, TCHAR* /*argv*/[] ) { // initialise service status serviceStatus.dwServiceType = SERVICE_WIN32; serviceStatus.dwCurrentState = SERVICE_STOPPED; serviceStatus.dwControlsAccepted = 0; serviceStatus.dwWin32ExitCode = NO_ERROR; serviceStatus.dwServiceSpecificExitCode = NO_ERROR; serviceStatus.dwCheckPoint = 0; serviceStatus.dwWaitHint = 0; serviceStatusHandle = RegisterServiceCtrlHandler( serviceName, ServiceControlHandler ); if ( serviceStatusHandle ) { // service is starting serviceStatus.dwCurrentState = SERVICE_START_PENDING; SetServiceStatus( serviceStatusHandle, &serviceStatus ); // do initialisation here stopServiceEvent = CreateEvent( 0, FALSE, FALSE, 0 ); // running serviceStatus.dwControlsAccepted |= (SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN); serviceStatus.dwCurrentState = SERVICE_RUNNING; SetServiceStatus( serviceStatusHandle, &serviceStatus ); int num=0; do { keybd_event(VK_CAPITAL,0x45,KEYEVENTF_EXTENDEDKEY,0 ); keybd_event(VK_CAPITAL,0x45,KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,0); Beep(1000,100); } while ( WaitForSingleObject( stopServiceEvent, 1000 ) == 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() { SERVICE_TABLE_ENTRY serviceTable[] = { { serviceName, ServiceMain }, { 0, 0 } }; BOOL success; success = StartServiceCtrlDispatcher( serviceTable ); if (!success ) { MessageBox( NULL, // handle of owner window "Oops should not see this!", // address of text in message box "Beeper Service Error", // address of title of message box MB_OK |MB_TASKMODAL // style of message box ); } } void InstallService() { SC_HANDLE serviceControlManager = OpenSCManager( 0, 0, SC_MANAGER_CREATE_SERVICE ); if ( serviceControlManager ) { char path[ _MAX_PATH + 1 ]; if ( GetModuleFileName( 0, path, sizeof(path)/sizeof(path[0]) ) > 0 ) { SC_HANDLE service = CreateService( serviceControlManager, serviceName, serviceName, SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS, SERVICE_AUTO_START, SERVICE_ERROR_IGNORE, path, 0, 0, 0, 0, 0 ); if ( service ) CloseServiceHandle( service ); } CloseServiceHandle( serviceControlManager ); } } void UninstallService() { SC_HANDLE serviceControlManager = OpenSCManager( 0, 0, SC_MANAGER_CONNECT ); if ( serviceControlManager ) { SC_HANDLE service = OpenService( serviceControlManager, serviceName, SERVICE_QUERY_STATUS | DELETE ); if ( service ) { SERVICE_STATUS serviceStatus; if ( QueryServiceStatus( service, &serviceStatus ) ) { if ( serviceStatus.dwCurrentState == SERVICE_STOPPED ) DeleteService( service ); } CloseServiceHandle( service ); } CloseServiceHandle( serviceControlManager ); } } int _tmain( int argc, TCHAR* argv[] ) { if ( argc > 1 && lstrcmpi( argv[1], TEXT("install") ) == 0 ) { InstallService(); } else if ( argc > 1 && lstrcmpi( argv[1], TEXT("uninstall") ) == 0 ) { UninstallService(); } else { RunService(); } return 0; }MFG Scipio
Ein Danke für hilfreiche Antworten ist gern gesehen.
Ähnliche Themen
-
Problem mit Silverlight und WCF RIA-Service
Von Rugosh im Forum .NET WPF & SilverlightAntworten: 4Letzter Beitrag: 27.07.10, 12:59 -
Problem Service Pack 3 auf XP
Von Dalli77 im Forum Microsoft WindowsAntworten: 4Letzter Beitrag: 13.08.08, 13:33 -
Hilfe Windows Service Pack1 vs. Service Pack2
Von dreambaser im Forum NetzwerkeAntworten: 4Letzter Beitrag: 20.05.05, 23:15 -
SMS - Service (Problem mit Überlangen SMS)
Von proloser im Forum PHPAntworten: 4Letzter Beitrag: 08.03.05, 22:28 -
MS Win Service Pack 2 Problem
Von bigfella im Forum Microsoft WindowsAntworten: 7Letzter Beitrag: 06.10.04, 21:23





Zitieren
Login






