BOOL ConvertVirtualStoreConf(void *execDirV, void *userDirV, void *virtualDirV) { #define FASTCOPY_INI_W L"FastCopy.ini" WCHAR buf[MAX_PATH]; WCHAR org_ini[MAX_PATH], usr_ini[MAX_PATH], vs_ini[MAX_PATH]; BOOL is_admin = TIsUserAnAdmin(); BOOL is_exists; MakePathV(usr_ini, userDirV, FASTCOPY_INI_W); MakePathV(org_ini, execDirV, FASTCOPY_INI_W); #ifdef _WIN64 ConvertToX86Dir(org_ini); #endif is_exists = GetFileAttributesV(usr_ini) != 0xffffffff; if (!is_exists) { CreateDirectoryV(userDirV, NULL); } if (virtualDirV && GetChar(virtualDirV, 0)) { MakePathV(vs_ini, virtualDirV, FASTCOPY_INI_W); if (GetFileAttributesV(vs_ini) != 0xffffffff) { if (!is_exists) { is_exists = ::CopyFileW(vs_ini, usr_ini, TRUE); } MakePathV(buf, userDirV, L"to_OldDir(VirtualStore).lnk"); SymLinkV(virtualDirV, buf); sprintfV(buf, L"%s.obsolete", vs_ini); MoveFileW(vs_ini, buf); if (GetFileAttributesV(vs_ini) != 0xffffffff) { DeleteFileV(vs_ini); } } } if ((is_admin || !is_exists) && GetFileAttributesV(org_ini) != 0xffffffff) { if (!is_exists) { is_exists = ::CopyFileW(org_ini, usr_ini, TRUE); } if (is_admin) { sprintfV(buf, L"%s.obsolete", org_ini); MoveFileW(org_ini, buf); if (GetFileAttributesV(org_ini) != 0xffffffff) { DeleteFileV(org_ini); } } } MakePathV(buf, userDirV, L"to_ExeDir.lnk"); // if (GetFileAttributesV(buf) == 0xffffffff) { SymLinkV(execDirV, buf); // } return TRUE; }
BOOL TMakeVirtualStorePathV(void *org_path, void *buf) { if (!IsWinVista()) return FALSE; if (!TIsVirtualizedDirV(org_path) || !TSHGetSpecialFolderPathV(NULL, buf, CSIDL_LOCAL_APPDATA, FALSE) || GetChar(org_path, 1) != ':' || GetChar(org_path, 2) != '\\') { strcpyV(buf, org_path); return FALSE; } sprintfV(MakeAddr(buf, strlenV(buf)), L"\\VirtualStore%s", MakeAddr(org_path, 2)); return TRUE; }
BOOL TInstDlg::RunAsAdmin(BOOL is_imme) { SHELLEXECUTEINFOW sei = {0}; WCHAR buf[MAX_PATH * 2]; WCHAR exe_path[MAX_PATH]; WCHAR setup_path[MAX_PATH]; WCHAR app_data[MAX_PATH]; WCHAR virtual_store[MAX_PATH]; WCHAR fastcopy_dir[MAX_PATH]; WCHAR *fastcopy_dirname = NULL; int len; ::GetModuleFileNameW(NULL, exe_path, sizeof(exe_path)); if (!(len = GetDlgItemTextV(FILE_EDIT, setup_path, MAX_PATH))) return FALSE; if (GetChar(setup_path, len-1) == '\\') SetChar(setup_path, len-1, 0); if (!GetFullPathNameW(setup_path, MAX_PATH, fastcopy_dir, &fastcopy_dirname)) return FALSE; if (!TSHGetSpecialFolderPathV(NULL, buf, CSIDL_APPDATA, FALSE)) return FALSE; MakePathV(app_data, buf, fastcopy_dirname); strcpyV(buf, fastcopy_dir); #ifdef _WIN64 ConvertToX86Dir(buf); #endif if (!TMakeVirtualStorePathV(buf, virtual_store)) return FALSE; sprintfV(buf, L"/runas=%p,%d,%d,%d,%d,\"%s\",\"%s\",\"%s\",\"%s\",\"%s\"", hWnd, cfg.mode, is_imme, cfg.programLink, cfg.desktopLink, cfg.startMenu, cfg.deskTop, setup_path, app_data, virtual_store); sei.cbSize = sizeof(SHELLEXECUTEINFO); sei.lpVerb = L"runas"; sei.lpFile = exe_path; sei.lpDirectory = NULL; sei.nShow = SW_NORMAL; sei.lpParameters = buf; EnableWindow(FALSE); BOOL ret = ::ShellExecuteExW(&sei); EnableWindow(TRUE); return ret; }