Exemplo n.º 1
0
/* 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);
	}
}
Exemplo n.º 2
0
/* Copies file/directory overwriting destination files if requested.  Returns
 * non-zero on error, otherwise zero is returned. */
static int
op_cp(void *data, const char src[], const char dst[], int overwrite)
{
#ifndef _WIN32
	char *escaped_src, *escaped_dst;
	char cmd[6 + PATH_MAX*2 + 1];
	int result;

	escaped_src = escape_filename(src, 0);
	escaped_dst = escape_filename(dst, 0);
	if(escaped_src == NULL || escaped_dst == NULL)
	{
		free(escaped_dst);
		free(escaped_src);
		return -1;
	}

	snprintf(cmd, sizeof(cmd),
			"cp %s -R " PRESERVE_FLAGS " %s %s",
			overwrite ? "" : NO_CLOBBER, escaped_src, escaped_dst);
	LOG_INFO_MSG("Running cp command: \"%s\"", cmd);
	result = background_and_wait_for_errors(cmd);

	free(escaped_dst);
	free(escaped_src);
	return result;
#else
	int ret;

	if(is_dir(src))
	{
		char cmd[6 + PATH_MAX*2 + 1];
		snprintf(cmd, sizeof(cmd), "xcopy \"%s\" \"%s\" ", src, dst);
		to_back_slash(cmd);

		if(is_vista_and_above())
			strcat(cmd, "/B ");
		if(overwrite)
		{
			strcat(cmd, "/Y ");
		}
		strcat(cmd, "/E /I /H /R > NUL");
		ret = system(cmd);
	}
	else
	{
		ret = (CopyFileA(src, dst, 0) == 0);
	}

	return ret;
#endif
}