Skip to content

Instantly share code, notes, and snippets.

@meitinger
Created November 5, 2018 02:13
Show Gist options
  • Save meitinger/5bdf39cbc1e110ee969a48755f9f73f2 to your computer and use it in GitHub Desktop.
Save meitinger/5bdf39cbc1e110ee969a48755f9f73f2 to your computer and use it in GitHub Desktop.
Utility that launches a RemoteApp.
/* Copyright (C) 2018, Manuel Meitinger
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Windows.Forms;
[assembly: AssemblyTitle("RemoteApp")]
[assembly: AssemblyDescription("Utility that launches a RemoteApp.")]
[assembly: AssemblyCompany("AufBauWerk - Unternehmen für junge Menschen")]
[assembly: AssemblyCopyright("Copyright © 2018 by Manuel Meitinger")]
[assembly: AssemblyVersion("1.0.0.1")]
[assembly: ComVisible(false)]
namespace Aufbauwerk.Tools.RemoteApp
{
static class Program
{
[ComImport, Guid("A0B2DD9A-7F53-4E65-8547-851952EC8C96"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
interface IMsRdpSessionManager
{
void StartRemoteApplication([MarshalAs(UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_BSTR)] [In] Array psaCreds, [MarshalAs(UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_BSTR)] [In] Array psaParams, [In] int lFlags);
int GetProcessId();
}
[ComImport, Guid("6B7F33AC-D91D-4563-BF36-0ACCB24E66FB"), ClassInterface(ClassInterfaceType.None)]
class MsRdpSessionManagerSingleUseClass
{
}
[STAThread]
static int Main(string[] args)
{
try
{
var rdp = (IMsRdpSessionManager)new MsRdpSessionManagerSingleUseClass();
rdp.StartRemoteApplication(new string[]
{
@"SERVER\user", @"p@ssw0rd"
}, args, 0);
Marshal.ReleaseComObject(rdp);
return 0;
}
catch (Exception e)
{
MessageBox.Show(e.Message, e.Source, MessageBoxButtons.OK, MessageBoxIcon.Error);
return Marshal.GetHRForException(e);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment