X-Git-Url: https://feistymeow.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=nucleus%2Ftools%2Fsimple_utilities%2Frun_as_service.cpp;fp=nucleus%2Ftools%2Fsimple_utilities%2Frun_as_service.cpp;h=1f1edf4abe747b0a1f8b96b339c761417dd1b2ee;hb=4ea6c95b4bdf06e3cbe6c03edfacae6a856f647b;hp=0000000000000000000000000000000000000000;hpb=2b76e268c4ab7fd8360195722a908fb1f36125cd;p=feisty_meow.git diff --git a/nucleus/tools/simple_utilities/run_as_service.cpp b/nucleus/tools/simple_utilities/run_as_service.cpp new file mode 100644 index 00000000..1f1edf4a --- /dev/null +++ b/nucleus/tools/simple_utilities/run_as_service.cpp @@ -0,0 +1,115 @@ +/*****************************************************************************\ +* * +* Name : run_as_service * +* Author : Chris Koeritz * +* * +******************************************************************************* +* Copyright (c) 2000-$now By Author. This program is free software; you can * +* redistribute it and/or modify it under the terms of the GNU General Public * +* License as published by the Free Software Foundation; either version 2 of * +* the License or (at your option) any later version. This is online at: * +* http://www.fsf.org/copyleft/gpl.html * +* Please send any updates to: fred@gruntose.com * +\*****************************************************************************/ + +#include +#include +#include +#include + +HOOPLE_STARTUP_CODE; + +////////////// + +bool run_as_service(char *user, log_base &out) +{ +#ifdef __WIN32__ + // ensure that the user has the "logon as a service" right. + nt_security secu; + long err = secu.SetPrivilegeOnUser("", user, "SeServiceLogonRight", true); + if (err) { + // that didn't work; probably the user name is bad? + out.log(astring(astring::SPRINTF, "There was a problem giving " + "\"%s\" the \"Logon as a Service\" right:\r\n%s", user, + critical_events::system_error_text(err).s())); + return false; + } +#else + astring junk = user; + out.eol(); + junk += ""; +#endif + return true; +} + +int main(int argc, char *argv[]) +{ + console_logger out; + if (argc < 2) { + out.log(filename(argv[0]).rootname() + " usage:\n\ +The first parameter must be a user name that will be given the\n\ +\"login as a service\" access rights.\n"); + return 1; + } + bool did_it = run_as_service(argv[1], out); + if (did_it) + out.log(astring("Success giving \"") + argv[1] + "\" the 'login as service' rights."); + else + out.log(astring("Failed in giving \"") + argv[1] + "\" the 'login as service' rights!"); + return !did_it; +} + +#ifdef __BUILD_STATIC_APPLICATION__ + // static dependencies found by buildor_gen_deps.sh: + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include +#endif // __BUILD_STATIC_APPLICATION__ +