X Tutup
Skip to content

Commit c9dfd11

Browse files
Specify a user-writable cwd
1 parent 0e19433 commit c9dfd11

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/elevate.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,20 @@ int runas(int argc, char** argv) {
208208
wbail(127, "CreateEnvironmentBlock");
209209
}
210210

211+
wchar_t *ExePath;
212+
toWideChar(argv[4], &ExePath);
213+
214+
wchar_t *DirPath = malloc(sizeof(wchar_t) * MAX_PATH);
215+
DirPath[0] = (wchar_t) '\0';
216+
_wsplitpath(ExePath, NULL, DirPath, NULL, NULL);
217+
218+
if (wcslen(DirPath) == 0) {
219+
GetCurrentDirectoryW(MAX_PATH, DirPath);
220+
}
221+
211222
if (!CreateProcessWithLogonW(wuser, L".", wpassword,
212223
LOGON_WITH_PROFILE, wcommand, wparameters,
213-
CREATE_UNICODE_ENVIRONMENT, lpvEnv, NULL,
224+
CREATE_UNICODE_ENVIRONMENT, lpvEnv, DirPath,
214225
&si, &pi)) {
215226
wbail(127, "CreateProcessWithLogonW");
216227
}

0 commit comments

Comments
 (0)
X Tutup