Exemplo n.º 1
0
        static int launchApp(String appid, String version)
        {
            String appUserModelId = null;
            var appListKey = Registry.CurrentUser.OpenSubKey("Software\\Classes\\ActivatableClasses\\Package");

            // if we have the version, then this should be simple
            if (version != null) {
                foreach (var appKeyName in appListKey.GetSubKeyNames()) {
                    if (appKeyName.IndexOf(appid + "_" + version + "_") == 0) {
                        var appKey = appListKey.OpenSubKey(appKeyName);
                        var appClassKey = appKey.OpenSubKey("ActivatableClassId\\App");
                        if (appClassKey == null)
                        {
                            appClassKey = appKey.OpenSubKey("ActivatableClassId\\App.wwa");
                        }
                        String serverId = (String)appClassKey.GetValue("Server");
                        var subKey = appKey.OpenSubKey("Server\\" + serverId);
                        appUserModelId = (String)subKey.GetValue("AppUserModelId");
                        break;
                    }
                }
            } else {
                // no version, so find all with the appid and the largest version number
                string lastVersion = null;
                foreach (var appKeyName in appListKey.GetSubKeyNames()) {
                    int p = appKeyName.IndexOf(appid + "_");
                    if (p == 0) {
                        int q = appKeyName.IndexOf("_", p + 1);
                        if (q != -1) {
                            string thisVersion = appKeyName.Substring(p + 1, q);
                            if (lastVersion == null || String.Compare(thisVersion, lastVersion, true) > 0) {
                                var appKey = appListKey.OpenSubKey(appKeyName);
                                var appClassKey = appKey.OpenSubKey("ActivatableClassId\\App");
                                if (appClassKey == null)
                                {
                                    appClassKey = appKey.OpenSubKey("ActivatableClassId\\App.wwa");
                                }
                                String serverId = (String)appClassKey.GetValue("Server");
                                var subKey = appKey.OpenSubKey("Server\\" + serverId);
                                if (subKey != null) {
                                    appUserModelId = (String)subKey.GetValue("AppUserModelId");
                                    lastVersion = thisVersion;
                                }
                            }
                        }
                    }
                }
            }

            if (appUserModelId == null) {
                Console.WriteLine("Could not find version " + version + " of application " + appid + " in the registry. Is the application installed?");
                return 1;
            }

            var aam = new ApplicationActivationManager();
            UInt32 id;
            aam.ActivateApplication(appUserModelId, null, ActivateOptions.None, out id);

            return 0;
        }
Exemplo n.º 2
0
        static int launchApp(String appid, String version)
        {
            String appUserModelId = null;
            var    appListKey     = Registry.CurrentUser.OpenSubKey("Software\\Classes\\ActivatableClasses\\Package");

            // if we have the version, then this should be simple
            if (version != null)
            {
                foreach (var appKeyName in appListKey.GetSubKeyNames())
                {
                    if (appKeyName.IndexOf(appid + "_" + version + "_") == 0)
                    {
                        var appKey = appListKey.OpenSubKey(appKeyName);
                        var subKey = appKey.OpenSubKey("Server\\App.wwa");
                        appUserModelId = (String)subKey.GetValue("AppUserModelId");
                        break;
                    }
                }
            }
            else
            {
                // no version, so find all with the appid and the largest version number
                string lastVersion = null;
                foreach (var appKeyName in appListKey.GetSubKeyNames())
                {
                    int p = appKeyName.IndexOf(appid + "_");
                    if (p == 0)
                    {
                        int q = appKeyName.IndexOf("_", p + 1);
                        if (q != -1)
                        {
                            string thisVersion = appKeyName.Substring(p + appid.Length + 1, q);
                            if (lastVersion == null || String.Compare(thisVersion, lastVersion, true) > 0)
                            {
                                var appKey = appListKey.OpenSubKey(appKeyName);
                                var subKey = appKey.OpenSubKey("Server\\App.wwa");
                                if (subKey != null)
                                {
                                    appUserModelId = (String)subKey.GetValue("AppUserModelId");
                                    lastVersion    = thisVersion;
                                }
                            }
                        }
                    }
                }
            }

            if (appUserModelId == null)
            {
                Console.WriteLine("Could not find version " + version + " of application " + appid + " in the registry. Is the application installed?");
                return(1);
            }

            var    aam = new ApplicationActivationManager();
            UInt32 id;

            aam.ActivateApplication(appUserModelId, null, ActivateOptions.None, out id);

            return(0);
        }
