--- q_a/samples/sd_flppy/instsrv.c 2018/08/09 18:29:42 1.1 +++ q_a/samples/sd_flppy/instsrv.c 2018/08/09 18:30:11 1.1.1.2 @@ -3,7 +3,7 @@ #include #include -#define FORCE_SERVICE_NAME_TO_FLOPPYLOCK (0==0) +#define FORCE_SERVICE_NAME_TO_FLOPPYLOCK (1==0) #define PERR(api) printf("\n%s: Error %d from %s on line %d", \ __FILE__, GetLastError(), api, __LINE__); @@ -17,6 +17,8 @@ SC_HANDLE schService; SC_HANDLE schSCManager; +VOID DisplayHelp(VOID); + VOID InstallService(LPCTSTR serviceName, LPCTSTR serviceExe) { LPCTSTR lpszBinaryPathName = serviceExe; @@ -74,20 +76,38 @@ VOID InstallService(LPCTSTR serviceName, return; } - schService = CreateService( - schSCManager, // SCManager database - serviceName, // name of service - serviceName, // name to display (new parameter after october beta) - SERVICE_ALL_ACCESS, // desired access - SERVICE_WIN32_OWN_PROCESS, // service type - SERVICE_AUTO_START, // start type - SERVICE_ERROR_NORMAL, // error control type - lpszBinaryPathName, // service's binary - NULL, // no load ordering group - NULL, // no tag identifier - NULL, // no dependencies - ".\\Administrator", // Admin account - ""); // null password + if (FORCE_SERVICE_NAME_TO_FLOPPYLOCK) + { schService = CreateService( + schSCManager, // SCManager database + serviceName, // name of service + serviceName, // name to display (new parameter after october beta) + SERVICE_ALL_ACCESS, // desired access + SERVICE_WIN32_OWN_PROCESS, // service type + SERVICE_AUTO_START, // start type + SERVICE_ERROR_NORMAL, // error control type + lpszBinaryPathName, // service's binary + NULL, // no load ordering group + NULL, // no tag identifier + NULL, // no dependencies + NULL, // Local System account + NULL); // null password + } + else + { schService = CreateService( + schSCManager, // SCManager database + serviceName, // name of service + serviceName, // name to display (new parameter after october beta) + SERVICE_ALL_ACCESS, // desired access + SERVICE_WIN32_OWN_PROCESS, // service type + SERVICE_AUTO_START, // start type + SERVICE_ERROR_NORMAL, // error control type + lpszBinaryPathName, // service's binary + NULL, // no load ordering group + NULL, // no tag identifier + NULL, // no dependencies + ".\\Administrator", // Admin account + ""); // likely incorrect password + } if (NULL == schService) { switch (GetLastError()) @@ -108,19 +128,29 @@ VOID InstallService(LPCTSTR serviceName, return; } else - { printf("\nCreateService SUCCESS\n"); - printf("\nDon't forget!!! You must now go to the Control Panel and"); - printf("\n use the Services applet to change the account name and"); - printf("\n password that this newly installed service will use when"); - printf("\n it attempts to logon as a service when it starts."); - printf("\nTo do this: use the Startup button in the Services applet,"); - printf("\n and (for example) specify the Administrator account and"); - printf("\n correct password."); - printf("\nAlso, use the Services applet to ensure this newly installed"); - printf("\n service starts automatically, since the point of this"); - printf("\n service is to start automatically and apply the DACLs"); - printf("\n to the floppy drives prior to a user logging on at"); - printf("\n the keyboard\n"); + { if (FORCE_SERVICE_NAME_TO_FLOPPYLOCK) + { printf("\nThe FloppyLock service was installed successfully.\n"); + printf("\nImportant! Before you can use the FloppyLock service, start Control"); + printf("\nPanel and choose the Services applet. Then select the FloppyLock"); + printf("\nservice and press Startup. Select System Account, or else FloppyLock"); + printf("\nwill not be able to start properly. If you want the service to start"); + printf("\nautomatically, select Automatic.\n"); + } + else + { printf("\nCreateService SUCCESS\n"); + printf("\nDon't forget!!! You must now go to the Control Panel and"); + printf("\n use the Services applet to change the account name and"); + printf("\n password that this newly installed service will use when"); + printf("\n it attempts to logon as a service when it starts."); + printf("\nTo do this: use the Startup button in the Services applet,"); + printf("\n and (for example) specify the Administrator account and"); + printf("\n correct password."); + printf("\nAlso, use the Services applet to ensure this newly installed"); + printf("\n service starts automatically, since the point of this"); + printf("\n service is to start automatically and apply the DACLs"); + printf("\n to the floppy drives prior to a user logging on at"); + printf("\n the keyboard\n"); + } } CloseServiceHandle(schService); @@ -222,36 +252,34 @@ VOID main(int argc, char *argv[]) LPTSTR lpszExeName = (LPTSTR)&ucExeNBuf; BOOL bRemovingService = FALSE; + char *p; + + if ( (argc != 2) && (argc != 3) ) + { DisplayHelp(); + exit(1); + } + + p=argv[1]; + if ( ('/' == *p) + || ('-' == *p) ) + { DisplayHelp(); + exit(1); + } if (FORCE_SERVICE_NAME_TO_FLOPPYLOCK) { if (argc != 2) - { printf("\nUsage: instsrv "); - printf("\n to install the FloppyLock service, or:"); - printf("\n instsrv remove"); - printf("\n to remove the FloppyLock service\n"); - printf("\nA more specific example"); - printf("\n instsrv c:\\q_a\\samples\\sd_flppy\\service\\floplock.exe"); - printf("\n (note fully-qualified path name to .exe)"); - printf("\n instsrv remove\n"); + { DisplayHelp(); exit(1); } else - { - strcpy(lpszExeName ,argv[1]); + { strcpy(lpszExeName ,argv[1]); bRemovingService = (!stricmp(argv[1], "remove")); } } else { if (argc != 3) - { printf("\nUsage: instsrv "); - printf("\n to install a service, or:"); - printf("\n instsrv remove"); - printf("\n to remove a service\n"); - printf("\nIn the case of this service, a more specific example"); - printf("\n instsrv FloppyLocker c:\\q_a\\samples\\sd_flppy\\service\\floplock.exe"); - printf("\n (note fully-qualified path name to .exe)"); - printf("\n instsrv FloppyLocker remove\n"); + { DisplayHelp(); exit(1); } else @@ -293,3 +321,28 @@ VOID main(int argc, char *argv[]) CloseServiceHandle(schSCManager); } + +VOID DisplayHelp(VOID) +{ + if (FORCE_SERVICE_NAME_TO_FLOPPYLOCK) + { printf("\nInstalls or removes the FloppyLock service. When the FloppyLock"); + printf("\nservice is started, only members of the Administrators group can use"); + printf("\nthe floppy drives on the computer.\n"); + printf("\nTo install the FloppyLock service, type INSTSRV \n"); + printf("\n path Absolute path to the FloppyLock service, floplock.exe. You must"); + printf("\n use a fully qualified path and the drive letter must be for a"); + printf("\n fixed, local drive. For example, INSTSRV c:\\reskit\\floplock.exe.\n"); + printf("\nTo remove the FloppyLock service, type INSTSRV remove\n"); + } + else + { printf("\nUsage: instsrv "); + printf("\n to install a service, or:"); + printf("\n instsrv remove"); + printf("\n to remove a service\n"); + printf("\nIn the case of this service, a more specific example"); + printf("\n instsrv FloppyLocker c:\\q_a\\samples\\sd_flppy\\floplock.exe"); + printf("\n (note fully-qualified path name to .exe)"); + printf("\n instsrv FloppyLocker remove\n"); + } + return; +}