public async Task FileCleanup() { Processing++; Log(log.Info, "Starting remote file cleanup"); //int filenumber, directorynumber, errornumber; //filenumber = directorynumber = errornumber = 0; string f = @"resources\FileDeleteList.txt"; // 1 // Declare new List. List <string> lines = new List <string>(); // 2 // Use using StreamReader for disposing. using (StreamReader r = new StreamReader(f, System.Text.Encoding.ASCII)) { // 3 // Use while != null pattern for loop string line; while ((line = r.ReadLine()) != null) { // 4 // Insert logic here. // ... // "line" is a line in the file. Add it to our List. if (line.Contains("USERNAME")) { line = line.Replace("USERNAME", CurrentUser); } lines.Add(string.Format("cmd /C RMDIR /S /Q {0}", line)); } } // 5 // Use lines to delete remote dirs. foreach (string s in lines) { Log(log.Info, "Deleting remote folder: " + s.Replace("cmd /C RMDIR /S /Q ", string.Empty)); var paexec = new Tool.PAExec(IPAddress, s); await paexec.Run(); } var x = new Tool.Files(); x.Copy(@"\\fs1\HelpDesk\SHORTCUTS\Clear_IE_Cache.lnk", string.Format(@"\\{0}\c$\Users\{1}\Desktop\", IPAddress, CurrentUser)); Log(log.Info, "Copied Clear_IE_Cache.lnk to Remote Desktop for clearing cache in IE. "); Processing--; Log(log.Info, "File cleanup complete"); }
public async Task ProfileWipe_Enable() { Processing++; var UserProfileServiceFix = new Tool.PAExec(IPAddress, @"-accepteula -realtime -s icacls c:\Users\Default\* /inheritance:e /T /C"); await UserProfileServiceFix.Run(); var file = new Tool.Files(); file.EventLogged += PassEventLogged; await Task.Run(() => file.Copy(@"\\fs1\HelpDesk\TOOLS\3rdParty\Delprof2 1.5.4", string.Format(@"\\{0}\c$\temp\Delprof2_1.5.4\", IPAddress))); file.EventLogged -= PassEventLogged; var add1 = new Tool.StandardProcess(@"c:\windows\system32\", "schtasks.exe", string.Format(@"/create /s \\{0} /sc onstart /delay 0000:10 /rl HIGHEST /ru SYSTEM /tn ""Profile wipe"" /tr ""c:\temp\Delprof2_1.5.4\delprof2.exe /u /id:{1}""", IPAddress.ToString(), CurrentUser)); var add2 = new Tool.StandardProcess(@"c:\windows\system32\", "schtasks.exe", @"/create /s \\" + IPAddress.ToString() + @" /sc onlogon /ru SYSTEM /tn ""remove wipe"" /tr ""c:\temp\Delprof2_1.5.4\remove.bat"""); await add1.Run(); await add2.Run(); Processing--; Log(log.Info, "Profile Wipe ENABELED on next boot."); }