2011-06-10 63 views
2

我想使用PowerShell删除临时互联网文件(TIF)文件夹中的扩展名“.htm”的文件。但不能太远。Powershell脚本删除临时互联网文件

下面是我的脚本。我注意到TIF文件夹中的缓存名称与显示全名不同。 (我试着写一个C#程序要做到这一点,但也不管用)

get-childitem "c:\Documents and Settings\sanjeev-nithyanandam\Local Settings\Temporary Internet Files\*" -include *.htm -recurse -force | foreach ($_) {remove-item $_.fullname -force} 

我这个职位"Temporary Internet Files" folder on Windows是TIF文件夹中的表现比其他文件夹不同的教训。

是否有解决方法来修改PS脚本并删除文件?

任何帮助表示赞赏。

谢谢! Sanjeev

+0

添加更多的信息:我想删除的类型是HTML文档的文件,并有命名为“URL本身的一部分”和缓存名称与热媒结束 – Sanjeev 2011-06-10 19:32:39

+0

会'删除项C:\文件和Settings \ sanjeev-nithyanandam \ Local Settings \ Temporary Internet Files \ * -recurse“'for you? – ProfessionalAmateur 2011-06-10 19:35:11

+0

无法删除,目录不为空(为位置添加了双引号)并且还尝试了-force开关 – Sanjeev 2011-06-10 20:00:42

回答

2

我不会用全名都懒得:

get-childitem "c:\Documents and Settings\sanjeev-nithyanandam\Local Settings\Temporary Internet Files*" -include *.htm -recurse -force | remove-item -force -recurse 
+0

没有为特定的文件夹工作我想删除的文件的类型是HTML Document,名称为“url自身的一部分”,缓存名以.htm结尾 – Sanjeev 2011-06-10 19:32:12

+0

什么操作系统?char [15] – EBGreen 2011-06-10 19:34:34

+0

Win XP professional – Sanjeev 2011-06-10 19:53:52

0
$a = Get-ChildItem C:\Scripts 
foreach($x in $a) 
{   
    $x.Delete() 
}   
-1

你可能最好让Windows为你做它。这个命令应该诀窍:

RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 8 

摘自how-to-geek

0

“ClearMyTracksByProcess”

是很好的,如果它做了什么,它包装盒上说,但如果你采取偷看在超级隐藏文件夹MS拥有所有的地方和Index.dat文件,然后你就会知道它不是做所有的名字sugests。

下面显示的是删除大多数间谍软件文件(包括FireFox和Flash Cookie /共享对象)的代码,并且记得在尝试之前终止进程“IExplore”,并且还需要更改目录属性。

如果您想了解更多信息,请点击我的名字。

using System; 
using System.Collections.Generic; 
using System.IO; 
using System.Diagnostics; 
using System.Text; 

namespace Fidling 
{ 
    public static class SpywareRemoval 
    { 
     private static void RemoveSpywareFiles(string RootPath, string Path,bool Recursive) 
     { 
      string FullPath = RootPath + Path + "\\"; 
      if (Directory.Exists(FullPath)) 
      { 
       DirectoryInfo DInfo = new DirectoryInfo(FullPath); 
       FileAttributes Attr = DInfo.Attributes; 
       DInfo.Attributes = FileAttributes.Normal; 
       foreach (string FileName in Directory.GetFiles(FullPath)) 
       { 
        RemoveSpywareFile(FileName); 
       } 
       if (Recursive) 
       { 
        foreach (string DirName in Directory.GetDirectories(FullPath)) 
        { 
         RemoveSpywareFiles("", DirName, true); 
         try { Directory.Delete(DirName); }catch { } 
        } 
       } 
       DInfo.Attributes = Attr; 
      } 
     } 

     private static void RemoveSpywareFile(string FileName) 
     { 
      if (File.Exists(FileName)) 
      { 
       try { File.Delete(FileName); }catch { }//Locked by something and you can forget trying to delete index.dat files this way 
      } 
     } 

     private static void DeleteFireFoxFiles(string FireFoxPath) 
     { 
      RemoveSpywareFile(FireFoxPath + "cookies.sqlite"); 
      RemoveSpywareFile(FireFoxPath + "content-prefs.sqlite"); 
      RemoveSpywareFile(FireFoxPath + "downloads.sqlite"); 
      RemoveSpywareFile(FireFoxPath + "formhistory.sqlite"); 
      RemoveSpywareFile(FireFoxPath + "search.sqlite"); 
      RemoveSpywareFile(FireFoxPath + "signons.sqlite"); 
      RemoveSpywareFile(FireFoxPath + "search.json"); 
      RemoveSpywareFile(FireFoxPath + "permissions.sqlite"); 
     } 

     public static void RunCleanup() 
     { 
      try { KillProcess("iexplore"); } 
      catch { }//Need to stop incase they have locked the files we want to delete 
      try { KillProcess("FireFox"); } 
      catch { }//Need to stop incase they have locked the files we want to delete 
      string RootPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal).ToLower().Replace("documents", ""); 
      RemoveSpywareFiles(RootPath, @"AppData\Roaming\Macromedia\Flash Player\#SharedObjects",false); 
      RemoveSpywareFiles(RootPath, @"AppData\Roaming\Macromedia\Flash Player\macromedia.com\support\flashplayer\sys\#local", false); 
      RemoveSpywareFiles(RootPath, @"AppData\Local\Temporary Internet Files", false);//Not working 
      RemoveSpywareFiles("", Environment.GetFolderPath(Environment.SpecialFolder.Cookies), true); 
      RemoveSpywareFiles("", Environment.GetFolderPath(Environment.SpecialFolder.InternetCache), true); 
      RemoveSpywareFiles("", Environment.GetFolderPath(Environment.SpecialFolder.History), true); 
      RemoveSpywareFiles(RootPath, @"AppData\Local\Microsoft\Windows\Wer", true); 
      RemoveSpywareFiles(RootPath, @"AppData\Local\Microsoft\Windows\Caches", false);   
      RemoveSpywareFiles(RootPath, @"AppData\Local\Microsoft\WebsiteCache", false); 
      RemoveSpywareFiles(RootPath, @"AppData\Local\Temp", false); 
      RemoveSpywareFiles(RootPath, @"AppData\LocalLow\Microsoft\CryptnetUrlCache", false); 
      RemoveSpywareFiles(RootPath, @"AppData\LocalLow\Apple Computer\QuickTime\downloads", false); 
      RemoveSpywareFiles(RootPath, @"AppData\Local\Mozilla\Firefox\Profiles", false); 
      RemoveSpywareFiles(RootPath, @"AppData\Roaming\Microsoft\Office\Recent", false); 
      RemoveSpywareFiles(RootPath, @"AppData\Roaming\Adobe\Flash Player\AssetCache", false); 
      if (Directory.Exists(RootPath + @"\AppData\Roaming\Mozilla\Firefox\Profiles")) 
      { 
       string FireFoxPath = RootPath + @"AppData\Roaming\Mozilla\Firefox\Profiles\"; 
       DeleteFireFoxFiles(FireFoxPath); 
       foreach (string SubPath in Directory.GetDirectories(FireFoxPath)) 
       { 
        DeleteFireFoxFiles(SubPath + "\\"); 
       } 
      } 
     } 

     private static void KillProcess(string ProcessName) 
     {//We ned to kill Internet explorer and Firefox to stop them locking files 
      ProcessName = ProcessName.ToLower(); 
      foreach (Process P in Process.GetProcesses()) 
      { 
       if (P.ProcessName.ToLower().StartsWith(ProcessName)) 
        P.Kill(); 
      } 
     } 
    } 
} 

