我有以下代码,其中我使用外部源中提供的其他 Windows 凭据引发了一个进程。
代码:
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());
}
}
该程序在 Windows 7,8 和 10 版本中非常适合我..
但在 Windows 10 版本 1703 中,我正在处理按日期格式显示的错误(运行过程的验证引发的错误).. 我不明白为什么这只发生在这个版本中。
出现错误是因为正在运行的进程期望日期格式为 dd / MM / yyyy。但我再说一遍,这只发生在这个版本的 Windows 10 中,并且在我尝试过的所有版本中共享相同的日期格式。