feisty meow concerns codebase 2.140
run_as_service.cpp
Go to the documentation of this file.
1/*****************************************************************************\
2* *
3* Name : run_as_service *
4* Author : Chris Koeritz *
5* *
6*******************************************************************************
7* Copyright (c) 2000-$now By Author. This program is free software; you can *
8* redistribute it and/or modify it under the terms of the GNU General Public *
9* License as published by the Free Software Foundation; either version 2 of *
10* the License or (at your option) any later version. This is online at: *
11* http://www.fsf.org/copyleft/gpl.html *
12* Please send any updates to: fred@gruntose.com *
13\*****************************************************************************/
14
16#include <filesystem/filename.h>
19
21
23
24bool run_as_service(char *user, log_base &out)
25{
26#ifdef __WIN32__
27 // ensure that the user has the "logon as a service" right.
28 nt_security secu;
29 long err = secu.SetPrivilegeOnUser("", user, "SeServiceLogonRight", true);
30 if (err) {
31 // that didn't work; probably the user name is bad?
32 out.log(astring(astring::SPRINTF, "There was a problem giving "
33 "\"%s\" the \"Logon as a Service\" right:\r\n%s", user,
34 critical_events::system_error_text(err).s()));
35 return false;
36 }
37#else
38 astring junk = user;
39 out.eol();
40 junk += "";
41#endif
42 return true;
43}
44
45int main(int argc, char *argv[])
46{
47 console_logger out;
48 if (argc < 2) {
49 out.log(filename(argv[0]).rootname() + " usage:\n\
50The first parameter must be a user name that will be given the\n\
51\"login as a service\" access rights.\n");
52 return 1;
53 }
54 bool did_it = run_as_service(argv[1], out);
55 if (did_it)
56 out.log(astring("Success giving \"") + argv[1] + "\" the 'login as service' rights.");
57 else
58 out.log(astring("Failed in giving \"") + argv[1] + "\" the 'login as service' rights!");
59 return !did_it;
60}
61
62#ifdef __BUILD_STATIC_APPLICATION__
63 // static dependencies found by buildor_gen_deps.sh:
65 #include <basis/astring.cpp>
67 #include <basis/environment.cpp>
68 #include <basis/guards.cpp>
69 #include <basis/mutex.cpp>
78#endif // __BUILD_STATIC_APPLICATION__
79
int main(int argc, char *argv[])
bool run_as_service(char *user, log_base &out)
HOOPLE_STARTUP_CODE