Пример #1
0
        public bool Gestured(PointInfo actionPoint)
        {
            if (AppInfo.Key == null)
            {
                return(false);
            }
            ApplicationActivationManager appActiveManager = new ApplicationActivationManager();

            try
            {
                uint pid;
                appActiveManager.ActivateApplication(AppInfo.Key, null, ActivateOptions.None, out pid);
            }
            catch
            {
                // ignored
            }
            //IShellItemArray array = GetShellItemArray(@"C:\temp\somefile.xyz");
            //appActiveManager.ActivateForFile("2c123c17-8b21-4eb8-8b7f-fdc35c8b7718_n2533ggrncqjt!App", array, "Open",
            //    out pid);


            //Process explorer = new Process();
            //explorer.StartInfo.FileName = "explorer.exe";
            //explorer.StartInfo.Arguments = @"shell:AppsFolder\" + AppInfo.Key;
            //explorer.Start();

            return(true);
        }
Пример #2
0
        static void ActivateFile(string appUserModelId, string path)
        {
            var appActiveManager = new ApplicationActivationManager();
            var items            = SHCreateShellItemArrayFromParsingName(path);

            appActiveManager.ActivateForFile(appUserModelId, items, "Open", out uint _);
        }
        // Tells the OS to take a package out of "debugging" mode.  This resets the intent
        // to pass environment variables to the package and allows the package to be suspended
        // by the OS in the future, as usual.
        static public void DisableDebuggingForPackage(string packgeFullName)
        {
            IApplicationActivationManager appActivationMgr = new ApplicationActivationManager();
            IPackageDebugSettings         pkgDebugSettings = new PackageDebugSettings();

            pkgDebugSettings.DisableDebugging(packgeFullName);
        }
Пример #4
0
        /// <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();
        }
Пример #5
0
        protected override Task ExecuteAsync(FileResult result)
        {
            if (result.Path != null)
            {
                var path = WebUtility.UrlDecode(result.Path.AbsolutePath).TrimStart('/');

                if (result.Path.Scheme == "shell")
                {
                    Process.Start(path);
                }
                else if (result.Path.Scheme == "uwp")
                {
                    var queryString = result.Path.GetQueryString();
                    if (queryString.TryGetValue("aumid", out var values))
                    {
                        var aumid = values?.FirstOrDefault();
                        if (aumid != null)
                        {
                            var manager = new ApplicationActivationManager();
                            manager.ActivateApplication(aumid, null, ACTIVATEOPTIONS.AO_NONE, out var _);
                        }
                    }
                }
            }

            return(Task.CompletedTask);
        }
Пример #6
0
    //This class was built using info from this SO question 
    //http://stackoverflow.com/questions/12925748/iapplicationactivationmanageractivateapplication-in-c
    private static String getOcr(string fileName)
    {
        ApplicationActivationManager appActiveManager = new ApplicationActivationManager();//Class not registered
        uint pid;
        //The first arg in ActivateApplication is found in your registry at
        //HKEY_CURRENT_USER\Software\Classes\ActivatableClasses\Package\Some_Sort_Of_Guid\Server\App.App....\AppUserModelId
        appActiveManager.ActivateApplication("2ca0072b-e230-42c2-a5f2-6ee47ccce84d_yekwsnrkhg0pr!App", fileName, ActivateOptions.NoSplashScreen, out pid);
        System.Diagnostics.Process proc = null;
        foreach (var p in System.Diagnostics.Process.GetProcesses())
        {
            if (p.Id == pid)
            {
                proc = p;
            }
        }
        while (!proc.HasExited)
        {
            System.Threading.Thread.Sleep(100);
        }

        string outputPath = UPLOAD_ROOT + fileName + ".txt";
        if (File.Exists(outputPath))
        {
            Debug.Print(outputPath + " exists");
            return File.ReadAllText(outputPath);

        }
        Debug.Print(outputPath + " does not exists");
        return "{}";
    }
