ReadKey() публичный Метод

public ReadKey ( string KeyName ) : string
KeyName string
Результат string
Пример #1
0
        public override void Uninstall(IDictionary savedState)
        {
            base.Uninstall(savedState);
            // BDS 13-11-2006
            // Instead of simply restoring the originalPathRegValue stored during the
            // installation now we read the installDir from the state saver and
            // replace it in the PATH stored in the registry. This will not damage
            // the other entries in the PATH variable.
            string origRegValue = (string)savedState["OriginalPathRegValue"];
            string installDir   = (string)savedState["InstallDir"];

            RegistryHelper registry = new RegistryHelper();

            registry.BaseRegistryKey = Registry.LocalMachine;
            registry.SubKey         += @"System\CurrentControlSet\Control\Session Manager\Environment";
            string currentPath = registry.ReadKey("PATH");

            if (currentPath != null && currentPath.Length > 0)
            {
                if (installDir != null && installDir.Length > 0)
                {
                    registry.WriteKey("PATH", currentPath.Replace(";" + installDir, ""));
                }
            }

            EnvironmentHelper.BroadCast();

            try
            {
                // Remove the registry entry.
                Registry.LocalMachine.DeleteSubKey(RegistrySubKey, false);

                // Remove the .addin file.
                string addinFile = (string)savedState[@"AddinFilePath"];

                if (addinFile != null && File.Exists(addinFile))
                {
                    File.Delete(addinFile);
                }
            }
            catch (SecurityException)
            {
                MessageBox.Show(@"You must have write permission to the HKEY_LOCAL_MACHINE registry key in order to uninstall this software.");
                throw new InstallException(@"Access denied.");
            }
            catch
            {
                throw new InstallException(@"Unknown error.");
            }
        }
