0

I had to deploy UWP app says examples “OfflineFacialLogin”, I am able to launch “OfflineFacialLogin” manually from the command prompt like this

“C:\Windows\System32>OfflineFacialLogin”

and same code works debug environment with below code.

var proc = new ProcessStartInfo();
string yourCommand;
yourCommand = OfflineFacialLogin.exe”;
proc.UseShellExecute = true;
proc.WorkingDirectory = @”C:\Windows\System32″;
proc.FileName = @”C:\Windows\System32\cmd.exe”;
proc.Arguments = “/c ” + yourCommand;
proc.WindowStyle = ProcessWindowStyle.Normal;process.Start(proc);

But after placing this code dll in system32 or syswow folder and restarting machine I don't UWP app OfflineFacialLogin is not launching, what could be reason

I want to OfflineFacialLogin will be firing up during the windows login, so I have written above code snippet on successful login and then launching UWP app

Siddhanta Rath
  • 976
  • 3
  • 21
  • 37
Pradeepa
  • 1
  • 2

1 Answers1

1

If you want to start the UWP application from the command line, you need to set an alias for the UWP application instead of waking up by calling the exe file.

Command-Line Activation of Universal Windows Apps

According to your description, you want to start the UWP application after booting, this can be done through StartupTask.

StartupTask

package.appxmanifest

<Package xmlns:uap5="http://schemas.microsoft.com/appx/manifest/uap/windows10/5" ...>
...
<Applications>
    <Application ...>
        ...
        <Extensions>
          <uap5:Extension Category="windows.startupTask">
            <uap5:StartupTask
              TaskId="MyStartupId"
              Enabled="false"
              DisplayName="Test startup" />
          </uap5:Extension>
      </Extensions>
    </Application>
</Applications>

The following code creates a StartupTask:

StartupTask startupTask = await StartupTask.GetAsync("MyStartupId"); // Pass the task ID you specified in the appxmanifest file
switch (startupTask.State)
{
    case StartupTaskState.Disabled:
        // Task is disabled but can be enabled.
        StartupTaskState newState = await startupTask.RequestEnableAsync(); // ensure that you are on a UI thread when you call RequestEnableAsync()
        Debug.WriteLine("Request to enable startup, result = {0}", newState);
        break;
    case StartupTaskState.DisabledByUser:
        // Task is disabled and user must enable it manually.
        MessageDialog dialog = new MessageDialog(
            "You have disabled this app's ability to run " +
            "as soon as you sign in, but if you change your mind, " +
            "you can enable this in the Startup tab in Task Manager.",
            "TestStartup");
        await dialog.ShowAsync();
        break;
    case StartupTaskState.DisabledByPolicy:
        Debug.WriteLine("Startup disabled by group policy, or not supported on this device");
        break;
    case StartupTaskState.Enabled:
        Debug.WriteLine("Startup is enabled.");
        break;
}

App.xaml.cs

protected override void OnLaunched(LaunchActivatedEventArgs e)
{
    ...
    if (e.Kind == ActivationKind.StartupTask)
    {
        // DO SOMTHING
    }
    ...
}

By adding StartupTask, after the user allows, the system will automatically start the UWP application after login.

halfer
  • 19,824
  • 17
  • 99
  • 186
Richard Zhang
  • 7,523
  • 1
  • 7
  • 13
  • @Siddhanta Rath thanks for the reply.......... i have already created UWP facial login app, and trying to launch it from in Custom credential provider applcation(DotNet project-as an option for login to the windows10) . I am able to launch in visual studio IDE but when i deploy the custom credential manager and restart the machine i am able to see Custom provider windows login screen, after entering the username and password, i am trying launch to UWP (Facial login app), but its not launching. – Pradeepa Jul 15 '20 at 12:27
  • 1
    Hello, if you are using `ProcessStartInfo` to start a UWP application in your .Net project, this is no different from starting from the command line. You can refer to the documentation I provided to add an alias in the UWP project to start it from the code. Generally speaking, UWP will be in the WindowsApp folder, which is protected. – Richard Zhang Jul 15 '20 at 12:32
  • My requirement is ---------------------------------- Enter Username and password in Custom credential provider(C# project) Launch UWP App (OfflineFacialLogin.exe)(UWP APP) Capture face and send call back result to custom credentail provider Based on result Windows Login should be either successfull or fail. I am failing to launch OfflineFacialLogin app.so that unable to capture facial and send back result. – Pradeepa Jul 15 '20 at 12:43
  • Richard Zhang thanks for comments, i have added alias name. – Pradeepa Jul 15 '20 at 12:45
  • Hello, Is there any error message after the UWP application failed to start through the alias method? The UWP application depends on some local components. When you try to start the UWP application, it may not start because the local dependencies have not been loaded. As test, you can try to wait for a while after normal login and then try to start UWP application through `ProcessStartInfo`. – Richard Zhang Jul 15 '20 at 13:02
  • Hi Richard, there are no errors and UWP app also not launching, I am able successfully login and control goes to desktop. as part of test i have also starting Winform app, its launching but UWP not. – Pradeepa Jul 15 '20 at 13:15
  • Hello, I tried to create a console application based on `.net core 3.1`, and use the code you provided to start the UWP application, which can work normally. After moving the dll related files generated by the console application into the System32 folder, the associated UWP application can also be started normally after restarting. Can you describe your recurring steps in detail and provide a sample that can reproduce the problem, That will help a lot. – Richard Zhang Jul 15 '20 at 14:41
  • Richard thanks for the reply, please find the recurring steps that i have mentioned in below comments – Pradeepa Jul 16 '20 at 11:35
  • I have used this github code https://github.com/SteveSyfuhs/CredProvider.NET. after download code from this path i have added below code in CredentialProviderCredential.cs file SetSelected method – Pradeepa Jul 16 '20 at 11:35
  • public virtual int SetSelected(out int pbAutoLogon) { Logger.Write(); var proc = new ProcessStartInfo(); string yourCommand; yourCommand = "OfflineFacialLogin.exe"; proc.UseShellExecute = true; proc.WorkingDirectory = @"C:\Windows\SysWOW64"; proc.FileName = @"C:\Windows\SysWOW64\cmd.exe"; proc.Arguments = "/c " + yourCommand; proc.WindowStyle = ProcessWindowStyle.Normal; Process.Start(proc); pbAutoLogon = 1; return HRESULT.S_OK;} – Pradeepa Jul 16 '20 at 11:36
  • I have Rebuild this project and deployed CredProvider.NET.dll in system32 and syswow folder. I have done registry install.reg I have Created OfflineFacialLogin.exe UWP and deployed. from cmd line(C:\Windows\SysWOW64>OfflineFacialLogin) i am able to launch UWP app I will restart machine. When i select "click me" in windows login i should get popup "OfflineFacialLogin" app to open. All these should work before i login to system and windwos control goes to desktop, – Pradeepa Jul 16 '20 at 11:36
  • any solution that i am facing right now, is recurring steps are clear? – Pradeepa Jul 17 '20 at 06:57
  • Hello, Sorry for the late reply, I checked the demo you provided, but some key references seem to be missing in the project, such as `CredProvider.NET.Interop`. In addition, if you can successfully start the application through the alias, the UWP side should work normally. It cannot start when you log in through a custom authentication program. It may be a design behavior. You can report the problem in the Feedback Hub application. – Richard Zhang Jul 17 '20 at 07:57
  • thanks for the reply, under project there is midl folder, in there CredProvider.NET.Interop2 there, you can reference and change accordingly in cs files – Pradeepa Jul 17 '20 at 10:08