本文介绍了标记锁定文件以在重新启动时删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在重新启动后标记锁定的文件以便删除
i已经用Google搜索并找到以下代码,但它无法正常工作
i need to mark locked files for delete after reboot
i have googled and found following code, but its not working
internal enum MoveFileFlags
{
MOVEFILE_REPLACE_EXISTING = 1,
MOVEFILE_COPY_ALLOWED = 2,
MOVEFILE_DELAY_UNTIL_REBOOT = 0x00000004,
MOVEFILE_WRITE_THROUGH = 8
}
[System.Runtime.InteropServices.DllImportAttribute("kernel32.dll", EntryPoint = "MoveFileEx")]
internal static extern bool MoveFileEx(string lpExistingFileName, string lpNewFileName,
MoveFileFlags dwFlags);
然后调用该函数
and then calling the function as
if (MoveFileEx(FileName, null, MoveFileFlags.MOVEFILE_DELAY_UNTIL_REBOOT))
MessageBox.Show("marked");
else
MessageBox.Show("not marked");
但每个函数都返回
but every function returns
false
和
未标记的消息框显示
调用函数是不对的,或者这段代码对Windows 7不起作用?
and
not marked messagebox is shown
is something wrong in calling the function or this code doesnt work for windows 7?
推荐答案
This value (MOVEFILE_DELAY_UNTIL_REBOOT) can be used only if the process is in the context of a user who belongs to the administrators group or the LocalSystem account.
您是否以管理员身份运行应用程序?
Are you running your application as an administrator?
这篇关于标记锁定文件以在重新启动时删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!