注册表的操作:
得到系统的AppData/Roaming文件夹路径,这个值在注册表里面存储着的。可以用下面这个方法得到。
GetValueData("Software//Microsoft//Windows//CurrentVersion//Explorer//Shell Folders", "AppData");
下面这个是得到默认的Roaming文件夹
return GetINIPath().Substring(0, 9) + "Default//AppData//Roaming";
写入特定类型的键值。
RegistryKey reg = Registry.CurrentUser.CreateSubKey(strKey);
RegistryValueKind rvk = reg.GetValueKind(strValue);
reg.SetValue(strValue, strData, rvk);
这个函数是指定写入值得类型。strType值是string dword,跟注册表里面的键值类型一样。
switch (strType)
{
case "string":
reg.SetValue(strValue, strData, RegistryValueKind.String);
break;
case "dword":
reg.SetValue(strValue, strData, RegistryValueKind.DWord);
break;
default:
break;
}
strKey是对应的目录,strValue是对应的键名
string idVal = string.Empty;
RegistryKey reg = Registry.CurrentUser.OpenSubKey(strKey);
idVal = reg.GetValue(strValue).ToString();
附录:
Vista与XP用户配置文件对照表
Vista新路径 | XP旧路径 |
.../AppData/Roaming | .../Application Data |
N/A | .../Local Settings |
.../AppData/Local | .../Local Settings/Application Data |
.../AppData/Local/Microsoft/Windows/History | .../Local Settings/History |
.../AppData/Local/Temp | .../Local Settings/Temp |
.../AppData/Local/Microsoft/Windows/Temporary Internet Files | .../Local Settings/Temporary Internet Files |
.../AppData/Roaming/Microsoft/Windows/Cookies | .../Cookies |
.../AppData/Roaming/Microsoft/Windows/Network Shortcuts | .../Nethood |
.../AppData/Roaming/Microsoft/Windows/Printer Shortcuts | .../PrintHood |
.../AppData/Roaming/Microsoft/Windows/Recent | .../Recent |
.../AppData/Roaming/Microsoft/Windows/Send To | .../SendTo |
.../AppData/Roaming/Microsoft/Windows/Start Menu | .../Start Menu |
.../AppData/Roaming/Microsoft/Windows/Templates | .../Templates |
.../Contacts | Not applicable |
.../Desktop | .../Desktop |
.../Documents | .../My Documents |
.../Downloads | Not applicable |
.../Favorites | .../Favorites |
.../Music | .../My Music |
.../Videos | .../My Videos |
.../Pictures | .../My Pictures |
.../Searches | Not applicable |
.../Links | Not applicable |
.../Saved Games | Not applicable |