Starting a new user session from a service

老子叫甜甜 提交于 2019-12-06 03:40:04

问题


I have the following problem:

From a service I need to start an application in a user session. No human user log on that machine, since it is a server. Launched application must have a session != 0.

Current "solution"

I used a scheduled task at machine startup, that task launch ( in session 0, of course ) an application launching a Remote Desktop logon on the same machine: this creates a user session > 0 and in the user startup the is the final application to launch. It works, but too tricky.

Is there some smartest way? It is critical that I can reuse a user session already on since there is potentially no user logged on.

MAJOR UPDATE

Well after a lot of research and partial successes, and also thanks to some SysAdmin inflexibility about creating an user for a specific pourpose, I decided to use OpenGL instead of WPF for render the 3d portion broken in Session 0. Surprisingly it took less than expected. I think having this question as a reference could be useful to other who want try to render a Viewport3D from a service.


回答1:


I'm not sure if this will work, but maybe this answer helps in your case.

Use the class from the answer I link i provided and the following method (with the appropriate values):

public static void EnableVideoDrivers(bool enable)
{
    // every type of device has a hard-coded GUID, put here the one for
    // video drivers
    Guid videoGuid = new Guid("{device GUID}");

    // get this from the properties dialog box of this device in Device Manager
    string instancePath = @"Device Instance Path";

    DeviceHelper.SetDeviceEnabled(videoGuid, instancePath, enable);
}

Here's a list of Popular Device Class GUIDs.




回答2:


I'm not sure I understand correctly your needs, but maybe just starting process with given credentials and redirect input and output is what you need. Starting process with given credentials:

  Process p = new Process();

  p.StartInfo = new ProcessStartInfo(fileName, args);
  p.StartInfo.UserName = userName;
  p.StartInfo.Password = pass;

  p.Start();

You may also need to redirect input and output of the application. That problem is well described on CodeProjecgt in this artice.



来源:https://stackoverflow.com/questions/15113901/starting-a-new-user-session-from-a-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!