X Tutup
Skip to content

Commit 747ccc8

Browse files
Include drive in dirpath
1 parent c9dfd11 commit 747ccc8

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/elevate.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,15 +210,33 @@ int runas(int argc, char** argv) {
210210

211211
wchar_t *ExePath;
212212
toWideChar(argv[4], &ExePath);
213+
wprintf(L"ExePath = '%s'\n", ExePath);
214+
215+
wchar_t *Drive = malloc(sizeof(wchar_t) * MAX_PATH);
216+
Drive[0] = (wchar_t) '\0';
217+
218+
wchar_t *DirName = malloc(sizeof(wchar_t) * MAX_PATH);
219+
DirName[0] = (wchar_t) '\0';
213220

214221
wchar_t *DirPath = malloc(sizeof(wchar_t) * MAX_PATH);
215222
DirPath[0] = (wchar_t) '\0';
216-
_wsplitpath(ExePath, NULL, DirPath, NULL, NULL);
217223

218-
if (wcslen(DirPath) == 0) {
224+
_wsplitpath(ExePath, Drive, DirName, NULL, NULL);
225+
226+
if (wcslen(DirName) == 0) {
219227
GetCurrentDirectoryW(MAX_PATH, DirPath);
228+
} else {
229+
wsprintfW(DirPath, L"%s%s", Drive, DirName);
220230
}
221231

232+
int LenDirPath = wcslen(DirPath);
233+
if (DirPath[LenDirPath - 1] == '\\') {
234+
DirPath[LenDirPath - 1] = '\0';
235+
}
236+
237+
wprintf(L"ExePath = '%s'\n", ExePath);
238+
wprintf(L"DirPath = '%s'\n", DirPath);
239+
222240
if (!CreateProcessWithLogonW(wuser, L".", wpassword,
223241
LOGON_WITH_PROFILE, wcommand, wparameters,
224242
CREATE_UNICODE_ENVIRONMENT, lpvEnv, DirPath,

0 commit comments

Comments
 (0)
X Tutup