在我的控制台应用程序 (c#) 项目中,我试图让用户在没有外部连接的安全网络上键入一个或多个网络位置的列表。用户将拥有完整的管理员权限。用户提供:Source:“机器名”和Destination:“网络位置”。
它应该在 XP 和 Win7 机器上运行并获取“文档”、“桌面”、“收藏夹”和“应用程序数据”。
它适用于 XP 的“文档”、“桌面”和“收藏夹”,但不适用于隐藏的“应用程序数据”,在 Win7 上它适用于除“文档”之外的所有内容。
我研究过的每个帖子和链接都说这是一个巨大的安全风险,而且无法做到。
有没有可以处理这个的库?如果没有,有人可以确认“无法完成”。?
我尝试过 Directory、DirectoryInfo、FileAttributes 和 WMI。
这是我的简化代码:
if (Str_Drive.Length == 0)
{
str_SrcAndDrive = @"\\" + str_Source.ToString() + @"\c$";
}
else
{
str_SrcAndDrive = @"\\" + str_Source.ToString() + @"\" + Str_Drive + "$";
}
//XP:
string str_basePath = Path.Combine(str_SrcAndDrive, "Documents and Settings");
var dir_base = new DirectoryInfo(str_basePath);
//System.OperatingSystem osInfo = System.Environment.OSVersion;
if (dir_base.Exists) //&& (osInfo.Platform == System.PlatformID.Win32NT)) //XP
{
foreach (var dir in dir_base.GetFileSystemInfos())
{
switch (dir.ToString())
{
case "administrator":
case "Administrator":
case "Default User":
case "All Users":
//Do nothing
break;
default:
string str_dir = dir.ToString();
//Code to show hidden directories
DirectoryInfo di = new DirectoryInfo(Path.Combine(str_basePath, str_dir));
string dirPath = "";
DirectoryInfo[] diArr = di.GetDirectories();
foreach (DirectoryInfo dri in diArr)
{
dirPath = dri.ToString();
FileAttributes attributes = File.GetAttributes(dirPath); //blows up here
if ((attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
{
File.SetAttributes(dirPath, File.GetAttributes(dirPath) & ~FileAttributes.Hidden);
File.SetAttributes(dirPath, attributes);
}
}
//Handle XP App Data
string str_baseAndDirsPath = Path.Combine(dir_base.ToString(), str_dir, "Application Data");
DirectoryInfo dir_baseAndDirs = new DirectoryInfo(str_baseAndDirsPath);
if (dir_baseAndDirs.Exists)
{
string str_Destination = Path.Combine(str_Dest, str_Source, str_dir, "Application Data");
ProcessXcopy(str_baseAndDirsPath, str_Destination);
} //continues, but this gives you the idea...