Использование C#, как программно создавать подключенные диски в сеансе удаленного рабочего стола для вошедшего в систему пользователя. - PullRequest
0 голосов
/ 08 января 2020

У нас есть программа запуска на рабочих станциях, которая запускает удаленное приложение, используя rdp. Мы пытаемся запустить интегрированный процесс с помощью элемента управления activex MsRdpWebAccess. Вот мой метод, который подключает и запускает сеанс rdp для пользователя.

private bool TryLaunchActiveX(string rdpBaseContent, string username, string password)
{
    string workspaceId = $"{AppUtilities.RdSetting.RdFarmAddress}-{username}";
    string workspaceFriendlyName = $"{AppUtilities.RdSetting.FriendlyNamePrefix} ({username})";
    string localRdp = rdpBaseContent.Replace($"workspace id:s:{AppUtilities.RdSetting.RdFarmAddress}", $"workspace id:s:{workspaceId}");

    try
    {
        MsRdpWebAccessLib.IMsRdpClientShell2 rdpClientTwo = new MsRdpWebAccessLib.MsRdpClientShell();
        rdpClientTwo.PublicMode = false;

        // The raw .rdp content
        rdpClientTwo.RdpFileContents = localRdp;

        // See if we're on a machine that supports the advanced COM interface
        MsRdpWebAccessLib.IMsRdpWorkspace2 rdpWorkspaceEx;
        try
        {
            MsRdpWebAccessLib.IMsRdpClientShell3 rdpClientThree = (MsRdpWebAccessLib.IMsRdpClientShell3)rdpClientTwo;
            rdpWorkspaceEx = rdpClientThree.MsRdpWorkspace2;
        }
        catch (Exception e)
        {
            log.Debug("Interface IMsRdpClientShell3 not supported", e);
            rdpWorkspaceEx = null;
        }

        // Start the workspace. Use the advanced interface if we have it, otherwise we just get a less 
        // friendly name but it still works fine.
        if (rdpWorkspaceEx != null)
        {
            // Yep, we're advanced, so we can use a friendlier workspace name
            log.Debug($"Starting workspace '{workspaceId}' with friendly name {workspaceFriendlyName} using 'rdpClient3'.");
            rdpWorkspaceEx.StartWorkspaceEx(workspaceId, workspaceFriendlyName, "", username, password, nextechAppCertThumbprint, minutesToKeepWorkspaceOpenAfterDisconnect, 0);
        }
        else
        {
            // Nope, no friendly name, just use the raw name by itself, which is decent enough
            log.Debug($"Starting workspace '{workspaceId}' using 'rdpClient2'.");
            rdpClientTwo.MsRdpWorkspace.StartWorkspace(workspaceId, username, password, nextechAppCertThumbprint, minutesToKeepWorkspaceOpenAfterDisconnect, 0);
        }

        // Tell the workspace to authenticate the password we gave it for this username above, saving 
        // the end user from having to enter it again.
        log.Debug($"Pre-authenticating user '{username}' in workspace '{workspaceId}'.");
        rdpClientTwo.MsRdpWorkspace.OnAuthenticated(workspaceId, username);

        // Finally launch!
        log.Debug($"Launching rdp client in workspace '{workspaceId}'.");
        rdpClientTwo.Launch();

        // If we made it here, we were successful
        return true;
    }
    catch (Exception e)
    {
        // On any exception, just fail gracefully and let the caller launch the old way
        log.Error($"Could not launch workspace '{workspaceId}' due to error:\r\n{e}");
        return false;
    }
}

Я не уверен, что после аутентификации пользователя и установления канала rd, как мне создать подключенный диск для вошедшего в систему пользователя? Любая помощь будет высоко ценится.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...