Skip to content
This repository has been archived by the owner on Feb 18, 2021. It is now read-only.

Commit

Permalink
Merge pull request #9 from bojanv/master
Browse files Browse the repository at this point in the history
Added CSharp version of Microsoft Edge Launcher
  • Loading branch information
andysterland committed Dec 11, 2015
2 parents 16cfbbe + f25d5be commit d7d3e22
Show file tree
Hide file tree
Showing 4 changed files with 265 additions and 0 deletions.
6 changes: 6 additions & 0 deletions MIcrosoftEdgeLauncherCsharp/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
</configuration>
60 changes: 60 additions & 0 deletions MIcrosoftEdgeLauncherCsharp/MIcrosoftEdgeLauncherCsharp.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{AFFCAEFD-5CAB-4491-8FAD-4C4363B78528}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MIcrosoftEdgeLauncherCsharp</RootNamespace>
<AssemblyName>MIcrosoftEdgeLauncherCsharp</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
163 changes: 163 additions & 0 deletions MIcrosoftEdgeLauncherCsharp/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;

namespace MIcrosoftEdgeLauncherCsharp
{
/// <summary>
/// Class Program, which allows for Edge to be runned out of
/// </summary>
class Program
{
/// <summary>
/// Edge Application Name
/// </summary>
private const string EdgeName = "Microsoft.MicrosoftEdge_8wekyb3d8bbwe!MicrosoftEdge";

/// <summary>
/// Defines the entry point of the application.
/// </summary>
/// <param name="args">The arguments.</param>
static void Main(string[] args)
{
//call to unmanaged code to activate "modern" app
var launcher = new ApplicationActivationManager();
Debug.WriteLine("Checking args...");
uint pid;
switch (args.Length)
{
case 0:
Debug.WriteLine("calling without arguments...");
launcher.ActivateApplication(EdgeName, null, ActivateOptions.None, out pid);
break;
case 1:
{
var url = args[0];
Debug.WriteLine("calling with url...");
Console.WriteLine(url);
//check, if valid URL
var regex = new Regex(@"^http\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(/\S*)?$");
if (regex.IsMatch(url))
launcher.ActivateApplication(EdgeName,
url,
ActivateOptions.None,
out pid);
else
Console.WriteLine("Enter valid URL. f.e. http://www.bing.com");
break;
}
default:
Console.WriteLine("Application allows ONLY one parameter. Type <MicrosoftEdgeLauncherCsharp.exe http://yourpreferedurl.com> (without <>).");
break;
}

Console.Read();
}

/// <summary>
/// Enum ActivateOptions
/// </summary>
public enum ActivateOptions
{
/// <summary>
/// The none
/// </summary>
None = 0x00000000, // No flags set
/// <summary>
/// The design mode
/// </summary>
DesignMode = 0x00000001, // The application is being activated for design mode, and thus will not be able to
// to create an immersive window. Window creation must be done by design tools which
// load the necessary components by communicating with a designer-specified service on
// the site chain established on the activation manager. The splash screen normally
// shown when an application is activated will also not appear. Most activations
// will not use this flag.
/// <summary>
/// The no error UI
/// </summary>
NoErrorUI = 0x00000002, // Do not show an error dialog if the app fails to activate.
/// <summary>
/// The no splash screen
/// </summary>
NoSplashScreen = 0x00000004, // Do not show the splash screen when activating the app.
}

/// <summary>
/// Interface IApplicationActivationManager
/// </summary>
[ComImport, Guid("2e941141-7f97-4756-ba1d-9decde894a3d"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
interface IApplicationActivationManager
{
// Activates the specified immersive application for the "Launch" contract, passing the provided arguments
// string into the application. Callers can obtain the process Id of the application instance fulfilling this contract.
/// <summary>
/// Activates the application.
/// </summary>
/// <param name="appUserModelId">The application user model identifier.</param>
/// <param name="arguments">The arguments.</param>
/// <param name="options">The options.</param>
/// <param name="processId">The process identifier.</param>
/// <returns>IntPtr.</returns>
IntPtr ActivateApplication([In] String appUserModelId, [In] String arguments, [In] ActivateOptions options, [Out] out UInt32 processId);
/// <summary>
/// Activates for file.
/// </summary>
/// <param name="appUserModelId">The application user model identifier.</param>
/// <param name="itemArray">The item array.</param>
/// <param name="verb">The verb.</param>
/// <param name="processId">The process identifier.</param>
/// <returns>IntPtr.</returns>
IntPtr ActivateForFile([In] String appUserModelId, [In] IntPtr /*IShellItemArray* */ itemArray, [In] String verb, [Out] out UInt32 processId);
/// <summary>
/// Activates for protocol.
/// </summary>
/// <param name="appUserModelId">The application user model identifier.</param>
/// <param name="itemArray">The item array.</param>
/// <param name="processId">The process identifier.</param>
/// <returns>IntPtr.</returns>
IntPtr ActivateForProtocol([In] String appUserModelId, [In] IntPtr /* IShellItemArray* */itemArray, [Out] out UInt32 processId);
}

/// <summary>
/// Class ApplicationActivationManager.
/// </summary>
/// <remarks>
/// implementation was made from community members at stackoverflow http://stackoverflow.com/questions/12925748/iapplicationactivationmanageractivateapplication-in-c
/// </remarks>
[ComImport, Guid("45BA127D-10A8-46EA-8AB7-56EA9078943C")]//Application Activation Manager
class ApplicationActivationManager : IApplicationActivationManager
{
/// <summary>
/// Activates the application.
/// </summary>
/// <param name="appUserModelId">The application user model identifier.</param>
/// <param name="arguments">The arguments.</param>
/// <param name="options">The options.</param>
/// <param name="processId">The process identifier.</param>
/// <returns>IntPtr.</returns>
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)/*, PreserveSig*/]
public extern IntPtr ActivateApplication([In] String appUserModelId, [In] String arguments, [In] ActivateOptions options, [Out] out UInt32 processId);
/// <summary>
/// Activates for file.
/// </summary>
/// <param name="appUserModelId">The application user model identifier.</param>
/// <param name="itemArray">The item array.</param>
/// <param name="verb">The verb.</param>
/// <param name="processId">The process identifier.</param>
/// <returns>IntPtr.</returns>
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
public extern IntPtr ActivateForFile([In] String appUserModelId, [In] IntPtr /*IShellItemArray* */ itemArray, [In] String verb, [Out] out UInt32 processId);
/// <summary>
/// Activates for protocol.
/// </summary>
/// <param name="appUserModelId">The application user model identifier.</param>
/// <param name="itemArray">The item array.</param>
/// <param name="processId">The process identifier.</param>
/// <returns>IntPtr.</returns>
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
public extern IntPtr ActivateForProtocol([In] String appUserModelId, [In] IntPtr /* IShellItemArray* */itemArray, [Out] out UInt32 processId);
}
}
}
36 changes: 36 additions & 0 deletions MIcrosoftEdgeLauncherCsharp/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("MIcrosoftEdgeLauncherCsharp")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MIcrosoftEdgeLauncherCsharp")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("affcaefd-5cab-4491-8fad-4c4363b78528")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

0 comments on commit d7d3e22

Please sign in to comment.