Пример #7
0
        public bool Gestured(PointInfo actionPoint)
        {
            if (AppInfo.Key == null) return false;
            ApplicationActivationManager appActiveManager = new ApplicationActivationManager();
            try
            {
                uint pid;
                appActiveManager.ActivateApplication(AppInfo.Key, null, ActivateOptions.None, out pid);
            }
            catch
            {
                // ignored
            }
            //IShellItemArray array = GetShellItemArray(@"C:\temp\somefile.xyz");
            //appActiveManager.ActivateForFile("2c123c17-8b21-4eb8-8b7f-fdc35c8b7718_n2533ggrncqjt!App", array, "Open",
            //    out pid);


            //Process explorer = new Process();
            //explorer.StartInfo.FileName = "explorer.exe";
            //explorer.StartInfo.Arguments = @"shell:AppsFolder\" + AppInfo.Key;
            //explorer.Start();

            return true;
        }
        // "Unsafe" so we can very easily pass environmentPzz (a string with embedded nulls)
        // to Win32 as an IntPtr
        unsafe static public void SpawnWindowsStoreAppProcess(string packgeFullName, string appUserModelId, string appArgs, string[] environment, out uint pid)
        {
            IApplicationActivationManager appActivationMgr = new ApplicationActivationManager();
            IPackageDebugSettings         pkgDebugSettings = new PackageDebugSettings();

            // NOTE: If you'd like to step through the native profiler DLL's startup, use a
            // string like this instead of the WindowsStoreAppThreadResumer string below
            //string debuggerCommandLine = "C:\\debuggers\\windbg.exe";

            string debuggerCommandLine = Path.Combine(
                Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName),
                "CLRProfilerWindowsStoreAppThreadResumer.exe");

            if (!File.Exists(debuggerCommandLine))
            {
                pid = unchecked ((uint)-1);
                MessageBox.Show(
                    string.Format(
                        "Cannot launch Windows Store app, because the following file is missing: '{0}'",
                        debuggerCommandLine));
                return;
            }

            ushort[] environmentPzz = StringArrayToPzz(environment);

            fixed(ushort *fixedEnvironmentPzz = environmentPzz)
            {
                pkgDebugSettings.EnableDebugging(packgeFullName, debuggerCommandLine, (IntPtr)fixedEnvironmentPzz);
            }

            appActivationMgr.ActivateApplication(appUserModelId, appArgs, ACTIVATEOPTIONS.AO_NONE, out pid);
        }
Пример #9
0
        public static void RunApplication(string app)
        {
            ApplicationActivationManager appActiveManager = new ApplicationActivationManager();//Class not registered
            uint pid;

            appActiveManager.ActivateApplication(app, null, ActivateOptions.None, out pid);
        }
        // Tells the OS to put the package in "debugging" mode, which ensures it does not
        // get suspended.  This is mainly used for attach, where environment variables are
        // not to be passed to the profilee.  For launch-profiling, SpawnWindowsStoreAppProcess()
        // also puts the package in debugging mode, but passes environment variables as well.
        static public void EnableDebuggingForPackage(string packageFullName)
        {
            IApplicationActivationManager appActivationMgr = new ApplicationActivationManager();
            IPackageDebugSettings         pkgDebugSettings = new PackageDebugSettings();

            pkgDebugSettings.EnableDebugging(packageFullName, null /* debugger cmd line */, IntPtr.Zero /* environment */);
            pkgDebugSettings.Resume(packageFullName);
        }
Пример #11
0
    static void Main(string[] args)
    {
        ApplicationActivationManager appActiveManager = new ApplicationActivationManager();                //Class not registered
        uint pid;

        appActiveManager.ActivateApplication("2c123c17-8b21-4eb8-8b7f-fdc35c8b7718_n2533ggrncqjt!App", null, ActivateOptions.None, out pid);
        Console.WriteLine();
        Console.ReadLine();
    }
Пример #12
0
        static void ActivateApp(string appUserModelId, string[] args)
        {
            var appActiveManager = new ApplicationActivationManager();
            var argsString       = string.Join(
                " ",
                args.Select(a => "\"" + a.Replace("\\", "\\\\").Replace("\"", "\\\"") + "\""));

            appActiveManager.ActivateApplication(appUserModelId, argsString, ActivateOptions.None, out _);
        }
Пример #13
0
        public ezTestUWP(string ezWorkspace, string testOutputPath,
                         string configuration, string platform, string project)
        {
            _ezWorkspace            = ezWorkspace;
            _absTestOutputDirectory = testOutputPath;
            _configuration          = configuration;
            _platform = platform;
            _project  = project;

            // May fail with an exception.
            appActiveManager = new ApplicationActivationManager();
        }
        public static Process Launch(string appUserModelId, string arguments)
        {
            var  launcher = new ApplicationActivationManager();
            uint processId;

            launcher.ActivateApplication(appUserModelId, arguments, ActivateOptions.None, out processId);
            if (processId > 0)
            {
                return(Process.GetProcessById((int)processId));
            }
            throw new Exception(String.Format("Could not launch Store App '{0}'", appUserModelId));
        }