Пример #2
0
        public override void Install(IDictionary stateSaver)
        {
            base.Install(stateSaver);

            string regValue = "";

            RegistryHelper registry = new RegistryHelper();

            registry.BaseRegistryKey = Registry.LocalMachine;
            registry.SubKey         += @"System\CurrentControlSet\Control\Session Manager\Environment";
            regValue = registry.ReadKey("PATH");

            string installDir = Context.Parameters["myDir"];

            if (regValue != null)
            {
                // BDS: 13-11-2006
                // Saving the original value and restoring it during the uninstallation would
                // loose the PATH information set by other software installed after WSCF.
                // Therefore I'm saving the installation directory to our state saver and later
                // using it to remove it from the PATH variable.
                // Consequently this line will soon become obsolete.
                stateSaver.Add("OriginalPathRegValue", regValue);
                stateSaver.Add("InstallDir", installDir);
                string newPathValue = regValue + ";" + installDir;
                registry.WriteKey("PATH", newPathValue);
            }
            // What happens if this value is null is not defined.

            EnvironmentHelper.BroadCast();

            // BDS: Write the installation directory into the registry.
            // Write the .addin file to the selected folder.
            try
            {
                RegistryKey subkey = Registry.LocalMachine.CreateSubKey(
                    RegistrySubKey);

                subkey.SetValue(Path, installDir);

                // Write the .addin file.
                ResourceManager rm = new ResourceManager("Thinktecture.Tools.Web.Services.Wscf.Environment.Properties.Resources",
                                                         Assembly.GetExecutingAssembly());
                string settings = rm.GetString("WSCF");

                string asmPath = installDir;

                if (!installDir.EndsWith(@"\"))
                {
                    asmPath += @"\";
                }

                asmPath += @"Thinktecture.Tools.Web.Services.ContractFirst.dll";
                settings = settings.Replace(@"@@ASM@@", asmPath);

                string version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
                settings = settings.Replace(@"@@FNVER@@", version);

                string configDir = null;
                if (Context.Parameters[@"ALLUSERS"] == @"1")
                {
                    configDir = FxEnvironment.GetEnvironmentVariable(@"ALLUSERSPROFILE");

                    if (configDir == null)
                    {
                        throw new InstallException("All Users directory not found.");
                    }

                    configDir += @"\Application Data\Microsoft\MSEnvShared\Addins";

                    if (!Directory.Exists(configDir))
                    {
                        Directory.CreateDirectory(configDir);
                    }
                }
                else
                {
                    configDir  = FxEnvironment.GetFolderPath(FxEnvironment.SpecialFolder.ApplicationData);
                    configDir += @"\Microsoft\MSEnvShared\Addins";

                    if (!Directory.Exists(configDir))
                    {
                        Directory.CreateDirectory(configDir);
                    }
                }

                string       addinFile = configDir + @"\WSCF.addin";
                StreamWriter writer    = new StreamWriter(addinFile, false, Encoding.Unicode);
                writer.Write(settings);
                writer.Flush();
                writer.Close();

                stateSaver.Add(@"AddinFilePath", addinFile);
            }
            catch (SecurityException)
            {
                MessageBox.Show(@"You must have write permission to the HKEY_LOCAL_MACHINE registry key in order to install this software.");
                throw new InstallException(@"Access denied.");
            }
            catch (Exception ex)
            {
                throw new InstallException(@"Unknown error:" + ex.Message);
            }
        }
Пример #3
0
        public override void Install(IDictionary stateSaver)
        {
            base.Install(stateSaver);

            string regValue = "";

            RegistryHelper registry = new RegistryHelper();
            registry.BaseRegistryKey = Registry.LocalMachine;
            registry.SubKey += @"System\CurrentControlSet\Control\Session Manager\Environment";
            regValue = registry.ReadKey("PATH");

            string installDir = Context.Parameters["myDir"];

            if(regValue != null)
            {
                // BDS: 13-11-2006
                // Saving the original value and restoring it during the uninstallation would
                // loose the PATH information set by other software installed after WSCF.
                // Therefore I'm saving the installation directory to our state saver and later
                // using it to remove it from the PATH variable.
                // Consequently this line will soon become obsolete.
                stateSaver.Add("OriginalPathRegValue", regValue);
                stateSaver.Add("InstallDir", installDir);
                string newPathValue = regValue + ";" + installDir;
                registry.WriteKey("PATH", newPathValue);
            }
            // What happens if this value is null is not defined.

            EnvironmentHelper.BroadCast();

            // BDS: Write the installation directory into the registry.
            // Write the .addin file to the selected folder.
            try
            {
                RegistryKey subkey = Registry.LocalMachine.CreateSubKey(
                    RegistrySubKey);

                subkey.SetValue(Path, installDir);

                // Write the .addin file.
                ResourceManager rm = new ResourceManager("Thinktecture.Tools.Web.Services.Wscf.Environment.Properties.Resources",
                Assembly.GetExecutingAssembly());
                string settings = rm.GetString("WSCF");

                string asmPath = installDir;

                if (!installDir.EndsWith(@"\"))
                {
                    asmPath += @"\";
                }

                asmPath += @"Thinktecture.Tools.Web.Services.ContractFirst.dll";
                settings = settings.Replace(@"@@ASM@@", asmPath);

                string version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
                settings = settings.Replace(@"@@FNVER@@", version);

                string configDir = null;
                if (Context.Parameters[@"ALLUSERS"] == @"1")
                {
                    configDir = FxEnvironment.GetEnvironmentVariable(@"ALLUSERSPROFILE");

                    if (configDir == null)
                    {
                        throw new InstallException("All Users directory not found.");
                    }

                    configDir += @"\Application Data\Microsoft\MSEnvShared\Addins";

                    if (!Directory.Exists(configDir))
                    {
                        Directory.CreateDirectory(configDir);
                    }
                }
                else
                {
                    configDir = FxEnvironment.GetFolderPath(FxEnvironment.SpecialFolder.ApplicationData);
                    configDir += @"\Microsoft\MSEnvShared\Addins";

                    if (!Directory.Exists(configDir))
                    {
                        Directory.CreateDirectory(configDir);
                    }
                }

                string addinFile = configDir + @"\WSCF.addin";
                StreamWriter writer = new StreamWriter(addinFile, false, Encoding.Unicode);
                writer.Write(settings);
                writer.Flush();
                writer.Close();

                stateSaver.Add(@"AddinFilePath", addinFile);
            }
            catch (SecurityException)
            {
                MessageBox.Show(@"You must have write permission to the HKEY_LOCAL_MACHINE registry key in order to install this software.");
                throw new InstallException(@"Access denied.");
            }
            catch(Exception ex)
            {
                throw new InstallException(@"Unknown error:" + ex.Message);
            }
        }
Пример #4
0
        public override void Uninstall(IDictionary savedState)
        {
            base.Uninstall(savedState);
            // BDS 13-11-2006
            // Instead of simply restoring the originalPathRegValue stored during the
            // installation now we read the installDir from the state saver and
            // replace it in the PATH stored in the registry. This will not damage
            // the other entries in the PATH variable.
            string origRegValue = (string)savedState["OriginalPathRegValue"];
            string installDir = (string)savedState["InstallDir"];

            RegistryHelper registry = new RegistryHelper();
            registry.BaseRegistryKey = Registry.LocalMachine;
            registry.SubKey += @"System\CurrentControlSet\Control\Session Manager\Environment";
            string currentPath = registry.ReadKey("PATH");

            if(currentPath != null && currentPath.Length > 0)
            {
                if (installDir != null && installDir.Length > 0)
                {
                    registry.WriteKey("PATH", currentPath.Replace(";" + installDir, ""));
                }
            }

            EnvironmentHelper.BroadCast();

            try
            {
                // Remove the registry entry.
                Registry.LocalMachine.DeleteSubKey(RegistrySubKey, false);

                // Remove the .addin file.
                string addinFile = (string)savedState[@"AddinFilePath"];

                if (addinFile != null && File.Exists(addinFile))
                {
                    File.Delete(addinFile);
                }
            }
            catch (SecurityException)
            {
                MessageBox.Show(@"You must have write permission to the HKEY_LOCAL_MACHINE registry key in order to uninstall this software.");
                throw new InstallException(@"Access denied.");
            }
            catch
            {
                throw new InstallException(@"Unknown error.");
            }
        }