Exemplo n.º 1
0
        public IDictionary <Wtypes.PROPERTYKEY, object> GetFromPropertyStore(IEnumerable <Wtypes.PROPERTYKEY> keys)
        {
            if (keys == null)
            {
                throw new NotSupportedException(AutoHelpers.FormatInvariant("Keys passed cannot be null"));
            }

            Shell32.IPersistFile persist = (Shell32.IPersistFile) new Shell32.ShellLink();
            persist.Load(this.ShortcutPath, (uint)ObjBase.STGM.STGM_READ);

            Shell32.IPropertyStore store = (Shell32.IPropertyStore)persist;

            Dictionary <Wtypes.PROPERTYKEY, object> results = new Dictionary <Wtypes.PROPERTYKEY, object>();

            foreach (Wtypes.PROPERTYKEY key in keys)
            {
                Wtypes.PROPERTYKEY pkey = key; // iteration variables are read-only and we need to pass by ref
                object             pv;
                store.GetValue(ref pkey, out pv);

                results.Add(key, pv);
            }

            return(results);
        }
Exemplo n.º 2
0
        private void DeleteRegistry()
        {
            AutoHelpers.LogInvariant("Deleting registry node: {0}", regNode);
            string deleteCmd = AutoHelpers.FormatInvariant(regDelCommand, regNode);

            Process regProc = Process.Start(regExePath, deleteCmd);

            regProc.WaitForExit();
        }
Exemplo n.º 3
0
        public RegistryKey GetMatchingKey(OpenTarget target)
        {
            switch (target)
            {
            case OpenTarget.Defaults:
                return(Registry.CurrentUser.OpenSubKey(@"Console"));

            case OpenTarget.Specifics:
                return(Registry.CurrentUser.OpenSubKey(@"Console").OpenSubKey("%SystemRoot%_system32_cmd.exe"));

            default:
                throw new NotImplementedException(AutoHelpers.FormatInvariant("This type of registry key isn't implemented: {0}", target.ToString()));
            }
        }
Exemplo n.º 4
0
        public void CreateTempCmdShortcut()
        {
            string tempPath = Path.Combine(Path.GetTempPath(), AutoHelpers.FormatInvariant("{0}.lnk", Path.GetRandomFileName()));

            AutoHelpers.LogInvariant("Creating temporary shortcut: {0}", tempPath);

            Shell32.IShellLinkW link = (Shell32.IShellLinkW) new Shell32.ShellLink();
            link.SetDescription("Created by Conhost.UIA.Tests.Common.ShortcutHelper");
            link.SetPath(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "cmd.exe"));

            Shell32.IPersistFile persist = (Shell32.IPersistFile)link; // performs QI
            persist.Save(tempPath, false);

            this.ShortcutPath = tempPath;
        }
Exemplo n.º 5
0
        public void RestoreRegistry()
        {
            AutoHelpers.LogInvariant("Restore settings to pre-test status.");
            this.DeleteRegistry();

            AutoHelpers.LogInvariant("Restoring registry from file: {0}", backupFile);

            Verify.IsTrue(File.Exists(backupFile));

            string restoreCmd = AutoHelpers.FormatInvariant(regLoadCommand, backupFile);

            Process regProc = Process.Start(regExePath, restoreCmd);

            regProc.WaitForExit();

            File.Delete(backupFile);

            this.backupFile = null;
        }
Exemplo n.º 6
0
        public void BackupRegistry()
        {
            AutoHelpers.LogInvariant("Save existing registry key status.");
            this.backupFile = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());

            AutoHelpers.LogInvariant("Backing up registry to file: {0}", backupFile);

            Verify.IsFalse(File.Exists(backupFile));

            string backupCmd = AutoHelpers.FormatInvariant(regSaveCommand, regNode, backupFile);

            AutoHelpers.LogInvariant("Calling command: {0} {1}", regExePath, backupCmd);

            Process regProc = Process.Start(regExePath, backupCmd);

            regProc.WaitForExit();

            Verify.IsTrue(File.Exists(backupFile));
        }
Exemplo n.º 7
0
        public void SetToPropertyStore(IDictionary <Wtypes.PROPERTYKEY, object> properties)
        {
            if (properties == null)
            {
                throw new NotSupportedException(AutoHelpers.FormatInvariant("Properties passed cannot be null."));
            }

            Shell32.IPersistFile persist = (Shell32.IPersistFile) new Shell32.ShellLink();
            persist.Load(this.ShortcutPath, (uint)ObjBase.STGM.STGM_READWRITE);

            Shell32.IPropertyStore store = (Shell32.IPropertyStore)persist;

            foreach (Wtypes.PROPERTYKEY key in properties.Keys)
            {
                Wtypes.PROPERTYKEY pkey = key; // iteration variables are read-only and we need to pass by ref
                object             pv   = properties[key];

                store.SetValue(ref pkey, ref pv);
            }

            persist.Save(null, true);
        }
Exemplo n.º 8
0
 public void SetDefaultValue(string valueName, object valueValue)
 {
     AutoHelpers.LogInvariant("Setting registry key {0}'s value name {1} to value {2}", regNode, valueName, valueValue);
     Registry.SetValue(regNodeVerbose, valueName, valueValue);
 }