我花了2天删除Windows 7的index.dat文件,因为MS在不断变化的规则,所以对什么版本Win732工作XXX不会对已更新的服务包和底线是你其他的工作版本需要使用具有管理权限的另一个Windows帐户删除这些文件,启动时的脚本缺省情况下没有管理员权限。

-1
$version = gwmi win32_operatingsystem | select version 
$version = $version.version.substring(0,4) 
$ErrorActionPreference = "Continue" 
$process = Get-Process iexplore -ErrorAction silentlycontinue 

if ($process) { 
    "exists" 
    Stop-Process $process -whatif 

    } 
else { 
    "does not exist" 

} 

if ($version -ge "6.0."){ 
    [STRING]$ds = "C:\Users\" 
}else{ 
    [STRING]$ds = "C:\Documents and Settings\" 
} 

sl $ds 

foreach ($directory in get-childitem $ds -Force | where {$_.PsIsContainer}){ 
$dir = $ds + $directory + "\Local Settings\Temporary Internet Files\Content.IE5" 
get-childitem $dir -Force | where {$_.PsIsContainer} | Remove-Item -include *.htm -Force -Recurse 
} 


$WinTempInet = $env:windir + '\temp\Temporary Internet Files\Content.IE5' 
if ($WinTempInet){ 
    sl $WinTempInet 
    foreach ($WinTempInetDir in get-childitem $WinTempInet -Force | where {$_.PsIsContainer}){ 
    get-childitem $WinTempInetDir -Force | where {$_.PsIsContainer} | Remove-Item 
    -include *.htm -Force -Recurse`