Nous avons été récemment infectés par le virus thumbs.db2 qui a créé des raccourcis vers tous nos documents Word et Excel sur nos lecteurs réseau et cache les vrais fichiers. J'ai été capable d'écrire du code pour parcourir tout le dossier et trouver les raccourcis et supprimer, mais je dois être capable d'afficher les fichiers cachés que j'ai été incapable d'atteindre.Supprimer les liens et afficher les fichiers cachés C#
Mon code est ci-dessous, écrit rapidement si s'il vous plaît être gentil :)
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();
}
Comment puis-je Démasquer les fichiers C#
Toute aide serait grandement appriciated.
Cordialement Sp
« que je suis incapable d'atteindre. » - Quel est le problème exactement? –
Alors, quelle est votre vraie question? Comment [afficher les fichiers] (http://msdn.microsoft.com/en-us/library/system.io.file.setattributes.aspx)? – Gene
Désolé, je cherche à afficher le fichier dans C#. – Steven