Пример #15
0
        /// <summary>
        /// Launches an app
        /// </summary>
        /// <param name="appUserModelId">something like (%package_family_name% + "!App"_</param>
        public static Application LaunchWindows8Application(string appUserModelId)
        {
            IApplicationActivationManager appActiveManager = new ApplicationActivationManager();
            // This call ensures that the app is launched as the foreground window
            //CoAllowSetForegroundWindow(appActiveManager, IntPtr.Zero);

            uint pid;

            appActiveManager.ActivateApplication(appUserModelId, null, ActivateOptions.None, out pid);

            return(Attach((int)pid));
        }
Пример #16
0
        public static void Activate(string appId, string file, string verb)
        {
            ApplicationActivationManager appActiveManager = new ApplicationActivationManager();//Class not registered
            IShellItem pShellItem = SafeNativeMethods.SHCreateItemFromParsingNameIShellItem(file, IntPtr.Zero, typeof(IShellItem).GUID);

            if (pShellItem != null)
            {
                if (SafeNativeMethods.SHCreateShellItemArrayFromShellItem(pShellItem, typeof(IShellItemArray).GUID, out IShellItemArray pShellItemArray) == (int)HResult.Ok)
                {
                    appActiveManager.ActivateForFile(appId, pShellItemArray, verb, out _);
                }
            }
        }
Пример #17
0
        private void LaunchAumidButton_Click(object sender, RoutedEventArgs e)
        {
            var aam = new ApplicationActivationManager() as IApplicationActivationManager;

            try
            {
                aam.ActivateApplication("ShellLauncherV2DemoAnotherUwp_5d7tap497jwe8!App", "", ActivateOptions.None);
            }
            catch (Exception)
            {
                // if the app is not installed, an exception will throw, catch it so the app won't crash
            }
        }
 private static void Main(string[] args)
 {
     ApplicationActivationManager appActiveManager = new ApplicationActivationManager();//Class not registered
     uint pid;
     appActiveManager.ActivateApplication("2c123c17-8b21-4eb8-8b7f-fdc35c8b7718_n2533ggrncqjt!App", null, ActivateOptions.None, out pid);
     Console.WriteLine("Activated");
     Console.ReadLine();
     
     IShellItemArray array = GetShellItemArray(@"C:\temp\somefile.xyz");
     appActiveManager.ActivateForFile("2c123c17-8b21-4eb8-8b7f-fdc35c8b7718_n2533ggrncqjt!App", array, "Open",
         out pid);
     Console.WriteLine("Activated for file");
     Console.ReadLine();
 }
Пример #19
0
        /// <summary>
        /// Launch the store app with the given id and arguments.
        /// </summary>
        /// <param name="appUserModelId">The app id of the application to launch.</param>
        /// <param name="arguments">The arguments to pass to the application.</param>
        /// <returns>The process of the launched application.</returns>
        public static Process Launch(string appUserModelId, string arguments)
        {
            var launcher = new ApplicationActivationManager();
            var hr       = launcher.ActivateApplication(appUserModelId, arguments, ActivateOptions.None, out var processId).ToInt32();

            if (hr < 0)
            {
                Marshal.ThrowExceptionForHR(hr);
            }
            if (processId > 0)
            {
                return(Process.GetProcessById((int)processId));
            }
            throw new Exception($"Could not launch Store App '{appUserModelId}'");
        }
Пример #20
0
    public static int Main(string[] args)
    {
        if (args.Length == 0)
        {
            Console.WriteLine("Usage: ActivateStoreApp <AppUserModelId>");
            return(1);
        }

        ApplicationActivationManager appActiveManager = new ApplicationActivationManager();
        uint pid;

        appActiveManager.ActivateApplication(args[0], null, ActivateOptions.None, out pid);
        Console.WriteLine("Process ID: {0}", pid);
        return(0);
    }
