private static string GetKeyName(RegistryType type) { switch (type) { case RegistryType.ConnectStatus: return(KEY_CONNECT_STATUS); case RegistryType.LogTime: return(KEY_LOG_TIME); case RegistryType.LogSend: return(KEY_LOG_SEND); case RegistryType.DateLogSend: return(KEY_DATE_LOG_SEND); case RegistryType.ServerUrl: return(KEY_SERVER_URL); case RegistryType.TimeScheduler: return(KEY_TIME_SCHEDULER); default: return(""); } }
/// <summary> /// 写入注册表值 /// </summary> /// <param name="type">注册表类型</param> /// <param name="registryPath">注册表路径</param> /// <param name="itemName">项名称</param> /// <param name="data">注册表值</param> /// <returns></returns> public static OperationReturn WriteItemData(RegistryType type, string registryPath, string itemName, object data) { OperationReturn optReturn = new OperationReturn(); optReturn.Result = true; optReturn.Code = Defines.RET_SUCCESS; try { RegistryKey rootKey; if (type == RegistryType.LocalMerchine) { rootKey = Registry.LocalMachine; } else { rootKey = Registry.CurrentUser; } var key = rootKey.CreateSubKey(registryPath); if (key != null) { key.SetValue(itemName, data); } } catch (Exception ex) { optReturn.Result = false; optReturn.Code = Defines.RET_FAIL; optReturn.Message = ex.Message; optReturn.Exception = ex; } return(optReturn); }
public extern static int RegQueryValueEx( [In] IntPtr hKey, [In] string ValueName, [In] UInt32 Reserved, [In, Out] ref RegistryType Type, [In, Out] StringBuilder Data, [In, Out] ref UInt32 cbData);
public void LoadItems(RegistryType registryType) { _hostController.SetCurrentController(registryType); SetCurrentCollectionManager(registryType); LoadItems(_currentCollectionManager.GetItems()); }
/// <summary> /// /// </summary> /// <param name="identifier"></param> /// <param name="readOnly">Indicates whether the IRegistry is ReadOnly. If true, an exception will be thrown if the IRegistry /// attempts a write.</param> /// <param name="registryType"></param> protected RegistryBase(IRegistryIdentifier identifier, RegistryType registryType, bool readOnly) { this.Clear(); this.Identifier = identifier; this.ReadOnly = readOnly; this.RegistryType = registryType; }
public static extern bool SetupDiGetDeviceRegistryProperty( IntPtr deviceInfoSet, DeviceInfoData deviceInfoData, Spdrp property, out RegistryType propertyRegDataType, byte[] propertyBuffer, uint propertyBufferSize, out uint requiredSize);
public extern static bool SetupDiGetDeviceRegistryProperty( [In] IntPtr DeviceInfo, [In] SP_DEVINFO_DATA DeviceInfoData, [In] DeviceRegistryProperty Property, [In, Out] ref RegistryType PropertyRegDataType, [In, Out] StringBuilder PropertyBuffer, [In] UInt32 PropertyBufferSize, [In, Out] ref UInt32 RequiredSize);
public FreightRegistry(string networkID, MassStorageCrate crate, ItemBase item, int lowstock, int highstock, RegistryType datatype) { this.NetworkID = networkID; this.MassStorage = crate; this.FreightItem = item; this.LowStock = lowstock; this.HighStock = highstock; this.DataType = datatype; }
/// <summary> /// The create. /// </summary> /// <param name="registryType"> /// The registry type. /// </param> /// <param name="data"> /// The data. /// </param> /// <returns> /// The <see cref="BaseDeviceProperty"/>. /// </returns> public BaseDeviceProperty Create(RegistryType registryType, byte[] data) { switch (registryType) { case RegistryType.Unknown: return new DeviceNullProperty(data); case RegistryType.Sz: return new DeviceStringProperty(data); case RegistryType.MultiSz: return new DeviceMultiStringProperty(data); default: return new DeviceNullProperty(data); } }
private RegistryProcess ProcessFromType(RegistryType type) { switch (type) { case RegistryType.Baby: return(new BabyRegistryProcess()); case RegistryType.Marry: return(new MarryRegistryProcess()); case RegistryType.Unmarry: return(new UnmarryRegistryProcess()); default: throw new ArgumentException(); } }
private void SetCurrentCollectionManager(RegistryType registryType) { switch (registryType) { case RegistryType.Fuel: _currentCollectionManager = _fuelCollectionManager; break; case RegistryType.Tank: _currentCollectionManager = _tankCollectionManager; break; case RegistryType.Nozzle: _currentCollectionManager = _nozzleCollectionManager; break; } }
/// <summary> /// The create. /// </summary> /// <param name="registryType"> /// The registry type. /// </param> /// <param name="data"> /// The data. /// </param> /// <returns> /// The <see cref="BaseDeviceProperty"/>. /// </returns> public BaseDeviceProperty Create(RegistryType registryType, byte[] data) { switch (registryType) { case RegistryType.Unknown: return(new DeviceNullProperty(data)); case RegistryType.Sz: return(new DeviceStringProperty(data)); case RegistryType.MultiSz: return(new DeviceMultiStringProperty(data)); default: return(new DeviceNullProperty(data)); } }
/// <summary> /// Lấy các giá trị cấu hình lưu trong Registry /// </summary> /// <param name="type"></param> /// <returns></returns> public static string GetConfigValueFromRegistry(RegistryType type) { var keyName = GetKeyName(type); if (!CheckRegistryKeyInCurrentUser(REGISTRY_PATH_CONFIG)) { return(null); } var key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(REGISTRY_PATH_CONFIG, RegistryKeyPermissionCheck.ReadWriteSubTree); var result = key != null?key.GetValue(keyName) : null; if (result != null) { return(result.ToString()); } return(string.Empty); }
/// <summary> /// 获取指定注册表路径下指定项的值 /// </summary> /// <param name="type">注册表类型</param> /// <param name="registryPath">注册表路径</param> /// <param name="itemName">项名称</param> /// <returns></returns> public static OperationReturn GetItemData(RegistryType type, string registryPath, string itemName) { OperationReturn optReturn = new OperationReturn(); optReturn.Result = true; optReturn.Code = Defines.RET_SUCCESS; try { RegistryKey rootKey; if (type == RegistryType.LocalMerchine) { rootKey = Registry.LocalMachine; } else { rootKey = Registry.CurrentUser; } var key = rootKey.OpenSubKey(registryPath); if (key == null) { optReturn.Result = false; optReturn.Code = Defines.RET_OBJECT_NULL; optReturn.Message = string.Format("Registry key not exsit.\t{0}", registryPath); return(optReturn); } var value = key.GetValue(itemName); if (value == null) { optReturn.Result = false; optReturn.Code = Defines.RET_OBJECT_NULL; optReturn.Message = string.Format("Registry item not exsit.\t{0}", itemName); return(optReturn); } optReturn.Message = value.ToString(); optReturn.Data = value; } catch (Exception ex) { optReturn.Result = false; optReturn.Code = Defines.RET_FAIL; optReturn.Message = ex.Message; optReturn.Exception = ex; } return(optReturn); }
public void SelectTab(RegistryType type) { switch (type) { case RegistryType.Fuel: rbFuels.Checked = true; break; case RegistryType.Tank: rbTanks.Checked = true; break; case RegistryType.Nozzle: rbNozzles.Checked = true; break; default: break; } }
public static void SetCongifValueToRegistry(RegistryType type, string value) { RegistryKey key; if (!CheckRegistryKeyInCurrentUser(REGISTRY_PATH_CONFIG)) { key = Microsoft.Win32.Registry.CurrentUser.CreateSubKey(REGISTRY_PATH_CONFIG, RegistryKeyPermissionCheck.ReadWriteSubTree); } else { key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(REGISTRY_PATH_CONFIG, RegistryKeyPermissionCheck.ReadWriteSubTree); } if (key != null) { key.SetValue(GetKeyName(type), value); } else { key.SetValue(GetKeyName(type), string.Empty); } }
public void SetCurrentController(RegistryType registryType) { switch (registryType) { case RegistryType.Fuel: UpdateViewsVisibility(true, false, false); _currentController = _fuelController; break; case RegistryType.Tank: UpdateViewsVisibility(false, true, false); _currentController = _tankController; break; case RegistryType.Nozzle: UpdateViewsVisibility(false, false, true); _currentController = _nozzleController; break; } _view.SetSaveButtonTooltip(_currentController.GetSaveButtonTooltip()); }
public static IRegistry GetRegistry(RegistryType registryType = RegistryType.HKLM) { switch (registryType) { case RegistryType.ClassesRoot: return(new ClassesRootRegistry()); case RegistryType.CurrentUser: return(new CurrentUserRegistry()); case RegistryType.HKLM: return(new HKLMRegistry()); case RegistryType.Users: return(new UsersRegistry()); case RegistryType.CurrentConfig: return(new CurrentConfigRegistry()); default: return(new HKLMRegistry()); } }
public static T GetValue <T>(string key, string path = null, RegistryType registryType = RegistryType.CurrentUser) { if (string.IsNullOrEmpty(key)) { throw new ArgumentNullException("key"); } var root = GetRoot(registryType); using (var registryKey = root.OpenSubKey(RootPath + (path ?? string.Empty), RegistryKeyPermissionCheck.ReadSubTree, RegistryRights.ReadKey)) { if (registryKey != null) { var value = registryKey.GetValue(key); if (value != null) { return(value.CastTo <T>()); } } } return(default(T)); }
private static string GetDeviceRegistryProperty(IntPtr hDeviceInfo, SP_DEVINFO_DATA deviceInfoData, DeviceRegistryProperty propertyType) { RegistryType propertyRegistryType = RegistryType.REG_NONE; StringBuilder propertyBuffer = new StringBuilder(512); UInt32 sizeRequired = 0; bool result = SetupDi.SetupDiGetDeviceRegistryProperty( hDeviceInfo, deviceInfoData, propertyType, ref propertyRegistryType, propertyBuffer, (UInt32)propertyBuffer.Capacity, ref sizeRequired); if ((result == true) & (propertyRegistryType == RegistryType.REG_SZ)) { return(propertyBuffer.ToString()); } else { return(null); } }
public static bool IsReg(this Type type, List <RegistryType> regTypes, out RegistryType regType) { regType = regTypes.Where(x => x.Registry == type).FirstOrDefault(); return(regType != null); }
public static extern bool SetupDiGetDeviceRegistryProperty( IntPtr deviceInfoSet, DeviceInfoData deviceInfoData, Spdrp property, out RegistryType propertyRegDataType, byte[] propertyBuffer, uint propertyBufferSize, out uint requiredSize);
/// <summary> /// /// </summary> /// <param name="identifier"></param> /// <param name="registryType"></param> /// <param name="readOnly">Indicates whether the IRegistry is ReadOnly. If true, an exception will be thrown if the IRegistry /// attempts a write.</param> public Registry(IRegistryIdentifier identifier, RegistryType registryType, bool readOnly) : base(identifier: identifier, registryType: registryType, readOnly: readOnly) { }
public Registry RegistryFromType(RegistryType type) { return(new Registry(ProcessFromType(type))); }
public static extern int RegGetValue(UIntPtr hkey, string lpSubKey, string lpValue, RegistryFlags dwFlags, out RegistryType pdwType, IntPtr pvData, ref uint pcbData);
/// <summary> /// Return the list of all available COM port into the system /// </summary> /// <returns></returns> public static ReadOnlyCollection <SerialPortInfo> GetAvailablePorts() { IntPtr hdevInfo = SetupDi.SetupDiGetClassDevs( ref GUID_DEVINTERFACE_COMPORT, null, IntPtr.Zero, SetupDIGetClassDevsFlags.DIGCF_PRESENT | SetupDIGetClassDevsFlags.DIGCF_DEVICEINTERFACE); if (hdevInfo == INVALID_HANDLE_VALUE) { throw new Exception("can't access to serial port communication information."); } List <SerialPortInfo> ports = new List <SerialPortInfo>(); uint index = 0; SP_DEVINFO_DATA deviceInfoData = new SP_DEVINFO_DATA(); while (SetupDi.SetupDiEnumDeviceInfo(hdevInfo, index++, deviceInfoData) == true) { IntPtr hKey = SetupDi.SetupDiOpenDevRegKey( hdevInfo, deviceInfoData, SetupDiOpenDevRegKeyScopeFlags.DICS_FLAG_GLOBAL, 0, SetupDiOpenDevRegKeyKeyTypeFlags.DIREG_DEV, REGSAM.KEY_QUERY_VALUE); if (hKey != IntPtr.Zero) { SerialPortInfo portInfo = new SerialPortInfo(); UInt32 resultLength = 1024; IntPtr registryName = Marshal.AllocHGlobal(1024); var retValue = Registry.NtQueryKey(hKey, 3, registryName, 1024, ref resultLength); if (retValue == 0) { string registryNameStr = Marshal.PtrToStringAuto((IntPtr)(registryName.ToInt32() + 4), Marshal.ReadInt32(registryName) / 2); Marshal.FreeHGlobal(registryName); var registryPath = registryNameStr.Split('\\'); if (registryPath != null && registryPath.Length > 3) { var sNumber = registryPath[registryPath.Length - 2]; if (sNumber != null && sNumber.Contains('_')) { portInfo.SerialName = sNumber.Remove(sNumber.IndexOf('_')); } else { portInfo.SerialName = sNumber; } var deviceVidPid = registryPath[registryPath.Length - 3].ToUpperInvariant(); if (deviceVidPid != null && deviceVidPid.Length > 0 && deviceVidPid.Contains("pid_") && deviceVidPid.Contains("vid_")) { try { char separator = '&'; if (deviceVidPid.Contains('&')) { separator = '&'; } else if (deviceVidPid.Contains('+')) { separator = '+'; } var position = deviceVidPid.IndexOf("vid_") + 4; var vid = deviceVidPid.Substring(position, deviceVidPid.IndexOf(separator) - position); position = deviceVidPid.IndexOf("pid_") + 4; var pid = deviceVidPid.Substring(position, deviceVidPid.Length - position); if (pid.Contains(separator)) { pid = pid.Remove(pid.IndexOf(separator)); } portInfo.DevicePid = int.Parse(pid, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture); portInfo.DeviceVid = int.Parse(vid, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture); } catch { } } } } RegistryType type = RegistryType.REG_NONE; UInt32 capacity; StringBuilder data = new StringBuilder(256); capacity = (UInt32)data.Capacity; int result = Registry.RegQueryValueEx(hKey, "PortName", 0, ref type, data, ref capacity); if ((result == Registry.ERROR_SUCCESS) & (type == RegistryType.REG_SZ)) { portInfo.Name = data.ToString(); string property = GetDeviceRegistryProperty(hdevInfo, deviceInfoData, DeviceRegistryProperty.SPDRP_DEVICEDESC); if (property != null) { portInfo.Description = property; } property = GetDeviceRegistryProperty(hdevInfo, deviceInfoData, DeviceRegistryProperty.SPDRP_MFG); if (property != null) { portInfo.Manufacturer = property; } property = GetDeviceRegistryProperty(hdevInfo, deviceInfoData, DeviceRegistryProperty.SPDRP_FRIENDLYNAME); if (property != null) { portInfo.FriendlyName = property; } property = GetDeviceRegistryProperty(hdevInfo, deviceInfoData, DeviceRegistryProperty.SPDRP_LOCATION_INFORMATION); if (property != null) { portInfo.LocalInformation = property; } property = GetDeviceRegistryProperty(hdevInfo, deviceInfoData, DeviceRegistryProperty.SPDRP_SERVICE); if (property != null) { portInfo.Service = property; } } ports.Add(portInfo); Registry.RegCloseKey(hKey); } } SetupDi.SetupDiDestroyDeviceInfoList(hdevInfo); //PatchInZModemSerials(ports); return(new ReadOnlyCollection <SerialPortInfo>(ports)); }
public static void SaveEntity <T>(T entity, RegistryType registryType = RegistryType.CurrentUser) { var root = GetRoot(registryType); SaveEntity(entity.GetType(), entity, root); }
public static T GetEntity <T>(RegistryType registryType = RegistryType.CurrentUser) where T : class { var root = GetRoot(registryType); return(GetEntity(typeof(T), root) as T); }
private static RegistryKey GetRoot(RegistryType registryType) { return(registryType == RegistryType.CurrentUser ? CurrentUser : LocalMachine); }
public void setRegistryType(RegistryType _n) { this.registryType = _n; }
private void NavigateToItem(Guid id, RegistryType type) { _view.SelectTab(type); _itemsController.SelectItem(id); }
private Registry(string url, RegistryType type) { _url = url; _type = type; }