我們最近感染了thumbs.db2病毒,該病毒創建了我們網絡驅動器上所有Word和Excel文檔的快捷方式,並隱藏了真實文件。我已經能夠編寫代碼遍歷所有文件夾並找到快捷方式並刪除,但我需要能夠取消隱藏我無法實現的隱藏文件。刪除鏈接和取消隱藏隱藏文件c#
我的代碼如下,寫的很快,所以請善待:)
public static IEnumerable<string> GetFiles(string root, string searchPattern)
{
Stack<string> pending = new Stack<string>();
pending.Push(root);
while (pending.Count != 0)
{
var path = pending.Pop();
string[] next = null;
try
{
next = Directory.GetFiles(path, searchPattern);
}
catch { }
if (next != null && next.Length != 0)
foreach (var file in next) yield return file;
try
{
next = Directory.GetDirectories(path);
foreach (var subdir in next) pending.Push(subdir);
}
catch { }
}
}
static void Main()
{
string lines = "";
string startFolder = @"S:\";
// Take a snapshot of the file system.
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(startFolder);
dir.GetDirectories("*.*");
// This method assumes that the application has discovery permissions
// for all folders under the specified path.
IEnumerable<String> fileList = GetFiles(startFolder,"*.lnk");
int I = 0;
List<LinkFileLocation> Lik = new List<LinkFileLocation>();
DtataDataContext D = new DtataDataContext();
//Execute the query. This might write out a lot of files!
foreach (string fi in fileList)
{
LinkFileLocation L = new LinkFileLocation();
// Console.WriteLine(fi.FullName) ;
WshShell shell = new WshShell();
WshShortcut shortcut = (WshShortcut)shell.CreateShortcut(fi);
FileInfo F = new FileInfo(fi);
var fs = F.GetAccessControl();
var sid = fs.GetOwner(typeof(SecurityIdentifier));
Console.WriteLine(sid); // SID
try
{
var ntAccount = sid.Translate(typeof(NTAccount));
Console.WriteLine(ntAccount); // DOMAIN\username
L.UserCreated = ntAccount.Value.ToString();
}
catch {
L.UserCreated = "Not Known";
}
L.CreationTime = F.CreationTime;
if (shortcut.Arguments.Contains("thumbs.db2 start") && shortcut.TargetPath.Contains("cmd.exe"))
{
L.Arguments = shortcut.Arguments;
L.Description = shortcut.Description;
L.FullName = shortcut.FullName;
L.HotKey = shortcut.Hotkey;
L.IconLocation = shortcut.IconLocation;
Console.Write("Infected Shortcut --" + I.ToString() + "-- :-" + shortcut.FullName.ToString() + Environment.NewLine);
lines += "Infected Shortcut :-" + shortcut.FullName.ToString() + Environment.NewLine;
I++;
}
D.LinkFileLocations.InsertOnSubmit(L);
D.SubmitChanges();
}
// Compose a string that consists of three lines.
// Write the string to a file.
System.IO.StreamWriter file = new System.IO.StreamWriter("c:\\test.txt");
file.WriteLine(lines);
file.Flush();
file.Close();
Console.WriteLine("Press any key to exit");
Console.ReadKey();
}
如何在C#中
任何幫助將大大appriciated取消隱藏文件。
最親切的問候 SP
「這是我一直無法實現。」 - 究竟是什麼問題? – 2012-08-16 08:31:22
那麼你真正的問題是什麼?如何[取消隱藏文件](http://msdn.microsoft.com/en-us/library/system.io.file.setattributes.aspx)? – Gene 2012-08-16 08:32:11
對不起,我正在尋找在c#中取消隱藏文件。 – Steven 2012-08-16 08:49:42