示例#1
0
文件: running.c 项目: cfillion/vifm
/* Runs a Windows executable handling errors and rights elevation. */
static void
run_win_executable(char full_path[], int elevate)
{
	int running_error = 0;
	int running_error_code = NO_ERROR;
	if(elevate && is_vista_and_above())
	{
		running_error = run_win_executable_as_evaluated(full_path);
	}
	else
	{
		int returned_exit_code;
		const int error = win_exec_cmd(full_path, &returned_exit_code);
		if(error != 0 && !returned_exit_code)
		{
			if(error == ERROR_ELEVATION_REQUIRED && is_vista_and_above())
			{
				const int user_response = prompt_msg("Program running error",
						"Executable requires rights elevation. Run with elevated rights?");
				if(user_response != 0)
				{
					running_error = run_win_executable_as_evaluated(full_path);
				}
			}
			else
			{
				running_error = 1;
				running_error_code = error;
			}
		}
		update_screen(UT_FULL);
	}
	if(running_error)
	{
		char err_msg[512];
		err_msg[0] = '\0';
		if(running_error_code != NO_ERROR && FormatMessageA(
				FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM, NULL,
				running_error_code, 0, err_msg, sizeof(err_msg), NULL) == 0)
		{
			LOG_WERROR(GetLastError());
		}

		show_error_msgf("Program running error", "Can't run an executable%s%s",
				(err_msg[0] == '\0') ? "." : ": ", err_msg);
	}
}
示例#2
0
文件: vifm.c 项目: ackeack/workenv
/* Runs vifmrc-converter in mode specified by the vifm_like_mode argument.
 * Returns zero on success, non-zero otherwise. */
static int
run_converter(int vifm_like_mode)
{
#ifndef _WIN32
	char buf[PATH_MAX];
	snprintf(buf, sizeof(buf), "vifmrc-converter %d", vifm_like_mode);
	return shellout(buf, -1, 1);
#else
	TCHAR buf[PATH_MAX + 2];
	TCHAR *last_path_component;
	int returned_exit_code;

	if(GetModuleFileName(NULL, buf, ARRAY_LEN(buf)) == 0)
		return -1;

	/* Remove last path component. */
	last_path_component = _tcsrchr(buf, _T('\\')) + 1;
	*last_path_component = _T('\0');

	switch(vifm_like_mode)
	{
		case 2:
			_tcscat(buf, _T("vifmrc-converter 2"));
			break;
		case 1:
			_tcscat(buf, _T("vifmrc-converter 1"));
			break;

		default:
			_tcscat(buf, _T("vifmrc-converter 0"));
			break;
	}

	return win_exec_cmd(buf, &returned_exit_code);
#endif
}