0

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.

Carlos Reyes
  • 55
  • 1
  • 1
  • 7
  • 1703 is out of support (except the Surface Hub Edition) Does it also occur in 1909? – magicandre1981 Mar 04 '20 at 15:42
  • @magicandre1981 thanks for your response, and this only occurs in 1703 versions, in the 1909 works. Can you show the link that talks about the versions support? – Carlos Reyes Mar 04 '20 at 16:43
  • This is explained [here](https://support.microsoft.com/en-us/help/4018124) **Windows 10, version 1703 has reached end of service for all editions. To continue receiving security and quality updates, Microsoft recommends updating to the latest version of Windows 10**. This page shows last update was [October 2019](https://support.microsoft.com/en-us/help/13853/windows-lifecycle-fact-sheet). 1709 will reach end of support for Enterprise edition in April 2020. So check if your app runs on the supported versiond and LTSB/LTSC versions. – magicandre1981 Mar 04 '20 at 20:48
  • @magicandre1981 finally i found a solution. Thanks for the information – Carlos Reyes Mar 07 '20 at 16:48

1 Answers1

0

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.

Carlos Reyes
  • 55
  • 1
  • 1
  • 7