//------------------------------------------------------------------------------ static void print_help() { const char* help_verbs[] = { "install <args...>", "Installs a command to cmd.exe's autorun to start Clink", "uninstall", "Does the opposite of 'install'", "show", "Displays the values of cmd.exe's autorun variables", "set <string...>", "Explicitly sets cmd.exe's autorun to <string>", }; const char* help_args[] = { "-a, --allusers", "Modifies autorun for all users (requires admin rights).", "-h, --help", "Shows this help text.", }; extern const char* g_clink_header; puts(g_clink_header); puts("Usage: autorun [options] <verb> [<string>] [-- <clink_args>]\n"); puts("Verbs:"); puts_help(help_verbs, sizeof_array(help_verbs)); puts("Options:"); puts_help(help_args, sizeof_array(help_args)); puts("Autorun simplifies making modifications to cmd.exe's autorun registry\n" "variables. The value of these variables are read and executed by cmd.exe when\n" "it starts. The 'install/uninstall' verbs add/remove the corrent command to run\n" "Clink when cmd.exe starts. All '<args>' that follow 'install' are passed to\n" "Clink - see 'clink inject --help' for reference.\n"); puts("To include quotes they must be escaped with a backslash;\n"); puts(" clink autorun set \\\"foobar\\\""); puts("\nWrite access to cmd.exe's AutoRun registry entry will require\n" "administrator privileges when using the --allusers option."); }
//------------------------------------------------------------------------------ void print_usage() { extern const char* g_clink_header; const char* help[] = { "setting_name", "Name of the setting who's value is to be set.", "value", "Value to set the setting to." }; puts(g_clink_header); puts(" Usage: set [setting_name] [value]\n"); puts_help(help, sizeof_array(help)); puts(" If 'settings_name' is omitted then all settings are list."); puts(" Omit 'value' for more detailed info about a setting.\n"); }
//------------------------------------------------------------------------------ static int print_help() { extern const char* g_clink_header; const char* help[] = { "[n]", "Print history items (only the last N items if specified).", "clear", "Completly clears the command history.", "delete <n>", "Delete Nth item (negative N indexes history backwards).", "add <...>", "Join remaining arguments and appends to the history.", "expand <...>", "Print substitution result.", }; puts(g_clink_header); puts("Usage: history <verb> [option]\n"); puts("Verbs:"); puts_help(help, sizeof_array(help)); puts("The 'history' command can also emulates Bash's builtin history command. The\n" "arguments -c, -d <n>, -p <...> and -s <...> are supported.\n"); return 1; }
//------------------------------------------------------------------------------ int autorun(int argc, char** argv) { char* clink_path; int i; int ret; int need_admin_rights; dispatch_func_t* function; const char* path_arg; struct option options[] = { { "install", no_argument, NULL, 'i' }, { "uninstall", no_argument, NULL, 'u' }, { "show", no_argument, NULL, 's' }, { "value", required_argument, NULL, 'v' }, { "help", no_argument, NULL, 'h' }, { NULL, 0, NULL, 0 } }; const char* help[] = { "-i, --install", "Installs an autorun entry for cmd.exe.", "-u, --uninstall", "Uninstalls an autorun entry.", "-s, --show", "Displays the current autorun settings.", "-v, --value <string>", "Sets the autorun to <string>.", "-h, --help", "Shows this help text.", "-- <args>", "Pass <args> that follow '--' on to Clink." }; extern const char* g_clink_header; extern const char* g_clink_footer; // Get path where clink is installed (assumed to be where this executable is) clink_path = malloc(strlen(_pgmptr)); clink_path[0] = '\0'; str_cat(clink_path, _pgmptr, (int)(strrchr(_pgmptr, '\\') - _pgmptr + 1)); function = NULL; path_arg = clink_path; need_admin_rights = 1; while ((i = getopt_long(argc, argv, "v:siuh", options, NULL)) != -1) { switch (i) { case 'i': function = install_autorun; break; case 'u': function = uninstall_autorun; break; case 's': function = show_autorun; need_admin_rights = 0; break; case 'v': function = force_autorun; path_arg = optarg; break; case '?': ret = -1; goto end; case 'h': puts(g_clink_header); puts_help(help, sizeof_array(help)); puts(g_clink_footer); ret = -1; goto end; } } // Collect arguments to pass on to Clink. if (optind < argc && strcmp(argv[optind - 1], "--") == 0) { const char* cmd_line; cmd_line = GetCommandLine(); cmd_line = strstr(cmd_line, " -- "); if (cmd_line != NULL) { g_clink_args = cmd_line + 4; } } // Do the magic. if (function != NULL) { // Check we're running with sufficient privileges. if (need_admin_rights && !does_user_have_admin_rights()) { puts("You must have administator rights to access cmd.exe's autorun"); ret = -1; goto end; } ret = dispatch(function, path_arg); } else { puts(g_clink_header); puts_help(help, sizeof_array(help)); puts( "Access to cmd.exe's registry entries is restricted to members " "of the\nAdministors group so you must have sufficient rights " "to edit\n the registry.\n" ); puts(g_clink_footer); ret = -1; } end: free(clink_path); return ret; }