标记锁定文件以在重新启动时删除 [英] mark locked file for delete at reboot
本文介绍了标记锁定文件以在重新启动时删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在重新启动后标记锁定的文件以便删除
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?
推荐答案
代码是否在管理员下运行帐户??如果没有,你想要做什么将无法正常工作,因为它需要修改HKEY_LOCAL_MACHINE regsitry,普通用户不能这样做!
Is the code running under an administrator account?? If not, what you want to do will not work as it requires modifying the HKEY_LOCAL_MACHINE regsitry, which normal users cannot do!
根据 Microsoft [ ^ ]:
According to Microsoft[^]:
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?
当设置了reboot选项时,API将始终返回false,因为它无法知道在发生后会发生什么重启。
- > http://msdn.microsoft.com/en-us /library/windows/desktop/aa365240(v=vs.85).aspx [ ^ ]
when the reboot option is set the API willl always return false, because it cant know what will happen after the reboot.
-> http://msdn.microsoft.com/en-us/library/windows/desktop/aa365240(v=vs.85).aspx[^]
这篇关于标记锁定文件以在重新启动时删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文