编辑:如果有人想测试,这里是文件: Cleaner
出于性能原因,我正在制作一个在启动时自动清理一些文件的程序。
如何使应用程序在另一台只有发布文件的计算机上运行?
我使用 Framework 2.0 制作了应用程序,并且在我的计算机上正常工作且没有错误,但是如果我将发布文件复制到另一台计算机,则在启动时会发生“应用程序停止响应”。
没有来自 Icon 的资源文件,并且是嵌入式资源。我不知道该怎么做。
private void Cleansystem()
{
timer1.Enabled = true;
timer1.Start();
progressBar1.Maximum = 10;
String Offline = Environment.ExpandEnvironmentVariables("%SYSTEMROOT%") + "\\Offline Web Pages";
String download = Environment.ExpandEnvironmentVariables("%SYSTEMROOT%") + "\\Downloaded Program Files";
String software = Environment.ExpandEnvironmentVariables("%SYSTEMROOT%") + "\\SoftwareDistribution\\Download";
String wintemp = Environment.ExpandEnvironmentVariables("%SYSTEMROOT%") + "\\Temp";
String recent = Environment.ExpandEnvironmentVariables("%appdata%") + "\\Microsoft\\Windows\\Recent";
String cookies = Environment.ExpandEnvironmentVariables("%appdata%") + "\\Microsoft\\Windows\\cookies";
String TempInternet = Environment.ExpandEnvironmentVariables("%userprofile%") + "\\Local Settings\\Temporary Internet Files";
String apptemp = Environment.ExpandEnvironmentVariables("%userprofile%") + "\\appdata\\Local\\Temp";
String settingtemp = Environment.ExpandEnvironmentVariables("%userprofile%") + "\\Local Settings\\Temp";
EmptyFolderContents(Offline);
EmptyFolderContents(download);
EmptyFolderContents(software);
EmptyFolderContents(wintemp);
EmptyFolderContents(recent);
EmptyFolderContents(cookies);
EmptyFolderContents(TempInternet);
EmptyFolderContents(apptemp);
EmptyFolderContents(settingtemp);
timer1.Interval = 1000;
timer1.Tick += new EventHandler(timer1_Tick);
}
private void EmptyFolderContents(string folderName)
{
foreach (var folder in Directory.GetDirectories(folderName))
{
try
{
Directory.Delete(folder, true);
}
catch (Exception excep)
{
logger.Fatal(excep);
}
}
foreach (var file in Directory.GetFiles(folderName))
{
try
{
File.Delete(file);
}
catch (Exception excep)
{
logger.Fatal(excep);
}
}
}
void timer1_Tick(object sender, EventArgs e)
{
if (progressBar1.Value != 10)
{
progressBar1.Value++;
}
else
{
Environment.Exit(0);
}
}
}
}
2013-05-08 18:02:58.7013 致命 System.IO.IOException:进程无法访问文件“C:\Windows\Temp\Cleaner.vsho_130508_173905_05efe1ff-6b41-4cb6-bb00-7acad6960c36.iTrace”,因为它正在被使用通过另一个过程。在 System.IO.__Error.WinIOError(Int32 错误代码,字符串可能全路径)
在 System.IO.File.InternalDelete(String path, Boolean checkHost) at System.IO.File.Delete(String path) at GifImagee.MainWindow.EmptyFolderContents(String folderName) in c:\Users\Administrator\Documents\Visual Studio 2012 \Projects\tet\Cleaner\Cleaner\MainWindow.xaml.cs:line 923 2013-05-08 18:02:58.7349 FATAL System.IO.IOException:进程无法访问文件'C:\Windows\Temp\OSO。 vshost.exe_130508_174608_0d66d9df-040c-457b-84b5-7c3576196718.iTrace',因为它正被另一个进程使用。在 System.IO.__Error.WinIOError(Int32 错误代码,字符串可能全路径)
在 System.IO.File.InternalDelete(String path, Boolean checkHost) at System.IO.File.Delete(String path) at GifImagee.MainWindow.EmptyFolderContents(String folderName) in c:\Users\Administrator\Documents\Visual Studio 2012 \Projects\tet\Cleaner\Cleaner\MainWindow.xaml.cs:line 923 2013-05-08 18:02:58.8630 FATAL System.UnauthorizedAccessException:访问路径“Aug2005_d3dx9_27_x64.cab”被拒绝。在 System.IO.Directory.Delete(String fullPath, String userPath, Boolean recursive, Boolean checkHost) at System.IO.Directory.Delete (String fullPath, String userPath, Boolean recursive, Boolean throwOnTopLevelDirectoryNotFound) at System.IO.Directory.Delete (字符串路径,布尔递归)在 C 中的 GifImagee.MainWindow.EmptyFolderContents(String folderName):\Users\Administrator\Documents\Visual Studio 2012\Projects\tet\Cleaner\Cleaner\MainWindow.xaml.cs:line 912 2013-05-08 18:02:58.8743 FATAL System.IO.IOException: The process cannot access the file 'C:\Users\Administrator\appdata\Local\Temp\etilqs_2Isw34P5eLyyP6D' 因为它正被另一个进程使用。在 System.IO.__Error.WinIOError(Int32 错误代码,字符串可能全路径)
在 System.IO.File.InternalDelete(String path, Boolean checkHost) at System.IO.File.Delete(String path) at GifImagee.MainWindow.EmptyFolderContents(String folderName) in c:\Users\Administrator\Documents\Visual Studio 2012 \Projects\tet\Cleaner\Cleaner\MainWindow.xaml.cs:line 923 2013-05-08 18:02:58.9074 FATAL System.IO.IOException: The process cannot access the file 'C:\Users\Administrator\appdata\ Local\Temp\etilqs_7CSWlOdfR5GbUuD' 因为它正被另一个进程使用。在 System.IO.__Error.WinIOError(Int32 错误代码,字符串可能全路径)
在 System.IO.File.InternalDelete(String path, Boolean checkHost) at System.IO.File.Delete(String path) at GifImagee.MainWindow.EmptyFolderContents(String folderName) in c:\Users\Administrator\Documents\Visual Studio 2012 \Projects\tet\Cleaner\Cleaner\MainWindow.xaml.cs:line 923 2013-05-08 18:02:58.9279 FATAL System.IO.IOException: The process cannot access the file 'C:\Users\Administrator\appdata\ Local\Temp\etilqs_9htGcbvUEEpPsK3' 因为它正被另一个进程使用。在 System.IO.__Error.WinIOError(Int32 错误代码,字符串可能全路径)
在 System.IO.File.InternalDelete(String path, Boolean checkHost) at System.IO.File.Delete(String path) at GifImagee.MainWindow.EmptyFolderContents(String folderName) in c:\Users\Administrator\Documents\Visual Studio 2012 \Projects\tet\Cleaner\Cleaner\MainWindow.xaml.cs:line 923 2013-05-08 18:02:58.9389 FATAL System.IO.IOException: The process cannot access the file 'C:\Users\Administrator\appdata\ Local\Temp\etilqs_fPoiWPUjDlCkgey' 因为它正被另一个进程使用。在 System.IO.__Error.WinIOError(Int32 错误代码,字符串可能全路径)
在 System.IO.File.InternalDelete(String path, Boolean checkHost) at System.IO.File.Delete(String path) at GifImagee.MainWindow.EmptyFolderContents(String folderName) in c:\Users\Administrator\Documents\Visual Studio 2012 \Projects\tet\Cleaner\Cleaner\MainWindow.xaml.cs:line 923 2013-05-08 18:02:58.9703 FATAL System.IO.IOException: The process cannot access the file 'C:\Users\Administrator\appdata\ Local\Temp\etilqs_JtJ95QHTNu6Vj7D' 因为它正被另一个进程使用。在 System.IO.__Error.WinIOError(Int32 错误代码,字符串可能全路径)
在 System.IO.File.InternalDelete(String path, Boolean checkHost) at System.IO.File.Delete(String path) at GifImagee.MainWindow.EmptyFolderContents(String folderName) in c:\Users\Administrator\Documents\Visual Studio 2012 \Projects\tet\Cleaner\Cleaner\MainWindow.xaml.cs:line 923 2013-05-08 18:02:59.0947 FATAL System.UnauthorizedAccessException:访问路径“Aug2005_d3dx9_27_x64.cab”被拒绝。在 System.IO.Directory.Delete(String fullPath, String userPath, Boolean recursive, Boolean checkHost) at System.IO.Directory.Delete (String fullPath, String userPath, Boolean recursive, Boolean throwOnTopLevelDirectoryNotFound) at System.IO.Directory.Delete (字符串路径,布尔递归)在 C 中的 GifImagee.MainWindow.EmptyFolderContents(String folderName):\Users\Administrator\Documents\Visual Studio 2012\Projects\tet\Cleaner\Cleaner\MainWindow.xaml.cs:line 912 2013-05-08 18:02:59.1152 FATAL System.IO.IOException: The process cannot access the file 'C:\Users\Administrator\Local Settings\Temp\etilqs_2Isw34P5eLyyP6D' 因为它正被另一个进程使用。在 System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) 在 System.IO.File.InternalDelete(String path, Boolean checkHost) 在 System.IO.File.Delete(String path) 在 GifImagee.MainWindow.EmptyFolderContents(String folderName) 在 c:\Users\Administrator\Documents\Visual Studio 2012\Projects\tet\Cleaner\Cleaner\MainWindow.xaml.cs:line 923 2013-05-08 18:02:59.1263 FATAL System.IO.IOException: The进程无法访问文件'C: \Users\Administrator\Local Settings\Temp\etilqs_7CSWlOdfR5GbUuD' 因为它正被另一个进程使用。在 System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) 在 System.IO.File.InternalDelete(String path, Boolean checkHost) 在 System.IO.File.Delete(String path) 在 GifImagee.MainWindow.EmptyFolderContents(String folderName) 在 c:\Users\Administrator\Documents\Visual Studio 2012\Projects\tet\Cleaner\Cleaner\MainWindow.xaml.cs:line 923 2013-05-08 18:02:59.1563 FATAL System.IO.IOException: The进程无法访问文件“C:\Users\Administrator\Local Settings\Temp\etilqs_9htGcbvUEEpPsK3”,因为它正被另一个进程使用。在 System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) 在 System.IO.File.InternalDelete(String path, Boolean checkHost) at System.IO.File.Delete(String path) at GifImagee.MainWindow.EmptyFolderContents(String folderName) in c:\Users\Administrator\Documents\Visual Studio 2012\Projects\tet\Cleaner\Cleaner\MainWindow.xaml .cs:line 923 2013-05-08 18:02:59.1774 FATAL System.IO.IOException: 进程无法访问文件'C:\Users\Administrator\Local Settings\Temp\etilqs_fPoiWPUjDlCkgey',因为它正在被另一个人使用过程。在 System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) 在 System.IO.File.InternalDelete(String path, Boolean checkHost) 在 System.IO.File.Delete(String path) 在 GifImagee.MainWindow.EmptyFolderContents(String文件夹名称)在 c:\Users\Administrator\Documents\Visual Studio 2012\Projects\tet\Cleaner\Cleaner\MainWindow.xaml.cs:line 923 2013-05-08 18:02:59。1886 FATAL System.IO.IOException:进程无法访问文件“C:\Users\Administrator\Local Settings\Temp\etilqs_JtJ95QHTNu6Vj7D”,因为它正被另一个进程使用。在 System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) 在 System.IO.File.InternalDelete(String path, Boolean checkHost) 在 System.IO.File.Delete(String path) 在 GifImagee.MainWindow.EmptyFolderContents(String文件夹名称)在 c:\Users\Administrator\Documents\Visual Studio 2012\Projects\tet\Cleaner\Cleaner\MainWindow.xaml.cs:line 923