- /* Work out directory name */\r
- unsigned int len = strlen(exe);\r
- unsigned int i;\r
- for (i = len; i && exe[i] != '\\' && exe[i] != '/'; i--);\r
- memmove(dir, exe, i);\r
- dir[i] = '\0';\r
-\r
- /* Open service manager */\r
- SC_HANDLE services = open_service_manager();\r
- if (! services) {\r
- MessageBox(0, "Can't open service manager!\nPerhaps you need to be an administrator...", NSSM, MB_OK);\r
- return 2;\r
- }\r
- \r
- /* Get path of this program */\r
- char path[MAX_PATH];\r
- GetModuleFileName(0, path, MAX_PATH);\r
-\r
- /* Construct command */\r
- char command[MAX_PATH];\r
- int runlen = strlen(NSSM_RUN);\r
- int pathlen = strlen(path);\r
- if (pathlen + runlen + 2 >= MAX_PATH) {\r
- MessageBox(0, "Path too long!\nThe full path to " NSSM " is too long.\nPlease install " NSSM " somewhere else...\n", NSSM, MB_OK);\r
- return 3;\r
- }\r
- if (snprintf(command, sizeof(command), "%s %s", path, NSSM_RUN) < 0) {\r
- MessageBox(0, "Error constructing ImagePath!\nThis really shouldn't happen. You could be out of memory\nor the world may be about to end or something equally bad.", NSSM, MB_OK);\r
- return 4;\r
- }\r
+ /* See if it works */\r
+ switch (install_service(name, exe, flags)) {\r
+ case 2:\r
+ popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_MESSAGE_OPEN_SERVICE_MANAGER_FAILED);\r
+ return 2;\r