Пример #21
0
        public override Process Start()
        {
            IntPtr shellItem  = IntPtr.Zero;
            Guid   IShellItem = new Guid("43826d1e-e718-42ee-bc55-a1e261c37bfe");

            SHCreateItemFromParsingName(this.File.FilePath, IntPtr.Zero, IShellItem, out shellItem);
            Guid   IShellItemArray = new Guid("B63EA76D-1F85-456F-A19C-48159EFA858B");
            IntPtr shellItemArray  = IntPtr.Zero;

            SHCreateShellItemArrayFromShellItem(shellItem, IShellItemArray, out shellItemArray);
            ApplicationActivationManager aam = new ApplicationActivationManager();
            uint procId;

            aam.ActivateForFile(this.AppUserModelID, shellItemArray, "open", out procId);
            return(Process.GetProcessById((int)procId));
        }
Пример #22
0
 private void Launch(IPublicAPI api)
 {
     try
     {
         var                   appManager = new ApplicationActivationManager();
         uint                  unusedPid;
         const string          noArgs  = "";
         const ACTIVATEOPTIONS noFlags = ACTIVATEOPTIONS.AO_NONE;
         appManager.ActivateApplication(UserModelId, noArgs, noFlags, out unusedPid);
     }
     catch (Exception)
     {
         var name    = "Plugin: Program";
         var message = $"Can't start UWP: {DisplayName}";
         api.ShowMsg(name, message, string.Empty);
     }
 }
Пример #23
0
        private void Launch(string id, string profile)
        {
            var appManager = new ApplicationActivationManager();
            const ActivateOptions noFlags = ActivateOptions.None;
            var queryArguments            = TerminalHelper.GetArguments(profile, _openNewTab);

            try
            {
                appManager.ActivateApplication(id, queryArguments, noFlags, out var unusedPid);
            }
            catch (Exception ex)
            {
                var name    = "Plugin: " + Resources.plugin_name;
                var message = Resources.run_terminal_failed;
                Log.Exception("Failed to open Windows Terminal", ex, GetType());
                _context.API.ShowMsg(name, message, string.Empty);
            }
        }
Пример #24
0
 //This class was built using info from this SO question 
 // http://stackoverflow.com/questions/12925748/iapplicationactivationmanageractivateapplication-in-c
 public static void StartOcr(string fileName)
 {
     ApplicationActivationManager appActiveManager = new ApplicationActivationManager();
     uint pid;
     appActiveManager.ActivateApplication(Config.BOCRWindowAppPackage, fileName, ActivateOptions.NoSplashScreen, out pid);
     System.Diagnostics.Process proc = null;
     foreach (var p in System.Diagnostics.Process.GetProcesses())
     {
         if (p.Id == pid)
         {
             proc = p;
         }
     }
     while (!proc.HasExited)
     {
         System.Threading.Thread.Sleep(100);
     }
 }
Пример #25
0
        /// <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();
        }
Пример #26
0
        static void Main(string[] args)
        {
            ApplicationActivationManager appActiveManager = new ApplicationActivationManager();//Class not registered

            try
            {
                uint pid;
                appActiveManager.ActivateApplication("f41b88ad-fb57-433c-863c-75e6978e7627_e8xk87pxx0yyw!App", null, ActivateOptions.None, out pid);
                Console.WriteLine("App is installed");
                Environment.Exit(0); // exit the app now since the UWP app was launched
            }
            catch (Exception e)
            {
                Console.WriteLine("App is not installed: " + e.Message);
            }
            Console.WriteLine();
            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }
Пример #27
0
 //This class was built using info from this SO question 
 //http://stackoverflow.com/questions/12925748/iapplicationactivationmanageractivateapplication-in-c
 public static void StartOcr(string fileName)
 {
     ApplicationActivationManager appActiveManager = new ApplicationActivationManager();//Class not registered
     uint pid;
     //The first arg in ActivateApplication is found in your registry at
     //HKEY_CURRENT_USER\Software\Classes\ActivatableClasses\Package\Some_Sort_Of_Guid\Server\App.App....\AppUserModelId
     appActiveManager.ActivateApplication("2ca0072b-e230-42c2-a5f2-6ee47ccce84d_yekwsnrkhg0pr!App", fileName, ActivateOptions.NoSplashScreen, out pid);
     System.Diagnostics.Process proc = null;
     foreach (var p in System.Diagnostics.Process.GetProcesses())
     {
         if (p.Id == pid)
         {
             proc = p;
         }
     }
     while (!proc.HasExited)
     {
         System.Threading.Thread.Sleep(100);
     }
 }
