Reputation: 55
I have the following code, where I raise a process using other Windows credentials provided in an external source.
Code:
public static void ImpersonateProcess_WithProfile(string appPath, string domain,
string user, string password)
{
ImpersonateProcess(appPath, domain, user, password, LogonFlags.LOGON_WITH_PROFILE);
}
private static void ImpersonateProcess(string appPath, string domain, string user,
string password, LogonFlags lf)
{
StartupInfo si = new StartupInfo();
si.cb = Marshal.SizeOf(typeof(StartupInfo));
ProcessInfo pi = new ProcessInfo();
if (CreateProcessWithLogonW(user, domain, password,
lf,
appPath, null,
0, IntPtr.Zero, null,
ref si, out pi))
{
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
}
else
{
throw new System.ComponentModel.Win32Exception(Marshal.GetLastWin32Error());
}
}
This program works perfectly for me in the version of windows 7,8 and 10 ..
But in windows 10 version 1703 I am dealing with an error by date format (Said error thrown by validations of the running process) .. I do not understand why this happens only with this version.
The error comes because the running process expects the date format to be dd / MM / yyyy. But I repeat this only happens to me only in this version of Windows 10 and sharing the same date format in all the versions I've tried.
Upvotes: 0
Views: 164
Reputation: 55
Finally i found a solution that helped me.
I just create a bat file where i change the system date format and then i run my .exe
@echo off
reg add "HKCU\Control Panel\International" /f /v sShortDate /t REG_SZ /d "dd/MM/yyyy" >nul
app.exe
This works for me.
Upvotes: 0