Mark file for deletion

  • Thread starter Thread starter Lubomir
  • Start date Start date
L

Lubomir

Hi,

How can I mark the file for deletion upon next reboot?

Thanks,

Lubomir
 
How can I mark the file for deletion upon next reboot?

class Program
{
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
public static extern bool MoveFileEx(string
lpExistingFileName, string lpNewFileName, int dwFlags);

public const int MOVEFILE_DELAY_UNTIL_REBOOT = 0x4;

public static void DeleteOnReboot(string filename)
{
if (!MoveFileEx(filename, null,
MOVEFILE_DELAY_UNTIL_REBOOT))
System.Windows.Forms.MessageBox.Show("Failed");
}

static void Main(string[] args)
{
DeleteOnReboot(@"C:\test.txt");
}
}
 
Gary Marshall said:
How can I mark the file for deletion upon next reboot?

class Program
{
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
public static extern bool MoveFileEx(string
lpExistingFileName, string lpNewFileName, int dwFlags);

public const int MOVEFILE_DELAY_UNTIL_REBOOT = 0x4;

public static void DeleteOnReboot(string filename)
{
if (!MoveFileEx(filename, null,
MOVEFILE_DELAY_UNTIL_REBOOT))
System.Windows.Forms.MessageBox.Show("Failed");
}

static void Main(string[] args)
{
DeleteOnReboot(@"C:\test.txt");
}
}



Note that this requires administrative privileges!

Willy.
 
Hi,

Thanks for answers. I was kind of hoping .NET has a method for it.

Thanks,

Lubomir



Willy Denoyette said:
Gary Marshall said:
How can I mark the file for deletion upon next reboot?

class Program
{
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
public static extern bool MoveFileEx(string
lpExistingFileName, string lpNewFileName, int dwFlags);

public const int MOVEFILE_DELAY_UNTIL_REBOOT = 0x4;

public static void DeleteOnReboot(string filename)
{
if (!MoveFileEx(filename, null,
MOVEFILE_DELAY_UNTIL_REBOOT))
System.Windows.Forms.MessageBox.Show("Failed");
}

static void Main(string[] args)
{
DeleteOnReboot(@"C:\test.txt");
}
}



Note that this requires administrative privileges!

Willy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Maximal path and maximal file name length 6
Service name 6
initialize listbox 1
Get object from string 4
Get the file name from a dll. 1
64 bit OS 2
Managed resources 1
Exception handling 7

Back
Top