Пример #28
0
    //This class was built using info from this SO question
    //http://stackoverflow.com/questions/12925748/iapplicationactivationmanageractivateapplication-in-c
    public static void StartOcr(string fileName)
    {
        ApplicationActivationManager appActiveManager = new ApplicationActivationManager();//Class not registered
        uint pid;

        //The first arg in ActivateApplication is found in your registry at
        //HKEY_CURRENT_USER\Software\Classes\ActivatableClasses\Package\Some_Sort_Of_Guid\Server\App.App....\AppUserModelId
        appActiveManager.ActivateApplication("2ca0072b-e230-42c2-a5f2-6ee47ccce84d_yekwsnrkhg0pr!App", fileName, ActivateOptions.NoSplashScreen, out pid);
        System.Diagnostics.Process proc = null;
        foreach (var p in System.Diagnostics.Process.GetProcesses())
        {
            if (p.Id == pid)
            {
                proc = p;
            }
        }
        while (!proc.HasExited)
        {
            System.Threading.Thread.Sleep(100);
        }
    }
Пример #29
0
        /// <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 for URL
                var regex = new Regex(@"^(https?|ftp)\://.*$");
                if (!regex.IsMatch(url))
                {
                    //assume local file
                    url = "file://" + url;
                }
                launcher.ActivateApplication(EdgeName, url, ActivateOptions.None, out pid);
                break;
            }

            default:
                Console.WriteLine("Application allows ONLY one parameter. Type <MicrosoftEdgeLauncherCsharp.exe http://yourpreferedurl.com> (without <>).");
                break;
            }

            Console.Read();
        }
Пример #30
0
        /// <summary>
        /// Launches an app
        /// </summary>
        /// <param name="appUserModelId">something like (%package_family_name% + "!App"_</param>
        public static void LaunchApp(string appUserModelId)
        {
            try
            {
                if (!String.IsNullOrWhiteSpace(appUserModelId))
                {
                    IApplicationActivationManager appActiveManager = new ApplicationActivationManager();
                    // This call ensures that the app is launched as the foreground window
                    //CoAllowSetForegroundWindow(appActiveManager, IntPtr.Zero);

                    uint pid;
                    appActiveManager.ActivateApplication(appUserModelId, null, ActivateOptions.None, out pid);
                }
                else
                {
                    throw new ArgumentNullException("AppUserModelId cannot be null or empty");
                }
            }
            catch (Exception ex)
            {
                Logger.Log(ex, "Launching app {0}", appUserModelId);
            }
        }
Пример #31
0
        public static uint Launch()
        {
            OnJwLauncherEvent(new JwLauncherEventArgs("Finding JWL package"));

            var packageNames = PackageInfo.GetPackageNamesStartingWith(PackagePrefix);

            if (packageNames.Count != 1)
            {
                var errorMessage = "Could not find JwLibrary package name.";
                throw new JwlManagerException(errorMessage);
            }

            var packageName = packageNames.First();

            OnJwLauncherEvent(new JwLauncherEventArgs($"Found JWL package: {packageName}"));

            OnJwLauncherEvent(new JwLauncherEventArgs("Finding JWL App user model Id"));
            var appUserModelId = PackageInfo.GetAppUserModelId(packageName);

            if (string.IsNullOrWhiteSpace(appUserModelId))
            {
                throw new JwlManagerException("Could not find JwLibrary app user model Id.");
            }

            OnJwLauncherEvent(new JwLauncherEventArgs($"Found JWL App user model Id: {appUserModelId}"));

            var appActiveManager = new ApplicationActivationManager();

            OnJwLauncherEvent(new JwLauncherEventArgs("Activating application"));

            appActiveManager.ActivateApplication(appUserModelId, null, ActivateOptions.None, out var processId);

            OnJwLauncherEvent(new JwLauncherEventArgs($"Activated application, process Id = 0x{processId:X}"));

            return(processId);
        }
Пример #32
0
        public static void Activate(string appId, string arguments)
        {
            ApplicationActivationManager appActiveManager = new ApplicationActivationManager();//Class not registered

            appActiveManager.ActivateApplication(appId, arguments, ActivateOptions.None, out _);
        }