Exemplo n.º 3
0
        static int launchApp(String appid, String version, String windowsAppId)
        {
            string appUserModelId = null;
            string windowsAppName = null;
            var appListKey = Registry.CurrentUser.OpenSubKey("Software\\Classes\\ActivatableClasses\\Package");

            // if we have the version, then this should be simple
            if (version != null) {
                foreach (var appKeyName in appListKey.GetSubKeyNames()) {
                    if (appKeyName.IndexOf(appid + "_" + version + "_") == 0) {
                        // Save the name, in case sub key doesn't exist
                        windowsAppName = appKeyName;
                        var appKey = appListKey.OpenSubKey(appKeyName);
                        var appClassKey = appKey.OpenSubKey("ActivatableClassId\\App");
                        if (appClassKey == null)
                        {
                            appClassKey = appKey.OpenSubKey("ActivatableClassId\\App.wwa");
                        }
                        String serverId = (String)appClassKey.GetValue("Server");
                        var subKey = appKey.OpenSubKey("Server\\" + serverId);
                        appUserModelId = (String)subKey.GetValue("AppUserModelId");
                        break;
                    }
                }
            } else {
                // no version, so find all with the appid and the largest version number
                string lastVersion = null;
                foreach (var appKeyName in appListKey.GetSubKeyNames()) {
                    int p = appKeyName.IndexOf(appid + "_");
                    if (p == 0) {
                        int q = appKeyName.IndexOf("_", p + 1);
                        if (q != -1) {
                            string thisVersion = appKeyName.Substring(p + 1, q);
                            if (lastVersion == null || String.Compare(thisVersion, lastVersion, true) > 0) {
                                // Save the name, in case sub key doesn't exist
                                windowsAppName = appKeyName;
                                var appKey = appListKey.OpenSubKey(appKeyName);
                                var appClassKey = appKey.OpenSubKey("ActivatableClassId\\App");
                                if (appClassKey == null)
                                {
                                    appClassKey = appKey.OpenSubKey("ActivatableClassId\\App.wwa");
                                }
                                if (appClassKey != null)
                                {
                                    String serverId = (String)appClassKey.GetValue("Server");
                                    var subKey = appKey.OpenSubKey("Server\\" + serverId);
                                    if (subKey != null)
                                    {
                                        appUserModelId = (String)subKey.GetValue("AppUserModelId");
                                        lastVersion = thisVersion;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            // If there's no Server entry in the registry...we still have a way when Windows Store application id is provided
            // You can find Windows Store application id in the "Application Id" value in the AppxManifest.xml.
            if (appUserModelId == null && windowsAppName != null) {

                // Extract "family name" from the entry name, by removing version and archtecture string
                // For example: Microsoft.SkypeApp_3.2.1.0_x86__kzf8qxf38zg5c -> Microsoft.SkypeApp_kzf8qxf38zg5c
                var first = windowsAppName.IndexOf("_");
                var last  = windowsAppName.LastIndexOf("_");
                var familyName = windowsAppName.Substring(0, first) + "_" + windowsAppName.Substring(last + 1);

                // we try to do our best...many apps are actually using "App" for application id
                if (windowsAppId == null) {
                    windowsAppId = "App";
                }

                // then we conbine it with the Windows Store application id...wish it generates valid one
                appUserModelId = String.Format("{0}!{1}", familyName, windowsAppId);
            }

            if (appUserModelId == null) {
                Console.WriteLine("Could not find version " + version + " of application " + appid + " in the registry. Is the application installed?");
                return 1;
            }

            try {
                var aam = new ApplicationActivationManager();
                UInt32 id;
                aam.ActivateApplication(appUserModelId, null, ActivateOptions.None, out id);
                Console.WriteLine(id);
            } catch (System.Runtime.InteropServices.COMException) {
                Console.WriteLine("Could not find version " + version + " of application " + appid + " in the registry. Is the application installed?");
                return 1;
            }

            return 0;
        }
Exemplo n.º 4
0
        static int launchApp(String appid, String version, String windowsAppId)
        {
            string appUserModelId = null;
            string windowsAppName = null;
            var    appListKey     = Registry.CurrentUser.OpenSubKey("Software\\Classes\\ActivatableClasses\\Package");

            // if we have the version, then this should be simple
            if (version != null)
            {
                foreach (var appKeyName in appListKey.GetSubKeyNames())
                {
                    if (appKeyName.IndexOf(appid + "_" + version + "_") == 0)
                    {
                        // Save the name, in case sub key doesn't exist
                        windowsAppName = appKeyName;
                        var appKey      = appListKey.OpenSubKey(appKeyName);
                        var appClassKey = appKey.OpenSubKey("ActivatableClassId\\App");
                        if (appClassKey == null)
                        {
                            appClassKey = appKey.OpenSubKey("ActivatableClassId\\App.wwa");
                        }
                        String serverId = (String)appClassKey.GetValue("Server");
                        var    subKey   = appKey.OpenSubKey("Server\\" + serverId);
                        appUserModelId = (String)subKey.GetValue("AppUserModelId");
                        break;
                    }
                }
            }
            else
            {
                // no version, so find all with the appid and the largest version number
                string lastVersion = null;
                foreach (var appKeyName in appListKey.GetSubKeyNames())
                {
                    int p = appKeyName.IndexOf(appid + "_");
                    if (p == 0)
                    {
                        int q = appKeyName.IndexOf("_", p + 1);
                        if (q != -1)
                        {
                            string thisVersion = appKeyName.Substring(p + 1, q);
                            if (lastVersion == null || String.Compare(thisVersion, lastVersion, true) > 0)
                            {
                                // Save the name, in case sub key doesn't exist
                                windowsAppName = appKeyName;
                                var appKey      = appListKey.OpenSubKey(appKeyName);
                                var appClassKey = appKey.OpenSubKey("ActivatableClassId\\App");
                                if (appClassKey == null)
                                {
                                    appClassKey = appKey.OpenSubKey("ActivatableClassId\\App.wwa");
                                }
                                if (appClassKey != null)
                                {
                                    String serverId = (String)appClassKey.GetValue("Server");
                                    var    subKey   = appKey.OpenSubKey("Server\\" + serverId);
                                    if (subKey != null)
                                    {
                                        appUserModelId = (String)subKey.GetValue("AppUserModelId");
                                        lastVersion    = thisVersion;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            // If there's no Server entry in the registry...we still have a way when Windows Store application id is provided
            // You can find Windows Store application id in the "Application Id" value in the AppxManifest.xml.
            if (appUserModelId == null && windowsAppName != null)
            {
                // Extract "family name" from the entry name, by removing version and archtecture string
                // For example: Microsoft.SkypeApp_3.2.1.0_x86__kzf8qxf38zg5c -> Microsoft.SkypeApp_kzf8qxf38zg5c
                var first      = windowsAppName.IndexOf("_");
                var last       = windowsAppName.LastIndexOf("_");
                var familyName = windowsAppName.Substring(0, first) + "_" + windowsAppName.Substring(last + 1);

                // we try to do our best...many apps are actually using "App" for application id
                if (windowsAppId == null)
                {
                    windowsAppId = "App";
                }

                // then we conbine it with the Windows Store application id...wish it generates valid one
                appUserModelId = String.Format("{0}!{1}", familyName, windowsAppId);
            }

            if (appUserModelId == null)
            {
                Console.WriteLine("Could not find version " + version + " of application " + appid + " in the registry. Is the application installed?");
                return(1);
            }

            try {
                var    aam = new ApplicationActivationManager();
                UInt32 id;
                aam.ActivateApplication(appUserModelId, null, ActivateOptions.None, out id);
            } catch (System.Runtime.InteropServices.COMException) {
                Console.WriteLine("Could not find version " + version + " of application " + appid + " in the registry. Is the application installed?");
                return(1);
            }

            return(0);
        }