0
votes

I'm using this kind of code to remove file after system reboot.

[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern bool MoveFileEx(string lpExistingFileName,string pNewFileName, MoveFileFlags dwFlags);

Everything is ok with native iis-imitator in VS. But when I'm using IIS this piece of code fails without any error message.

I can suggest that this is a problem with permissions on IIS. But it's only my dumb suggestion.

Can you please help me with this case?

1

1 Answers

1
votes
  • Check the return value of your call to MoveFileEx(). If it is false then the call failed.
  • Call Marshal.GetLastWin32Error to find out the Win32 error code. This sometimes helps narrow the problem down (although not always).
  • If that sheds no more light then you'll need to tell us the full path names for the file you are moving, and for its new destination.

In your comments you state that you are passing the MOVEFILE_DELAY_UNTIL_REBOOT flag. The documentation for MoveFileEx states:

This value can be used only if the process is in the context of a user who belongs to the administrators group or the LocalSystem account.

It seems likely that this is the root cause of the problem. Thanks to @Logan for pointing this out.