Пример #33
0
        /// <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:
            {
                // Calling Microsoft Edge as is
                // me_launcher
                Debug.WriteLine("calling without arguments...");
                launcher.ActivateApplication(EdgeName, null, ActivateOptions.None, out pid);
                break;
            }

            case 1:
            {
                // Calling microsoft edge to open a website
                // me_launcher "[website]"
                var par = args[0];

                if (par == "-h")
                {
                    Showguide();
                }
                else
                {
                    // == Checking the nature of the parameter
                    // Define the regex expressions
                    var regex_url = new Regex(@"^((https?|ftp)\://|www).*$");

                    // Check flags
                    bool sanity = regex_url.IsMatch(par);

                    if (sanity)
                    {
                        // Launch the application
                        launcher.ActivateApplication(EdgeName,
                                                     par,
                                                     ActivateOptions.None,
                                                     out pid);
                    }
                    else
                    {
                        Console.WriteLine("Something went wrong in the address parsing...");
                        Showguide();
                    }
                }
                break;
            }

            default:
            {
                // Calling microsoft edge with options
                // me_launcher [-opts] "https://[website]"

                int  noptpar  = args.Length - 1;
                bool filemode = false;
                bool readmode = false;

                // Parsing the parameters
                for (int i = 0; i < noptpar; i++)
                {
                    string par = args[i];

                    if (par == "-r")
                    {
                        readmode = true;
                        continue;
                    }

                    if (par == "-f")
                    {
                        filemode = true;
                        continue;
                    }

                    // If you get here something is wrong...
                    Console.Write("Error parsing the parameters: ");
                    Console.WriteLine("\"" + par + "\" was not recognized as valid parameter!");
                    Showguide();
                }

                // Check that both the options have been selected
                if (filemode && readmode)
                {
                    Console.WriteLine("It is not possible to open local file in read mode");
                    Showguide();
                    break;
                }


                // Extract the target from the parameters
                string target = args[noptpar];

                string extended_target = target;
                if (filemode)
                {
                    extended_target = "file://" + extended_target;
                }

                if (readmode)
                {
                    extended_target = "read:" + extended_target;
                }

                // Launch the application
                launcher.ActivateApplication(EdgeName,
                                             extended_target,
                                             ActivateOptions.None,
                                             out pid);
                break;
            }
            }             // ENDOFSWITCH

            //Console.Read();
        }
Пример #34
0
 private async void Launch(IPublicAPI api)
 {
     var appManager = new ApplicationActivationManager();
     uint unusedPid;
     const string noArgs = "";
     const ACTIVATEOPTIONS noFlags = ACTIVATEOPTIONS.AO_NONE;
     await Task.Run(() =>
     {
         try
         {
             appManager.ActivateApplication(UserModelId, noArgs, noFlags, out unusedPid);
         }
         catch (Exception)
         {
             var name = "Plugin: Program";
             var message = $"Can't start UWP: {DisplayName}";
             api.ShowMsg(name, message, string.Empty);
         }
     });
 }
Пример #35
0
 public ezTestUWP()
 {
     // May fail with an exception.
     appActiveManager = new ApplicationActivationManager();
 }
