/// <summary> /// Get framework version for specified SubKey /// </summary> /// <param name="parentKey"></param> /// <param name="subVersionName"></param> /// <param name="versions"></param> private static void GetDotNetVersion(RegistryKey parentKey, string subVersionName, IList<NetFrameworkVersionInfo> versions) { if (parentKey != null) { string installed = Convert.ToString(parentKey.GetValue("Install")); if (installed == "1") { NetFrameworkVersionInfo versionInfo = new NetFrameworkVersionInfo(); versionInfo.VersionString = Convert.ToString(parentKey.GetValue("Version")); var test = versionInfo.BaseVersion; versionInfo.InstallPath = Convert.ToString(parentKey.GetValue("InstallPath")); versionInfo.ServicePackLevel = Convert.ToInt32(parentKey.GetValue("SP")); if (parentKey.Name.Contains("Client")) versionInfo.FrameworkProfile = "Client Profile"; else if (parentKey.Name.Contains("Full")) versionInfo.FrameworkProfile = "Full Profile"; if (!versions.Contains(versionInfo)) versions.Add(versionInfo); } } }
internal PackageInfo(RegistryKey key) { PackageId = Path.GetFileName(key.Name); DisplayName = (string)key.GetValue("DisplayName"); PackageRootFolder = (string)key.GetValue("PackageRootFolder"); // walk the files... XamlFiles = new List<string>(); JsFiles = new List<string>(); WalkFiles(new DirectoryInfo(PackageRootFolder)); // probe for a start page... var appKey = key.OpenSubKey("Applications"); if (appKey != null) { using (appKey) { foreach(var subAppName in appKey.GetSubKeyNames()) { using (var subAppKey = appKey.OpenSubKey(subAppName)) { if (subAppKey != null) { var start = (string)subAppKey.GetValue("DefaultStartPage"); if (!(string.IsNullOrEmpty(start))) { FoundStartPage = true; break; } } } } } } }
/// <summary> /// 解压缩 /// </summary> /// <param name="zipname">要解压的文件名</param> /// <param name="zippath">要解压的文件路径</param> public static void DeZip(string zipname, string zippath) { try { the_Reg = Registry.ClassesRoot.OpenSubKey(@"Applications\WinRar.exe\Shell\Open\Command"); the_Obj = the_Reg.GetValue(""); the_rar = the_Obj.ToString(); the_Reg.Close(); the_rar = the_rar.Substring(1, the_rar.Length - 7); the_Info = " X " + zipname + " " + zippath; the_StartInfo = new ProcessStartInfo(); the_StartInfo.FileName = the_rar; the_StartInfo.Arguments = the_Info; the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden; the_Process = new Process(); the_Process.StartInfo = the_StartInfo; the_Process.Start(); the_Process.WaitForExit(); the_Process.Close(); } catch (Exception ex) { throw new Exception(ex.Message); } }
// populates an options object from values stored in the registry private static void PopulateOptions(object options, RegistryKey key) { foreach (PropertyInfo propInfo in options.GetType().GetProperties()) { if (propInfo.IsDefined(typeof(ApplyPolicyAttribute))) { object valueFromRegistry = key.GetValue(propInfo.Name); if (valueFromRegistry != null) { if (propInfo.PropertyType == typeof(string)) { propInfo.SetValue(options, Convert.ToString(valueFromRegistry, CultureInfo.InvariantCulture)); } else if (propInfo.PropertyType == typeof(int)) { propInfo.SetValue(options, Convert.ToInt32(valueFromRegistry, CultureInfo.InvariantCulture)); } else if (propInfo.PropertyType == typeof(Type)) { propInfo.SetValue(options, Type.GetType(Convert.ToString(valueFromRegistry, CultureInfo.InvariantCulture), throwOnError: true)); } else { throw CryptoUtil.Fail("Unexpected type on property: " + propInfo.Name); } } } } }
public void CopyFromRegistry(RegistryKey keyToSave) { if (keyToSave == null) { throw new ArgumentNullException("keyToSave"); } this.ValueNames = keyToSave.GetValueNames(); if (this.ValueNames == null) { this.ValueNames = new string[0]; } this.Values = new object[this.ValueNames.Length]; for (int i = 0; i < this.ValueNames.Length; i++) { this.Values[i] = keyToSave.GetValue(this.ValueNames[i]); } this.KeyNames = keyToSave.GetSubKeyNames(); if (this.KeyNames == null) { this.KeyNames = new string[0]; } this.Keys = new SerializableRegistryKey[this.KeyNames.Length]; for (int j = 0; j < this.KeyNames.Length; j++) { this.Keys[j] = new SerializableRegistryKey(keyToSave.OpenSubKey(this.KeyNames[j])); } }
internal ComAppInfo(RegistryKey classKey, String guidStr) : base(classKey) { _infoType = "ApplId"; // The AppId entries either use the GUID as their key // and the value is the description, or the exe file // is the key, and the Guid is found in the AppId value String guidValueStr = (String)classKey.GetValue("AppID"); if (guidValueStr != null) { Name = guidStr; InitGuid(guidValueStr, new Guid(guidValueStr)); } else { String defValue = (String)classKey.GetValue(null); if (defValue == null || defValue.Equals("")) Name = guidStr; else DocString = defValue; InitGuid(guidStr, new Guid(guidStr)); } }
protected virtual void LoadRegistryInfo(RegistryKey regkey) { int x = (int)regkey.GetValue(strLocationX, 100); int y = (int)regkey.GetValue(strLocationY, 100); int cx = (int)regkey.GetValue(strWidth, 324); int cy = (int)regkey.GetValue(strHeight, 300); this.toolStripCbLang.SelectedIndex = (int)regkey.GetValue(strOcrLanguage, -1); rectNormal = new Rectangle(x, y, cx, cy); // Adjust rectangle for any change in desktop size. Rectangle rectDesk = SystemInformation.WorkingArea; rectNormal.Width = Math.Min(rectNormal.Width, rectDesk.Width); rectNormal.Height = Math.Min(rectNormal.Height, rectDesk.Height); rectNormal.X -= Math.Max(rectNormal.Right - rectDesk.Right, 0); rectNormal.Y -= Math.Max(rectNormal.Bottom - rectDesk.Bottom, 0); // Set form properties. DesktopBounds = rectNormal; WindowState = (FormWindowState)regkey.GetValue(strWinState, 0); this.textBox1.WordWrap = Convert.ToBoolean( (int)regkey.GetValue(strWordWrap, Convert.ToInt32(true))); this.textBox1.Font = new Font((string)regkey.GetValue(strFontFace, "Microsoft Sans Serif"), float.Parse((string)regkey.GetValue(strFontSize, "10")), (FontStyle)regkey.GetValue(strFontStyle, FontStyle.Regular)); this.textBox1.ForeColor = Color.FromArgb( (int)regkey.GetValue(strForeColor, Color.FromKnownColor(KnownColor.Black).ToArgb())); this.textBox1.BackColor = Color.FromArgb( (int)regkey.GetValue(strBackColor, Color.FromKnownColor(KnownColor.White).ToArgb())); }
private void registryTraveller(RegistryKey look_here) { if (worker.CancellationPending) return; foreach (string check_me in look_here.GetValueNames()) { RegistryKeyValue value = new RegistryKeyValue(); try { value.key = look_here.Name; value.value = check_me; if (look_here.GetValue(check_me) != null) { value.data = look_here.GetValue(check_me).ToString(); if (value.data.Length >= path.FullDirPath.Length && path.FullDirPath.ToLower() == value.data.Substring(0, path.FullDirPath.Length).ToLower()) { outputLine(Environment.NewLine + "Key:" + value.key); outputLine("Value: " + value.value); output("Data: "); outputPath(value.data); } } } catch { } } try { RegistryKey sub_key; foreach (string check_me in look_here.GetSubKeyNames()) { try { sub_key = look_here.OpenSubKey(check_me); if (sub_key != null) registryTraveller(sub_key); } catch (System.Security.SecurityException) { } } } catch { } }
internal TcpIpReaderSettings(RegistryKey regKey, string host) { IsRemote = true; Host = host; Name = regKey.Name.Substring(regKey.Name.LastIndexOf('\\')+1); Port = (int)regKey.GetValue("Port", 29500); EventPort = (int)regKey.GetValue("EventPort", 29501); }
internal PipeReaderSettings(RegistryKey regKey, string host) { IsRemote = true; Host = host; Name = regKey.Name.Substring(regKey.Name.LastIndexOf('\\') + 1); PipeName = regKey.GetValue("PipeName", "SCardSimulatorDriver0").ToString(); EventPipeName = regKey.GetValue("EventPipeName", "SCardSimulatorDriverEvents0").ToString(); }
private void ConnectionDlg_Load(object sender, EventArgs e) { regKey = Registry.CurrentUser; regKey = regKey.CreateSubKey("Software\\TickNet\\DBServer"); textHost.Text = regKey.GetValue("DB_Server").ToString(); textLogin.Text = regKey.GetValue("DB_Login").ToString(); textPass.Text = regKey.GetValue("DB_Pass").ToString(); }
static TFDBManager() { __current = ""; __databaseKey = RegistrySupport.SubKey("Database"); __current = __databaseKey.GetValue("Current", "").ToString(); __dbfile = __databaseKey.GetValue("Filename", "").ToString(); }
public static object GetValue(RegistryKey key, string name) { log.DebugFormat(InternalResources.GettingKeyValue, key, name); var value = key.GetValue(name); log.DebugFormat(InternalResources.GotValue, value); return key.GetValue(name); }
protected override void LoadRegistryInfo(RegistryKey regkey) { base.LoadRegistryInfo(regkey); String workingDir = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); dangAmbigsPath = (string)regkey.GetValue(strDangAmbigsPath, Path.Combine(workingDir, "Data")); dangAmbigsOn = Convert.ToBoolean( (int)regkey.GetValue(strDangAmbigsOn, Convert.ToInt32(true))); }
public WebPageShortcut (RegistryKey regKey):base (regKey) { //set the browser this.Browser = regKey.GetValue (WebPageShortcut.BrowserKeyName).ToString (); //set the url this.Url = regKey.GetValue (WebPageShortcut.UrlKeyName).ToString (); //flush immediately to generate the batch file and to ensure the exe path matches this.FlushToRegistry (); }
public void Load(RegistryKey regkey) { history.Clear(); PushBack(regkey.GetValue(key) as string); for (int i = 1; i < HISTORY_LENGTH; i++) PushBack(regkey.GetValue(key + i.ToString(CultureInfo.InvariantCulture)) as string); SetComboBox(combobox); }
internal string GetApplicationFileByExtension(string ext) { reg_key = Registry.CurrentUser.OpenSubKey( String.Format(@"Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\{0}\OpenWithList", ext)); if (reg_key == null) return ""; string mru_list = (string)reg_key.GetValue("MRUList"); if (mru_list == null) return ""; string app_file = (string)reg_key.GetValue(mru_list.Substring(0, 1)); if (app_file.IndexOf("dmpm")>=0 && mru_list.Length>1) app_file=(string)reg_key.GetValue(mru_list.Substring(1,1)); reg_key.Close(); return app_file; }
static public ReaderSettings GetSettings(RegistryKey regKey) { int type = (int)regKey.GetValue("Type", 0); string Host = regKey.GetValue("Host", ".").ToString(); if (type == 1) return new TcpIpReaderSettings(regKey, Host); else if (type == 0) return new PipeReaderSettings(regKey, Host); else throw new Exception("Reader type not defined"); }
public COMMimeType(string mime_type, RegistryKey key) { string clsid = key.GetValue("CLSID") as string; string extension = key.GetValue("Extension") as string; if ((clsid != null) && (COMUtilities.IsValidGUID(clsid))) { Clsid = Guid.Parse(clsid); } Extension = extension; MimeType = mime_type; }
public MainWindow() { _reg = Registry.CurrentUser.CreateSubKey("Software").CreateSubKey("ch.ph.FileManager"); _clip = new Clipboard(); InitializeComponent(); FormClosing += new FormClosingEventHandler(this_FormClosing); _localRootDir.Text = _reg.GetValue("LocalRootDir") as string; _awsAccessKeyId.Text = _reg.GetValue("AwsAccessKeyId") as string; _awsSecretAccessKey.Text = _reg.GetValue("AwsSecretAccessKey") as string; _awsBucket.Text = _reg.GetValue("AwsBucket") as string; }
public void loadSettings() { try { geopuntKey = Registry.CurrentUser.CreateSubKey("Software\\geopunt"); csvMaxRows = (int)geopuntKey.GetValue("csvMaxRows", 500); timeout = (int)geopuntKey.GetValue("timeOut", 15000); } catch (Exception ex) { MessageBox.Show(ex.Message + " : " + ex.StackTrace, "Kon settings niet openen"); } }
protected IEnumerable<string> BuildFrameworkNamesRecursively(RegistryKey registryKey, string name, string topLevelSp = "0", bool topLevel = false) { Argument.IsNotNull(() => registryKey); Argument.IsNotNullOrEmpty(() => name); Argument.IsNotNullOrEmpty(() => topLevelSp); if (registryKey == null) { yield break; } var fullVersion = string.Empty; var version = (string)registryKey.GetValue("Version", string.Empty); var sp = registryKey.GetValue("SP", "0").ToString(); var install = registryKey.GetValue("Install", string.Empty).ToString(); if (string.Equals(sp, "0")) { sp = topLevelSp; } if (!string.Equals(sp, "0") && string.Equals(install, "1")) { fullVersion = string.Format("{0} {1} SP{2}", name, version, sp); } else if (string.Equals(install, "1")) { fullVersion = string.Format("{0} {1}", name, version); } var topLevelInitialized = !topLevel || !string.IsNullOrEmpty(fullVersion); var subnamesCount = 0; foreach (var subKeyName in registryKey.GetSubKeyNames().Where(x => Regex.IsMatch(x, @"^\d{4}$|^Client$|^Full$"))) { using (var subKey = registryKey.OpenSubKey(subKeyName)) { foreach (var subName in BuildFrameworkNamesRecursively(subKey, string.Format("{0} {1}", name, subKeyName), sp, !topLevelInitialized)) { yield return subName; subnamesCount++; } } } if (subnamesCount == 0) { yield return fullVersion; } }
public void LoadFromRegistry(RegistryKey key, SettingsModel defaultValues) { int opac = (int)key.GetValue("Opacity", (int)(defaultValues.Opacity * 100)); Opacity = (double)opac / 100.0; LoadFontFromRegistry(key, defaultValues.UserFont); MinutesBeforeAway = (int)key.GetValue("MinutesBeforeAway", MinutesBeforeAway); CaseListRefreshInterval_Secs = (int)key.GetValue("PollingInterval", 1000 * CaseListRefreshInterval_Secs) / 1000; // Saved in ms for backward compat with older version if (CaseListRefreshInterval_Secs == 0) // Handle invalid registry data CaseListRefreshInterval_Secs = 600; SwitchToNothingWhenClosing = (int)key.GetValue("SwitchToNothingWhenClosing", 0) != 0; }
internal SystemInformation(RegistryKey key) { bool loaded = false; LastStartupDateTime = DateTime.Now; try { if (key.GetValue(KeyInstallation) != null) { InstallationDateTime = DateTime.ParseExact( (string)key.GetValue(KeyInstallation), "O", CultureInfo.InvariantCulture ); string lastReportDate = (string)key.GetValue(KeyLastReport); if (lastReportDate != null) { LastReportDateTime = DateTime.ParseExact( lastReportDate, "O", CultureInfo.InvariantCulture ); } #if CACHE_SYSTEM_INFORMATION OperatingSystem = (string)key.GetValue(KeyOperatingSystem); OperationSystemVersion = (string)key.GetValue(KeyOperationSystemVersion); Cpu = (string)key.GetValue(KeyCpu); CpuInformation = (string)key.GetValue(KeyCpuInformation); #endif loaded = true; } } catch { // If we were unable to load the settings, initialize new settings. } if (!loaded) { Detect(); key.SetValue(KeyInstallation, InstallationDateTime.ToString("O")); if (key.GetValue(KeyLastReport) != null) key.DeleteValue(KeyLastReport); #if CACHE_SYSTEM_INFORMATION key.SetValue(KeyOperatingSystem, OperatingSystem); key.SetValue(KeyOperationSystemVersion, OperationSystemVersion); key.SetValue(KeyCpu, Cpu); key.SetValue(KeyCpuInformation, CpuInformation); #endif } #if !CACHE_SYSTEM_INFORMATION DetectSystemInformation(); #endif }
private static bool IsProgramVisible(RegistryKey subkey) { var name = (string)subkey.GetValue("DisplayName"); var releaseType = (string)subkey.GetValue("ReleaseType"); //var unistallString = (string)subkey.GetValue("UninstallString"); var systemComponent = subkey.GetValue("SystemComponent"); var parentName = (string)subkey.GetValue("ParentDisplayName"); return !string.IsNullOrEmpty(name) && string.IsNullOrEmpty(releaseType) && string.IsNullOrEmpty(parentName) && (systemComponent == null); }
private void CheckRegistry() { registry = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"); Object startup = registry.GetValue("LightSensor"); auto_start = startup!=null; registry = Registry.CurrentUser.OpenSubKey("SOFTWARE\\LightSensor"); if (registry != null) { Object value = registry.GetValue("Interval",10000); sensor.CheckInterval = (int)value; value = registry.GetValue("CurrentWebCam", -1); sensor.CurrentWebCam = (int)value; } }
/// <summary> /// Page setup with the specifed header and footer. /// </summary> /// <param name="header"></param> /// <param name="footer"></param> public IEHeaderFooterSettings(string header, string footer) { _iePageSetupKey = Registry.CurrentUser.OpenSubKey(_iePageSetupKeyPath, true); _header = header; _footer = footer; if (_iePageSetupKey != null) { _oldHeader = (string)_iePageSetupKey.GetValue("header"); _oldFooter = (string)_iePageSetupKey.GetValue("footer"); _iePageSetupKey.SetValue("header", _header); _iePageSetupKey.SetValue("footer", _footer); } }
public static string GetMsBuildPath(IServiceProvider serviceProvider) { string registryPath; if (serviceProvider == null) { return(String.Empty); } ILocalRegistry3 localRegistry = serviceProvider.GetService(typeof(SLocalRegistry)) as ILocalRegistry3; if (localRegistry == null) { return(String.Empty); } // first, we need the registry hive currently in use ErrorHandler.ThrowOnFailure(localRegistry.GetLocalRegistryRoot(out registryPath)); // now that we have it, append the subkey we are interested in to it if (!registryPath.EndsWith("\\")) { registryPath += '\\'; } registryPath += "MSBuild"; // finally, get the value from the registry Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(registryPath, false); string msBuildPath = (string)key.GetValue("MSBuildBinPath", null); if (msBuildPath == null || msBuildPath.Length <= 0) { string error = SR.GetString(SR.ErrorMsBuildRegistration); throw new FileLoadException(error); } return(msBuildPath); }
//------------------------------------------------------------------------------------------ /// <summary> /// Returns the Mime-Type associated to the supplied Extension. /// </summary> // SEE MIME-TYPES IN: http://msdn.microsoft.com/en-us/library/ms775147%28VS.85%29.aspx public static string GetMimeTypeFromFileExtension(string FileExtension) { string MimeCode = "application/octet-stream"; FileExtension = FileExtension.Trim().ToLower(); FileExtension = (FileExtension.StartsWith(".") ? FileExtension : "." + FileExtension); Microsoft.Win32.RegistryKey RegKey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(FileExtension); if (RegKey != null && RegKey.GetValue("Content Type") != null) { MimeCode = RegKey.GetValue("Content Type").ToString(); } return(MimeCode); }
private void Form1_Load(object sender, EventArgs e) { Properties.Settings.Default.Reload(); // Assign control values. Most values are set using application binding on the control. comboBoxImageFormat.SelectedIndex = Properties.Settings.Default.imageFormat; SyncClipboardSettingsContainerEnabledState(); // Check the registry for a key describing whether EasyImgur should be started on boot. Microsoft.Win32.RegistryKey registryKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true); string value = (string)registryKey.GetValue("EasyImgur", string.Empty); // string.Empty is returned if no key is present. checkBoxLaunchAtBoot.Checked = value != string.Empty; if (value != string.Empty && value != QuotedApplicationPath) { // A key exists, make sure we're using the most up-to-date path! registryKey.SetValue("EasyImgur", QuotedApplicationPath); ShowBalloonTip(2000, "EasyImgur", "Updated registry path", ToolTipIcon.Info); } UpdateRegistry(true); // this will need to be updated too, if we're using it // Bind the data source for the list of contributors. Contributors.BindingSource.DataSource = Contributors.ContributorList; contributorsList.DataSource = Contributors.BindingSource; }
public override void Commit(System.Collections.IDictionary savedState) { // Call the Commit method of the base class base.Commit(savedState); // Open the registry key containing the path to the Application Manager Microsoft.Win32.RegistryKey key = null; key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Software\\microsoft\\windows\\currentversion\\app paths\\ceappmgr.exe"); // If the key is not null, then ActiveSync is installed on the user's desktop computer if (key != null) { // Get the path to the Application Manager from the registry value string appPath = null; appPath = key.GetValue(null).ToString(); // Get the target directory where the .ini file is installed. // This is sent from the Setup application //string strIniFilePath = "\"" + Context.Parameters["InstallDir"] + "RFIDSearchLight.ini\""; string installPath = GetAppInstallDirectory(); string strIniFilePath = installPath + @"\RFIDSearchLight.ini"; if (appPath != null) { // Now launch the Application Manager System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo.FileName = appPath; process.StartInfo.Arguments = strIniFilePath; process.Start(); } } else { // No Active Sync - throw a message } }
public RegistryKeyClass(string registryPath, string allowText, ERegistryHkey hkey) { //Let user decide if the new created setting should be activated or not string configDefaultState = ConfigurationManager.AppSettings["DEFAULTCREATIONSTATE"].ToString(); int state = configDefaultState == "1" ? 1 : 0; bool skipEnabled = false; bool functionThrough = false; while (!functionThrough) { try { SetHKeyFormat(registryPath, hkey); object registryKeyValue = _registryKey.GetValue(allowText); if ((int?)registryKeyValue == 0) { KeyOff = true; } else if ((int?)registryKeyValue == 1) { KeyOff = false; } functionThrough = true; } catch (NullReferenceException ex) { CreateMissingItems(registryPath, allowText, state, hkey, ref skipEnabled, ref functionThrough); } } }
/// <summary> /// Obtains the maximum file size from the registry. If an entry is not found then the default /// value is saved to the registry. If an error is detected in any of this, the default /// value is returned /// </summary> /// <param name="bStoreValue">True if the registry value should be forcibly set after being retrieved (handles default case)</param> /// <returns>The maximum file size</returns> private int getMaxLogFileSize(bool bStoreValue) { int retValue = Defaults.DEFAULT_LOG_FILESIZE; try { // Attempt to get the MaxFileSize from the registry. If the key cannot be found there, // create a new key, setting the value to the default value. Microsoft.Win32.RegistryKey rkQBWC = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(Defaults.REG_KEY, false); retValue = (Int32)rkQBWC.GetValue(MaxLogSizeKey, Defaults.DEFAULT_LOG_FILESIZE); rkQBWC.Close(); // Because the default value will be returned if a no registry entry is found (and we'll // never know about the lack of an entry), set the value in the registry if so commanded. if (bStoreValue) { setMaxLogFileSize(retValue); } } catch { if (bStoreValue) { setMaxLogFileSize(retValue); } } return(retValue); }
/** * TODO: Update this to work with OS X */ private static string GetPathToWorlds(int?steamUserId) { // Are we editing Steam Cloud worlds? if (steamUserId != null) { using (Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"Software\\Valve\\Steam")) { if (key != null) { string steamWorlds = Path.Combine(key.GetValue("SteamPath") as string, "userdata"); // No Steam UserID was specified; we'll guess it if there's only a single user if (steamUserId == 0) { string[] userDirectories = Directory.GetDirectories(steamWorlds); if (userDirectories.Length == 1) { steamUserId = Convert.ToInt32(Path.GetFileName(userDirectories[0])); } } steamWorlds = Path.Combine(steamWorlds, steamUserId.ToString(), "105600", "remote", "worlds").Replace("/", "\\"); if (Directory.Exists(steamWorlds)) { return(steamWorlds); } } } } return(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), @"My Games\Terraria\Worlds")); }
/// <summary> /// Выявляем фактическую директория приложения KeyTool /// </summary> /// <returns></returns> public static string GetJavaInstallationPath() { string environmentPath = Environment.GetEnvironmentVariable("JAVA_HOME"); if (!string.IsNullOrEmpty(environmentPath)) { return(environmentPath); } if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows)) { string javaKey = "SOFTWARE\\JavaSoft\\Java Runtime Environment\\"; using (RegistryKey rk = Registry.LocalMachine.OpenSubKey(javaKey)) { string currentVersion = rk.GetValue("CurrentVersion").ToString(); using (Microsoft.Win32.RegistryKey key = rk.OpenSubKey(currentVersion)) { return(key.GetValue("JavaHome").ToString()); } } } else { return(string.Empty); } }
// Not a winpeas method public static bool RegExists(string hive, string path, string value) { Microsoft.Win32.RegistryKey myKey = null; if (hive == "HKLM") { myKey = Registry.LocalMachine.OpenSubKey(path); } else if (hive == "HKU") { myKey = Registry.Users.OpenSubKey(path); } else { myKey = Registry.CurrentUser.OpenSubKey(path); } if (myKey is null) { return(false); } object RegValue = myKey.GetValue(value); if (RegValue is null) { return(false); } return(true); }
public static string GetValFrReg(string strRegSubKey, string strKey) { string strValue = ""; // Get a reference to the desired registry hive. // This example uses the CurrentUser hive in order to store user preferences // for each user on this machine separately. //Microsoft.Win32.RegistryKey Reg = Microsoft.Win32.Registry.LocalMachine; RegistryKey localKey = RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, RegistryView.Registry64); RegistryKey localKey32 = RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, RegistryView.Registry32); // The following line creates the desired sub key where the settings are be stored. // If the sub key already exists, a reference to the existing key is returned. Microsoft.Win32.RegistryKey regKey = localKey.OpenSubKey(strRegSubKey); Microsoft.Win32.RegistryKey regKey32 = localKey32.OpenSubKey(strRegSubKey); // The following lines retrieve the width and height settings from the sub key. // The second parameter indicates a default value if the setting // does not exist in the registry. if (regKey32 != null) { strValue = (string)regKey32.GetValue(strKey, ""); } else { strValue = (string)regKey.GetValue(strKey, ""); } return(strValue); }
/*private void UpdateText(string message) * { * resultBox.Text = message; * }*/ private void watchButton_Click(object sender, RoutedEventArgs e) { Microsoft.Win32.RegistryKey rkApp = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true); Properties.Settings.Default.ServerAddress = this.serverAddress.Text; Properties.Settings.Default.APIKey = this.apiKey.Text; Properties.Settings.Default.WatchLocation = this.watchFolder.Text; Properties.Settings.Default.DeleteOnUpload = (bool)this.removeUploads.IsChecked; Properties.Settings.Default.AutoStart = (bool)this.autoStart.IsChecked; Properties.Settings.Default.RelaunchOnStartup = (bool)this.relaunchOnStartup.IsChecked; Properties.Settings.Default.Save(); if (this.relaunchOnStartup.IsChecked == true) { rkApp.SetValue(System.Diagnostics.Process.GetCurrentProcess().ProcessName, System.Reflection.Assembly.GetExecutingAssembly().Location); } else if (rkApp.GetValue(System.Diagnostics.Process.GetCurrentProcess().ProcessName) != null) { rkApp.DeleteValue(System.Diagnostics.Process.GetCurrentProcess().ProcessName); } OnChanged(); this.Close(); }
/// <summary> /// Copy all properties associated with a DataSourceName from local machine to local user /// </summary> /// <param name="p_strDsn"></param> public void CopyLocalMachineDsn(string p_strDsn) { // if (!this.LocalMachineDSNKeyExist(p_strDsn)) { m_intError = -1; MessageBox.Show("Registry does not have a local machine ODBC.INI key for DSN name " + p_strDsn, "ODBCManager", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); return; } //delete the current user DSN subkey if it exists if (this.CurrentUserDSNKeyExist(p_strDsn)) { m_oCurrentUserRegKey = Registry.CurrentUser.OpenSubKey(ODBC_INI_REG_PATH, true); m_oCurrentUserRegKey.DeleteSubKey(p_strDsn); } else { m_oCurrentUserRegKey = Registry.CurrentUser.OpenSubKey(ODBC_INI_REG_PATH, true); } m_oCurrentUserRegKey.CreateSubKey(p_strDsn); m_oLocalMachineRegKey = Registry.LocalMachine.OpenSubKey(ODBC_INI_REG_PATH + "\\" + p_strDsn, false); m_oCurrentUserRegKey = Registry.CurrentUser.OpenSubKey(ODBC_INI_REG_PATH + "\\" + p_strDsn, true); string[] strValueNames = m_oLocalMachineRegKey.GetValueNames(); foreach (string strValueName in strValueNames) { m_oCurrentUserRegKey.SetValue(strValueName, (string)m_oLocalMachineRegKey.GetValue(strValueName)); } m_oLocalMachineRegKey.Close(); m_oCurrentUserRegKey.Close(); }
private void ToggleSwitch_IsCheckedChanged_1(object sender, EventArgs e) { var btn = sender as ToggleSwitch; if (btn.IsChecked == true) { Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true); Assembly curAssembly = Assembly.GetExecutingAssembly(); key.SetValue(curAssembly.GetName().Name, curAssembly.Location); } else { Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true); Assembly curAssembly = Assembly.GetExecutingAssembly(); if (key.GetValue(curAssembly.GetName().Name) != null) { key.DeleteValue(curAssembly.GetName().Name); } } XMLHelper.SaveObjAsXml(ProgramData.Instance, "StikyNotesData.xml"); }
/// <summary> /// 应用程序的主入口点。 /// </summary> /// static bool isFirstRun() { Microsoft.Win32.RegistryKey reg = null; try { reg = Registry.LocalMachine.OpenSubKey("SOFTWARE\\VEWVRT", true); } catch { } string runKey = ""; if (null == reg) { reg = Registry.LocalMachine.CreateSubKey("SOFTWARE\\VEWVRT"); reg.SetValue("firstrun_r", "0"); return(true); } runKey = (string)reg.GetValue("firstrun_r"); if (runKey == "0") { return(false); } reg.SetValue("firstrun_r", "0"); return(true); }
public void TestInitialize() { var counter = Interlocked.Increment(ref s_keyCount); _testKey += counter.ToString(); _rk1 = Microsoft.Win32.Registry.CurrentUser; if (_rk1.OpenSubKey(_testKey) != null) _rk1.DeleteSubKeyTree(_testKey); if (_rk1.GetValue(_testKey) != null) _rk1.DeleteValue(_testKey); //created the test key. if that failed it will cause many of the test scenarios below fail. try { _rk1 = Microsoft.Win32.Registry.CurrentUser; _rk2 = _rk1.CreateSubKey(_testKey); if (_rk2 == null) { Assert.False(true, "ERROR: Could not create test subkey, this will fail a couple of scenarios below."); } else _keyString = _rk2.ToString(); } catch (Exception e) { Assert.False(true, "ERROR: unexpected exception, " + e.ToString()); } }
private void SyncWallpaperStyle() { try { // open the Desktop key Microsoft.Win32.RegistryKey DesktopKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Control Panel\\Desktop"); // read the wallpaperstyle key and cast its values to my custom enum _StretchMode = (Orbit.Configuration.BackgroundStretchMode) int.Parse((string)DesktopKey.GetValue("WallpaperStyle")); // confirm it's not being tiled // only happens on stretch mode 0 if (_StretchMode == 0) { // if tilewallpaper is 1, then it's tiled if (DesktopKey.GetValue("TileWallpaper").ToString() == "1") { _StretchMode = Orbit.Configuration.BackgroundStretchMode.Tile; } } // debug out stretch mode change //System.Diagnostics.Debug.WriteLine(_StretchMode.ToString()+", number: "+DesktopKey.GetValue("WallpaperStyle").ToString()); // close the key DesktopKey.Close(); } catch (Exception ex) { // in case it fails (be registry access problems OR weird registry value), set stretch to none _StretchMode = Orbit.Configuration.BackgroundStretchMode.None; // debug out error System.Diagnostics.Debug.WriteLine(ex.Message + "\n" + ex.StackTrace); } }
private static string GetSystemDefaultBrowser() { string name = string.Empty; Microsoft.Win32.RegistryKey regKey = null; try { regKey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey("http\\shell\\open\\command", false); name = regKey.GetValue(null).ToString().ToLower().Replace(string.Concat('"'), ""); if (!name.EndsWith("exe")) { name = name.Substring(0, name.LastIndexOf(".exe") + 4); } else { name = "iexplore"; } } catch (System.Exception) { name = string.Format("温馨提示:\n满足下面的条件即可访问:\n1、已经安装了浏览器\n2、设置了默认浏览器", new object[0]); } finally { if (regKey != null) { regKey.Close(); } } return(name); }
public static void GetGOGApps() { string GOGFilepath; string GOGRegistry_key = @"SOFTWARE\WOW6432Node\GOG.com\GalaxyClient\paths"; using (Microsoft.Win32.RegistryKey key = Registry.LocalMachine.OpenSubKey(GOGRegistry_key)) { GOGFilepath = key.GetValue("client").ToString() + "\\GalaxyClient.exe"; } Exe gogExe = new Exe(); gogExe.gameName = "GOG Galaxy"; gogExe.filePath = GOGFilepath; Exes.Add(gogExe); string registry_key = @"SOFTWARE\WOW6432Node\GOG.com\Games"; using (Microsoft.Win32.RegistryKey key = Registry.LocalMachine.OpenSubKey(registry_key)) { foreach (string subkey_name in key.GetSubKeyNames()) { using (RegistryKey subkey = key.OpenSubKey(subkey_name)) { Exe exe = new Exe(); exe.gameName = subkey.GetValue("GAMENAME").ToString(); exe.filePath = subkey.GetValue("LAUNCHCOMMAND").ToString(); exe.launcher = "GOG Galaxy"; Exes.Add(exe); } } } }
static int createScanEvents1() { int iRet = 0; //add two new events string sReg = ITC_KEYBOARD.CUSBkeys.getRegLocation(); Microsoft.Win32.RegistryKey reg = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(sReg + "\\Events\\State", true); int iNumKeys = reg.ValueCount; //check if there is already a StateLeftScan1 entry bool bFound = false; string[] sValueNames = reg.GetValueNames(); for (int i = 1; i <= iNumKeys; i++) { string t = (string)reg.GetValue(sValueNames[i - 1]); if (t.Equals("StateLeftScan1", StringComparison.OrdinalIgnoreCase)) { bFound = true; iRet = Convert.ToInt16(sValueNames[i - 1].Substring("Event".Length)); break; } } if (!bFound) //create new entries { //for(int i=1; i<=sValueNames.Length; reg.SetValue("Event" + (iNumKeys + 1).ToString(), "StateLeftScan1"); reg = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(sReg + "\\Events\\Delta", true); reg.SetValue("Event" + (iNumKeys + 1).ToString(), "DeltaLeftScan1"); iRet = iNumKeys + 1; } reg.Close(); return(iRet); }
public static bool FindVisualStudio2008(out ITaskItem toolPath, TaskLoggingHelper log) { bool toolFound = false; toolPath = new TaskItem(); string toolName = "Microsoft Visual Studio 2008"; using (Microsoft.Win32.RegistryKey regkey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\VisualStudio\9.0")) { if (regkey != null) { toolPath.ItemSpec = (string)regkey.GetValue("toolPath", ""); } } toolFound = (toolPath.ItemSpec.Length != 0); if (log != null) { if (toolFound) { log.LogMessageFromResources("ToolFound", toolName, toolPath); } else { log.LogMessageFromResources("ToolNotFound", toolName); } } return(toolFound); }
private void AddToAutostart(bool enabled, string name) { string Path = Directory.GetCurrentDirectory(); string yourKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Run"; Microsoft.Win32.RegistryKey startupKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(yourKey); if (enabled) { if (startupKey.GetValue(name) == null) { startupKey.Close(); startupKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(yourKey, true); // Add startup reg key startupKey.SetValue(name, Path.ToString()); startupKey.Close(); } } else { // remove startup startupKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(yourKey, true); startupKey.DeleteValue(name, false); startupKey.Close(); } }
private static List <RegistrationElementDataClass> getValue(Microsoft.Win32.RegistryKey registrationSubKey, string subKeyName, int level) { List <RegistrationElementDataClass> registrationData = new List <RegistrationElementDataClass>(); List <string> valueNames = registrationSubKey.GetValueNames().ToList(); if (valueNames.Count > 0) { foreach (string valueName in valueNames) { RegistryValueKind typeOfValue = RegistryValueKind.None; object registrationValue = registrationSubKey.GetValue(valueName); string valueStirng = getStringValue(registrationSubKey, registrationValue, valueName, ref typeOfValue); registrationData.Add(new RegistrationElementDataClass() { RegistrationElementPath = registrationSubKey.Name, ValueName = valueName, ValueObject = registrationValue, RegistryValueType = typeOfValue, ValueString = valueStirng, Level = level, KeyName = subKeyName, UserName = Environment.UserName, }); }//END foreach (string valueName in valueNames) } return(registrationData); }
public int ReadIntegrer(string KeyName) { // Opening the registry key Microsoft.Win32.RegistryKey rk = Microsoft.Win32.Registry.CurrentUser; // Open a subKey as read-only Microsoft.Win32.RegistryKey sk1 = rk.OpenSubKey(@"Software\Cidra\Wam"); // If the RegistrySubKey doesn't exist -> (null) if (sk1 == null) { throw new NullReferenceException(subKey + " key doesn't exist"); } else { try { // If the RegistryKey exists I get its value // or null is returned. return(int.Parse(sk1.GetValue(KeyName.ToUpper()).ToString())); } catch (Exception ex) { // AAAAAAAAAAARGH, an error! throw new NullReferenceException(ex.Message + "Reading registry ", ex); } } }
public static string GetMsBuildPath(IServiceProvider serviceProvider, string version) { string msBuildPath = null; using (RegistryKey root = VSRegistry.RegistryRoot(serviceProvider, __VsLocalRegistryType.RegType_Configuration, false)) { // Get the value from the registry using (RegistryKey vsKey = root.OpenSubKey("MSBuild", false)) { msBuildPath = (string)vsKey.GetValue("MSBuildBinPath", null); } } if (!string.IsNullOrEmpty(msBuildPath)) { return(msBuildPath); } // The path to MSBuild was not found in the VisualStudio's registry hive, so try to // find it in the new MSBuild hive. string registryPath = string.Format(CultureInfo.InvariantCulture, "Software\\Microsoft\\MSBuild\\ToolsVersions\\{0}", version); using (Microsoft.Win32.RegistryKey msbuildKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(registryPath, false)) { msBuildPath = (string)msbuildKey.GetValue("MSBuildToolsPath", null); } if (string.IsNullOrEmpty(msBuildPath)) { string error = SR.GetString(SR.ErrorMsBuildRegistration, CultureInfo.CurrentUICulture); throw new FileLoadException(error); } return(msBuildPath); }
public static Int32? GetDword( RegistryKey rk, string value, Int32? defaultValue = null ) { var result = rk.GetValue( value ) as Int32?; if( null == result && null != defaultValue ) { result = defaultValue; } return result; }
public static string GetProductInfo(String strKey, int optionalMIVersion = 0) { //Returns the value that belongs to the given keyname string registryKey = @"SOFTWARE\MapInfo\MapInfo\Professional"; using (Microsoft.Win32.RegistryKey prokey = Registry.LocalMachine.OpenSubKey(registryKey)) { string result = ""; var versions = from a in prokey.GetSubKeyNames() let r = prokey.OpenSubKey(a) let name = r.Name let slashindex = name.LastIndexOf(@"\") select new { MapinfoVersion = Convert.ToInt32(name.Substring(slashindex + 1, name.Length - slashindex - 1)) }; foreach (var item in versions) { if (optionalMIVersion == 0 || optionalMIVersion == item.MapinfoVersion) { string registryResultKey = registryKey + "\\" + Convert.ToString(item.MapinfoVersion); Microsoft.Win32.RegistryKey provkey = Registry.LocalMachine.OpenSubKey(registryResultKey); result = provkey.GetValue(strKey).ToString(); } } return(result); } }
//检测软件是否安装 private static bool checkAPPInWindows(String app) { //定义注册表操作类并指向注册表的软件信息目录 Microsoft.Win32.RegistryKey uninstallNode = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"); foreach (string subKeyName in uninstallNode.GetSubKeyNames()) { Microsoft.Win32.RegistryKey subKey = uninstallNode.OpenSubKey(subKeyName); //定义注册表搜索子类 object displayName = subKey.GetValue("DisplayName"); //搜索键名为DisplayName的键————根据软件名字查找 //针对特定软件,检查“InstallRoot” //RegistryKey akeytwo = rk.OpenSubKey(@"SOFTWARE\Kingsoft\Office\6.0\common\"); //查询wps——excel表格 //string filewps = akeytwo.GetValue("InstallRoot").ToString(); //if (File.Exists(filewps + @"\office6\et.exe")) if (displayName != null) { if (displayName.ToString().Contains(app)) { return(true); } } } return(false); }
protected override void ProcessRecord() { string javapath = String.Empty; string path = String.Empty; using (Microsoft.Win32.RegistryKey rk = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\\Wow6432Node\\JavaSoft\\Java Runtime Environment\\")) { if (rk != null) { string currentVersion = rk.GetValue("CurrentVersion").ToString(); if (currentVersion != null) { using (Microsoft.Win32.RegistryKey key = rk.OpenSubKey(currentVersion)) { if (key != null) { path = key.GetValue("JavaHome").ToString(); } } } } } if (Name != null) { javapath += path; } WriteObject(javapath); }
//- Default search should be: //- HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders //- AppData / C:\Documents and Settings\cyrille\Application Data\Autodesk\Tools\settings.xml //- HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders //- Common AppData / C:\Documents and Settings\All\Application Data\Autodesk\Tools\settings.xml private string BuildName(bool bAllUsers, bool bMustExits) { if (bAllUsers == false) { Microsoft.Win32.RegistryKey keycu = Microsoft.Win32.Registry.CurrentUser.OpenSubKey( "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders" ); string fileName = string.Format("{0}\\{1}\\{2}\\{3}.xml", keycu.GetValue("AppData"), mCompany, mAppName, mBaseName); if (System.IO.File.Exists(fileName) == true || bMustExits == false) { return(fileName); } } Microsoft.Win32.RegistryKey keylm = Microsoft.Win32.Registry.LocalMachine.OpenSubKey( "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders" ); string fileNameAll = string.Format("{0}\\{1}\\{2}\\{3}.xml", keylm.GetValue("Common AppData"), mCompany, mAppName, mBaseName); if (System.IO.File.Exists(fileNameAll) == true || bMustExits == false) { return(fileNameAll); } return(null); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Checks if a registry value exists. /// </summary> /// <param name="key">The base registry key of the key to check</param> /// <param name="subKey">Name of the group key, or string.Empty if there is no /// groupKeyName.</param> /// <param name="regEntry">The name of the registry entry.</param> /// <param name="value">[out] value of the registry entry if it exists; null otherwise.</param> /// <returns><c>true</c> if the registry entry exists, otherwise <c>false</c></returns> /// ------------------------------------------------------------------------------------ public static bool RegEntryExists(RegistryKey key, string subKey, string regEntry, out object value) { value = null; if (key == null) return false; if (string.IsNullOrEmpty(subKey)) { value = key.GetValue(regEntry); if (value != null) return true; return false; } if (!KeyExists(key, subKey)) return false; using (RegistryKey regSubKey = key.OpenSubKey(subKey)) { Debug.Assert(regSubKey != null, "Should have caught this in the KeyExists call above"); if (Array.IndexOf(regSubKey.GetValueNames(), regEntry) >= 0) { value = regSubKey.GetValue(regEntry); return true; } return false; } }
public static void GetEpicApps() { string epicManifestFilepath; string registry_key = @"SOFTWARE\WOW6432Node\Epic Games\EpicGamesLauncher"; using (Microsoft.Win32.RegistryKey key = Registry.LocalMachine.OpenSubKey(registry_key)) { epicManifestFilepath = key.GetValue("AppDataPath").ToString() + "\\Manifests"; FileInfo[] manifests; System.IO.DirectoryInfo directoryInfo = new System.IO.DirectoryInfo(@epicManifestFilepath); manifests = directoryInfo.GetFiles("*.item", SearchOption.TopDirectoryOnly); foreach (FileInfo manifest in manifests) { StreamReader file = new StreamReader(manifest.FullName); string line; string gameName = "NULL"; string gameFilepath = "NULL"; string exeName = "NULL"; while ((line = file.ReadLine()) != null) { if (line.Contains("DisplayName")) { line = line.Substring(17, line.Length - 17); line = line.TrimEnd(','); line = line.TrimEnd('"'); gameName = line; } else if (line.Contains("InstallLocation")) { line = line.Substring(21, line.Length - 21); line = line.TrimEnd(','); line = line.TrimEnd('"'); gameFilepath = line; } else if (line.Contains("LaunchExecutable")) { line = line.Substring(22, line.Length - 22); line = line.TrimEnd(','); line = line.TrimEnd('"'); exeName = line; } } gameFilepath = gameFilepath + "\\" + exeName; Exe newExe = new Exe(); newExe.gameName = gameName; newExe.filePath = gameFilepath; newExe.launcher = "Epic Games"; Exes.Add(newExe); } } }
private void button2_Click(object sender, EventArgs e) { try { //清除内容 listBox1.Items.Clear(); NumAdd = 0; //定义注册表顶级结点 命名空间Microsoft.Win32 Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey ("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\TypedPaths", true); //判断键是否存在 if (key != null) { //检索包含此项关联的所有值名称 即url1 url2 url3 string[] names = key.GetValueNames(); foreach (string str in names) { //获取url中相关联的值 listBox1.Items.Add(key.GetValue(str).ToString()); NumAdd++; } //显示获取文件总数 this.textBox1.Text = NumAdd + "个文件"; } /* 注册表的使用操作 * //创建键 * //在HKEY_CURRENT_USER下创建Eastmount键 * RegistryKey test1 = Registry.CurrentUser.CreateSubKey("Eastmount"); * //创建键结构 HKEY_CURRENT_USER\Software\Eastmount\test2 * RegistryKey test2 = Registry.CurrentUser.CreateSubKey(@"Software\Eastmount\test2"); * * //删除HKEY_CURRENT_USER下创建Eastmount键 * Registry.CurrentUser.DeleteSubKey("Eastmount"); * //删除创建的子键test2 * Registry.CurrentUser.DeleteSubKeyTree(@"Software\Eastmount"); * * //获取Environment中路径 * string strPath; * strPath = (string)Registry.GetValue(@"HKEY_CURRENT_USER\Environment", * "path", "Return this default if path does not exist"); * MessageBox.Show(strPath); * * //设置键值Version=1.25 * Registry.SetValue(@"HKEY_CURRENT_USER\Software\YourSoftware", "Version", "1.25"); * //设置键值 * Registry.SetValue(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\TypedPaths", "url4", @"E:\dota"); * * //隐藏桌面我的电脑 * RegistryKey rgK = Registry.CurrentUser.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel"); * rgK.SetValue("{20D04FE0-3AEA-1069-A2D8-08002B30309D}",0); */ } catch (Exception msg) //异常处理 { MessageBox.Show(msg.Message); } }
public static void GetSteamApps() { List <string> steamLibraryFilepaths = new List <string>(); List <DirectoryInfo> gameFolderPaths = new List <DirectoryInfo>(); Dictionary <string, string> manifestInfo = new Dictionary <string, string>(); string registry_key = @"SOFTWARE\WOW6432Node\Valve\Steam"; using (Microsoft.Win32.RegistryKey key = Registry.LocalMachine.OpenSubKey(registry_key)) { steamFilepath = key.GetValue("InstallPath").ToString(); } manifestInfo = ReadSteamGameManifest(); steamLibraryFilepaths.Add(steamFilepath); string libraryFileManifestPath = steamFilepath + "\\steamapps\\libraryfolders.vdf"; StreamReader file = new StreamReader(@libraryFileManifestPath); string line; while ((line = file.ReadLine()) != null) { if (line.Contains(":\\")) { line = line.Substring(7, line.Length - 7); line = line.TrimEnd('"'); steamLibraryFilepaths.Add(line); } } for (int i = 0; i < steamLibraryFilepaths.Count; i++) { steamLibraryFilepaths[i] = steamLibraryFilepaths[i] + "\\steamapps\\common"; //Console.WriteLine(steamLibraryFilepaths[i]); } foreach (string filepath in steamLibraryFilepaths) { DirectoryInfo directoryInfo = new DirectoryInfo(@filepath); gameFolderPaths.AddRange(directoryInfo.GetDirectories()); } foreach (DirectoryInfo gameFolder in gameFolderPaths) { //Console.WriteLine(gameFolder.Name); if (manifestInfo.ContainsKey(gameFolder.Name)) { Exe newExe = new Exe(); newExe.gameName = gameFolder.Name; newExe.filePath = gameFolder.FullName + "\\" + manifestInfo[gameFolder.Name]; newExe.launcher = "Steam"; Console.WriteLine(newExe.filePath); Exes.Add(newExe); } } }