Changeset 78
- Timestamp:
- 08/17/10 10:23:57 (18 months ago)
- Location:
- trunk/sources/win32service
- Files:
-
- 2 added
- 5 edited
-
svcconfig/include/svcconfig.h (added)
-
svcconfig/src/svcconfig.cpp (modified) (18 diffs)
-
svccontrol/include/svccontrol.h (added)
-
svccontrol/src/svccontrol.cpp (modified) (7 diffs)
-
win32service/include/svc/svc.h (modified) (2 diffs)
-
win32service/readme.txt (modified) (1 diff)
-
win32service/src/svc/svc.cpp (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/win32service/svcconfig/src/svcconfig.cpp
r73 r78 3 3 #include <strsafe.h> 4 4 #include <stdio.h> 5 #include "svcconfig.h" 5 6 6 7 #pragma comment(lib, "advapi32.lib") 7 8 8 TCHAR szCommand[10]; 9 TCHAR szSvcName[80]; 10 11 VOID __stdcall DisplayUsage(void); 12 13 VOID __stdcall DoQuerySvc(void); 14 VOID __stdcall DoUpdateSvcDesc(void); 15 VOID __stdcall DoDisableSvc(void); 16 VOID __stdcall DoEnableSvc(void); 17 VOID __stdcall DoDeleteSvc(void); 9 TCHAR szConfigCommand[TEXT_SIZE]; 10 TCHAR szConfigSvcName[TEXT_SIZE]; 11 18 12 19 13 // … … 27 21 // None 28 22 // 29 void __cdecl _tmain(int argc, TCHAR *argv[]) 30 { 23 //void __cdecl _tmain(int argc, TCHAR *argv[]) 24 bool svcconfig (TCHAR * argv[]) 25 { 26 bool result = true; 31 27 printf("\n"); 28 /* 32 29 if( argc != 3 ) 33 30 { … … 36 33 return; 37 34 } 38 39 StringCchCopy(szCo mmand, 10, argv[1]);40 StringCchCopy(sz SvcName, 80, argv[2]);41 42 if (lstrcmpi( szCo mmand, TEXT("query")) == 0 )43 DoQuerySvc();44 else if (lstrcmpi( szCo mmand, TEXT("describe")) == 0 )35 */ 36 StringCchCopy(szConfigCommand, TEXT_SIZE, argv[1]); 37 StringCchCopy(szConfigSvcName, TEXT_SIZE, argv[2]); 38 39 if (lstrcmpi( szConfigCommand, TEXT("query")) == 0 ) 40 result = DoQuerySvc(); 41 else if (lstrcmpi( szConfigCommand, TEXT("describe")) == 0 ) 45 42 DoUpdateSvcDesc(); 46 else if (lstrcmpi( szCo mmand, TEXT("disable")) == 0 )43 else if (lstrcmpi( szConfigCommand, TEXT("disable")) == 0 ) 47 44 DoDisableSvc(); 48 else if (lstrcmpi( szCo mmand, TEXT("enable")) == 0 )45 else if (lstrcmpi( szConfigCommand, TEXT("enable")) == 0 ) 49 46 DoEnableSvc(); 50 else if (lstrcmpi( szCo mmand, TEXT("delete")) == 0 )47 else if (lstrcmpi( szConfigCommand, TEXT("uninstallService")) == 0 ) 51 48 DoDeleteSvc(); 52 49 else 53 50 { 54 _tprintf(TEXT("Unknown command (%s)\n\n"), szCommand); 55 DisplayUsage(); 56 } 57 } 58 51 _tprintf(TEXT("Unknown command (%s)\n\n"), szConfigCommand); 52 //DisplayUsage(); 53 } 54 55 return result; 56 } 57 /* 59 58 VOID __stdcall DisplayUsage() 60 59 { … … 70 69 printf("\t delete\n"); 71 70 } 72 71 */ 73 72 // 74 73 // Purpose: … … 81 80 // None 82 81 // 83 VOID__stdcall DoQuerySvc()82 bool __stdcall DoQuerySvc() 84 83 { 85 84 SC_HANDLE schSCManager; … … 99 98 { 100 99 printf("OpenSCManager failed (%d)\n", GetLastError()); 101 return ;100 return false; 102 101 } 103 102 … … 106 105 schService = OpenService( 107 106 schSCManager, // SCM database 108 sz SvcName, // name of service107 szConfigSvcName, // name of service 109 108 SERVICE_QUERY_CONFIG); // need query config access 110 109 … … 113 112 printf("OpenService failed (%d)\n", GetLastError()); 114 113 CloseServiceHandle(schSCManager); 115 return ;114 return false; 116 115 } 117 116 … … 133 132 { 134 133 printf("QueryServiceConfig failed (%d)", dwError); 134 return false; 135 135 goto cleanup; 136 136 } … … 144 144 { 145 145 printf("QueryServiceConfig failed (%d)", GetLastError()); 146 return false; 146 147 goto cleanup; 147 148 } … … 163 164 { 164 165 printf("QueryServiceConfig2 failed (%d)", dwError); 166 return false; 165 167 goto cleanup; 166 168 } … … 175 177 { 176 178 printf("QueryServiceConfig2 failed (%d)", GetLastError()); 179 return false; 177 180 goto cleanup; 178 181 } … … 180 183 // Print the configuration information. 181 184 182 _tprintf(TEXT("%s configuration: \n"), sz SvcName);185 _tprintf(TEXT("%s configuration: \n"), szConfigSvcName); 183 186 _tprintf(TEXT(" Type: 0x%x\n"), lpsc->dwServiceType); 184 187 _tprintf(TEXT(" Start Type: 0x%x\n"), lpsc->dwStartType); … … 198 201 LocalFree(lpsc); 199 202 LocalFree(lpsd); 200 203 return true; 201 204 cleanup: 202 205 CloseServiceHandle(schService); … … 236 239 schService = OpenService( 237 240 schSCManager, // SCM database 238 sz SvcName, // name of service241 szConfigSvcName, // name of service 239 242 SERVICE_CHANGE_CONFIG); // need change config access 240 243 … … 301 304 schService = OpenService( 302 305 schSCManager, // SCM database 303 sz SvcName, // name of service306 szConfigSvcName, // name of service 304 307 SERVICE_CHANGE_CONFIG); // need change config access 305 308 … … 368 371 schService = OpenService( 369 372 schSCManager, // SCM database 370 sz SvcName, // name of service373 szConfigSvcName, // name of service 371 374 SERVICE_CHANGE_CONFIG); // need change config access 372 375 … … 428 431 schService = OpenService( 429 432 schSCManager, // SCM database 430 sz SvcName, // name of service433 szConfigSvcName, // name of service 431 434 DELETE); // need delete access 432 435 -
trunk/sources/win32service/svccontrol/src/svccontrol.cpp
r73 r78 4 4 #include <aclapi.h> 5 5 #include <stdio.h> 6 7 #pragma comment(lib, "advapi32.lib") 8 9 TCHAR szCommand[10]; 10 TCHAR szSvcName[80]; 6 #include "svccontrol.h" 7 8 TCHAR szControlCommand[TEXT_SIZE]; 9 TCHAR szControlSvcName[TEXT_SIZE]; 11 10 12 11 SC_HANDLE schSCManager; 13 12 SC_HANDLE schService; 14 13 15 VOID __stdcall DisplayUsage(void); 16 17 VOID __stdcall DoStartSvc(void); 18 VOID __stdcall DoUpdateSvcDacl(void); 19 VOID __stdcall DoStopSvc(void); 20 21 BOOL __stdcall StopDependentServices(void); 14 #pragma comment(lib, "advapi32.lib") 15 22 16 23 17 // … … 31 25 // None 32 26 // 33 void _tmain(int argc, TCHAR *argv[]) 27 //void _tmain(int argc, TCHAR *argv[]) 28 void svccontrol(TCHAR * argv[]) 34 29 { 35 printf("\n"); 30 /*printf("\n"); 31 36 32 if( argc != 3 ) 37 33 { … … 40 36 return; 41 37 } 42 43 StringCchCopy(szCo mmand, 10, argv[1]);44 StringCchCopy(sz SvcName, 80, argv[2]);45 46 if (lstrcmpi( szCo mmand, TEXT("start")) == 0 )38 */ 39 StringCchCopy(szControlCommand, TEXT_SIZE, argv[1]); 40 StringCchCopy(szControlSvcName, TEXT_SIZE, argv[2]); 41 42 if (lstrcmpi( szControlCommand, TEXT("startService")) == 0 ) 47 43 DoStartSvc(); 48 else if (lstrcmpi( szCo mmand, TEXT("dacl")) == 0 )44 else if (lstrcmpi( szControlCommand, TEXT("dacl")) == 0 ) 49 45 DoUpdateSvcDacl(); 50 else if (lstrcmpi( szCo mmand, TEXT("stop")) == 0 )46 else if (lstrcmpi( szControlCommand, TEXT("stopService")) == 0 ) 51 47 DoStopSvc(); 52 48 else 53 49 { 54 _tprintf(TEXT("Unknown command (%s)\n\n"), szCo mmand);55 DisplayUsage();50 _tprintf(TEXT("Unknown command (%s)\n\n"), szControlCommand); 51 // DisplayUsage(); 56 52 } 57 53 } 58 54 /* 59 55 VOID __stdcall DisplayUsage() 60 56 { … … 68 64 printf("\t stop\n"); 69 65 } 70 66 */ 71 67 // 72 68 // Purpose: … … 104 100 schService = OpenService( 105 101 schSCManager, // SCM database 106 sz SvcName, // name of service102 szControlSvcName, // name of service 107 103 SERVICE_ALL_ACCESS); // full access 108 104 … … 336 332 schService = OpenService( 337 333 schSCManager, // SCManager database 338 sz SvcName, // name of service334 szControlSvcName, // name of service 339 335 READ_CONTROL | WRITE_DAC); // access 340 336 … … 474 470 schService = OpenService( 475 471 schSCManager, // SCM database 476 sz SvcName, // name of service472 szControlSvcName, // name of service 477 473 SERVICE_STOP | 478 474 SERVICE_QUERY_STATUS | -
trunk/sources/win32service/win32service/include/svc/svc.h
r73 r78 15 15 VOID SvcInit( DWORD, LPTSTR * ); 16 16 VOID SvcReportEvent( LPTSTR ); 17 VOID __stdcall DisplayUsage(); 18 VOID AddSvcCommand(TCHAR * command); 17 19 18 20 DWORD WINAPI ThreadProc( __in LPVOID lpParameter); … … 21 23 22 24 HANDLE hThread = NULL; 25 TCHAR * svcCommand[3]; -
trunk/sources/win32service/win32service/readme.txt
r73 r78 3 3 Source: http://msdn.microsoft.com/en-us/library/bb540476%28v=VS.85%29.aspx 4 4 5 Brief Description: 6 win32service is a win32 console application that installs a service named "evo". 7 This service can be started and stopped using the Services Administrative Tool seen from the Control Panel. 5 BRIEF DESCRIPTION: 6 win32service is a win32 console application that runs the following command: 7 1. Installs a Windows service named "evo" 8 2. Uninstalls the service named "evo" 9 3. Starts the service 10 4. Stops the service 11 5. Starts the rtmpserver normally in the console. 12 In addition, the service can also be started and stopped using the Services Administrative Tool seen from the Control Panel. 8 13 9 Additional Applications: 10 There are other applications outside win32service that can be useful in testing: 11 1. SvcControl - is a console application that can start and stop the service. More commands can be done here (refer to Source) 12 2. SvcConfig - is a consol application that can be used to delete the service. More commands can be done here (refer to Source) 14 MODULES: 15 1. svcconfig - contains the function that deletes/uninstalls the service. This is also where the application checks if a service is already installed. 16 2. svccontrol - contains the functions that starts and stops the service. 17 3. svc - contains the "main" function. When the service is created, the SvcMain acts as the main function of the thread when the service starts. 18 4. rtmpserver - is the application that runs the server. 13 19 14 Instruction (How to use ?):20 Instruction (How to use): 15 21 To start/stop service: 16 22 1. Compile the application. 17 23 2. Open a command prompt as administrator (right click on command prompt, select "Run as Administrator"). 18 24 3. cd to directory of win32service. 19 4. Type "win32service install " and wait for "Service installed successfuly" to appear.25 4. Type "win32service installService" and wait for "Service installed successfuly" to appear. 20 26 5. Check the Service admin tool and look for "evo" service. 21 27 6. Start/Stop evo service. 22 28 23 To delete the service: compile SvcConfig, cd to the dir of svcconfig.exe, type "svcconfig delete evo". 24 25 To start/stop rtmpserver (Will be improved soon) 29 To start/stop rtmpserver 26 30 rtmpserver should start when evo service starts. To make sure that it starts successfuly: 27 31 - Put the exact path of rtmpserver.lua in line#-84 of rtmpserver.cpp. 28 32 - Assign a "mediaFolder" parameter in rtmpserver.lua 29 Stop the evo service to stop rtmpserver. 33 Start the server by starting the service using the 'startService' command. 34 Stop the server by stopping the service using the 'stopService' command. 35 If the service is not installed, start the server normally by running the application without any command parameter. 36 37 To uninstall the service, enter the 'uninstallService' command. 38 39 SOME TECHNICAL DETAILS: 40 - The application makes sure that when the service is installed, the user will not be able to start the server normally. 41 - To check if the service is installed, the application queries information about the service. If the query returns a value, the server will not be started normally. 42 - Running the application without any command assumes that the user is attempting to start the server in a normal way. 43 - svcconfig and svccontrol have other functions that can be useful during testing and in future implementations, hence a lot of codes remain intact. 30 44 31 45 NOTES: 46 - [as of commit in 08-17-2010] The config file is hard-coded in rtmpserver.cpp 32 47 - Currently, the rtmpserver logs is saved to C:\\RTMPServerlogs.txt. 33 48 - There are limited sample applications in the net that implements this model. 34 - In most of the sample apps, they loop a "while()" during the service's RUNNING state, simulating a running thread (since SvcMain acts likea thread).49 - In most of the sample apps, they loop a "while()" during the service's RUNNING state, simulating a running thread (since SvcMain acts as a thread). -
trunk/sources/win32service/win32service/src/svc/svc.cpp
r73 r78 5 5 #include "svc/Svc.h" 6 6 #include "rtmpserver/rtmpserver.h" 7 #include "svccontrol.h" 8 #include "svcconfig.h" 7 9 8 10 #pragma comment(lib, "advapi32.lib") … … 23 25 void __cdecl _tmain(int argc, TCHAR *argv[]) 24 26 { 25 // If command-line parameter is "install", install the service. 26 // Otherwise, the service is probably being started by the SCM. 27 28 if( lstrcmpi( argv[1], TEXT("install")) == 0 ) 29 { 30 SvcInstall(); 31 return; 32 } 33 34 // TO_DO: Add any additional services for the process to this table. 27 28 // Install/uninstall the service. 29 if( lstrcmpi( argv[1], TEXT("installService")) == 0 ) 30 { 31 SvcInstall(); 32 return; 33 }else if( lstrcmpi( argv[1], TEXT("uninstallService")) == 0) 34 { 35 AddSvcCommand(argv[1]); 36 bool result = svcconfig(svcCommand);//Delete service 37 return; 38 } 39 // TO_DO: Add any additional services for the process to this table. 35 40 SERVICE_TABLE_ENTRY DispatchTable[] = 36 41 { … … 46 51 SvcReportEvent(TEXT("StartServiceCtrlDispatcher")); 47 52 } 48 } 49 53 54 // Control the service 55 if( lstrcmpi( argv[1], TEXT("startService")) == 0 || lstrcmpi( argv[1], TEXT("stopService")) == 0) 56 { 57 AddSvcCommand(argv[1]); 58 svccontrol(svcCommand);//Start/Stop service 59 return; 60 } else { 61 if ( argc == 1 ) //if no argument, assume that rtmpserver is started normally 62 { 63 AddSvcCommand(TEXT("query")); 64 if (!svcconfig(svcCommand)){ 65 printf("Server will start normally.\n\n"); 66 rtmpserver(); 67 return; 68 }else{ 69 printf("\nERROR: Server cannot be started normally.\n\n"); 70 printf("Service described above is already installed.\n"); 71 printf("Start/Stop the server by starting/stopping the service.\n\n"); 72 printf("To start server normally, enter 'uninstallService' command to delete the service.\n\n"); 73 return; 74 } 75 } 76 } 77 78 } 79 80 //Populates the svcCommand array 81 VOID AddSvcCommand(TCHAR * command) 82 { 83 svcCommand[0] = TEXT(""); 84 svcCommand[1] = command; 85 svcCommand[2] = SVCNAME; 86 } 87 88 //Displays usage 89 VOID __stdcall DisplayUsage() 90 { 91 printf("Description:\n"); 92 printf("\tRun Evostream server as stand-alone or as a service.\n\n"); 93 printf("Usage:\n"); 94 printf("Install Service:\n"); 95 printf("\twin32service installService\n\n"); 96 printf("Uninstall Service:\n"); 97 printf("\twin32service uninstallService\n\n"); 98 printf("Start/Stop Service:\n"); 99 printf("\twin32service [command]\n"); 100 printf("\t[command]\n"); 101 printf("\t startService\n"); 102 printf("\t stopService\n"); 103 printf("Run as stand-alone:\n"); 104 printf("\twin32service <configfile path>\n"); 105 printf("\twin32service --use-implicit-console-appender\n"); 106 } 50 107 // 51 108 // Purpose: … … 110 167 CloseServiceHandle(schService); 111 168 CloseServiceHandle(schSCManager); 112 113 169 /* The lines below works fine. Uncomment them to run rtmpserver upon installing of the service */ 114 170 // if(Initialize())
Note: See TracChangeset
for help on using the changeset viewer.