Пример #36
0
        public static uint LaunchApp(string packageFullName, string appId = null, string arguments = null)
        {
            var pir = IntPtr.Zero;

            try
            {
                int openPackageInfoByFullNameErrorCodeResult = OpenPackageInfoByFullName(packageFullName, 0, out pir);

                Debug.Assert(openPackageInfoByFullNameErrorCodeResult == 0);

                if (openPackageInfoByFullNameErrorCodeResult != 0)
                {
                    throw new Win32Exception(openPackageInfoByFullNameErrorCodeResult);
                }

                int length = 0;
                int appIdCount;

                // First you pass NULL to buffer to get the required size of buffer. You use
                // this number to allocate memory space for buffer. Then you pass the
                // address of this memory space to fill buffer.
                int getPackageApplicationIdsErrorResult = GetPackageApplicationIds(pir, ref length, null, out appIdCount);

                var buffer = new byte[length];

                //If the function succeeds it returns ERROR_SUCCESS. Otherwise, the function
                //returns an error code. The possible error codes include the following.
                //ERROR_INSUFFICIENT_BUFFER
                int getPackageApplicationIdsErrorCodeResult = GetPackageApplicationIds(pir, ref length, buffer, out appIdCount);
                Debug.Assert(getPackageApplicationIdsErrorCodeResult == 0);

                if (getPackageApplicationIdsErrorCodeResult != 0)
                {
                    throw new Win32Exception(getPackageApplicationIdsErrorCodeResult);
                }

                string appUserModelId = Encoding.Unicode.GetString(buffer, IntPtr.Size * appIdCount, length - IntPtr.Size * appIdCount);

                // If appId parameter specified then try to find it in the list when
                // there's more than one appId found in package
                if (appIdCount > 1)
                {
                    // Extract list one out of the null terminated unicode result
                    // when more than one result
                    var allUserModIds = appUserModelId.Split(new[] { '\0' }, StringSplitOptions.RemoveEmptyEntries);

                    if (appId != null)
                    {
                        appUserModelId = allUserModIds.ToList().FirstOrDefault(p => p.ToLower().EndsWith(appId.ToLower()));
                    }

                    if (string.IsNullOrEmpty(appUserModelId))
                    {
                        appUserModelId = allUserModIds[0];
                    }
                }

                var activation = new ApplicationActivationManager() as IApplicationActivationManager;

                uint pid;

                int activateApplicationHResult = activation.ActivateApplication(appUserModelId, arguments ?? string.Empty, ActivateOptions.NoErrorUI, out pid);

                if (activateApplicationHResult < 0)
                {
                    Marshal.ThrowExceptionForHR(activateApplicationHResult);
                }

                return(pid);
            }
            finally
            {
                if (pir != IntPtr.Zero)
                {
                    ClosePackageInfo(pir);
                }
            }
        }
        // "Unsafe" so we can very easily pass environmentPzz (a string with embedded nulls)
        // to Win32 as an IntPtr
        unsafe static public void SpawnWindowsStoreAppProcess(string packgeFullName, string appUserModelId, string appArgs, string[] environment, out uint pid)
        {
            IApplicationActivationManager appActivationMgr = new ApplicationActivationManager();
            IPackageDebugSettings pkgDebugSettings = new PackageDebugSettings();

            // NOTE: If you'd like to step through the native profiler DLL's startup, use a
            // string like this instead of the WindowsStoreAppThreadResumer string below
            //string debuggerCommandLine = "C:\\debuggers\\windbg.exe";
            
            string debuggerCommandLine = Path.Combine(
                Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName),
                "CLRProfilerWindowsStoreAppThreadResumer.exe");
            
            if (!File.Exists(debuggerCommandLine))
            {
                pid = unchecked((uint)-1);
                MessageBox.Show(
                    string.Format(
                        "Cannot launch Windows Store app, because the following file is missing: '{0}'", 
                        debuggerCommandLine));
                return;
            }

            ushort[] environmentPzz = StringArrayToPzz(environment);

            fixed (ushort* fixedEnvironmentPzz = environmentPzz)
            {
                pkgDebugSettings.EnableDebugging(packgeFullName, debuggerCommandLine, (IntPtr)fixedEnvironmentPzz);
            }

	        appActivationMgr.ActivateApplication(appUserModelId, appArgs, ACTIVATEOPTIONS.AO_NONE, out pid);
        }
 // Tells the OS to take a package out of "debugging" mode.  This resets the intent
 // to pass environment variables to the package and allows the package to be suspended
 // by the OS in the future, as usual.
 static public void DisableDebuggingForPackage(string packgeFullName)
 {
     IApplicationActivationManager appActivationMgr = new ApplicationActivationManager();
     IPackageDebugSettings pkgDebugSettings = new PackageDebugSettings();
     pkgDebugSettings.DisableDebugging(packgeFullName);
 }
 // Tells the OS to put the package in "debugging" mode, which ensures it does not
 // get suspended.  This is mainly used for attach, where environment variables are
 // not to be passed to the profilee.  For launch-profiling, SpawnWindowsStoreAppProcess()
 // also puts the package in debugging mode, but passes environment variables as well.
 static public void EnableDebuggingForPackage(string packageFullName)
 {
     IApplicationActivationManager appActivationMgr = new ApplicationActivationManager();
     IPackageDebugSettings pkgDebugSettings = new PackageDebugSettings();
     pkgDebugSettings.EnableDebugging(packageFullName, null /* debugger cmd line */, IntPtr.Zero /* environment */);
     pkgDebugSettings.Resume(packageFullName);
 }