BleepingComputer.com: Deleting a file in VB.Net

Jump to content


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.

Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Deleting a file in VB.Net

#1 User is offline   aommaster 

  • I !<3 malware
  • PipPipPipPipPipPip
  • Find Topics
  • Group: Malware Response Team
  • Posts: 5,171
  • Joined: 08-June 08
  • Gender:Male
  • Location:Dubai

Posted 07 July 2009 - 05:16 AM

Hi guys!

I have a program that reads a chm file through this function:
System.Windows.Forms.Help.ShowHelp(Me, tempfolder & "/Help.chm", HelpNavigator.AssociateIndex)


Now, I would like to delete it when the program closes.

So far I have this:
If System.IO.File.Exists(tempfolder & "/preview.html") Then
	SetAttr(tempfolder & "/preview.html", FileAttribute.Normal)
	Kill(tempfolder & "/preview.html")
End If

However, the above fails, because apparently, the Help.ShowHelp class uses a read/write attribute (I cannot have a read only for some reason. If I do, the help window does not open).

Is there any way of deleting this file ones the program terminates?

Thanks guys!

This post has been edited by aommaster: 07 July 2009 - 05:17 AM

My website: http://www.aommaster.com
Posted Image
Please do not send me PM's requesting for help. The forums are there for a reason : )
If I am helping you and do not respond to your thread for 48 hours, please send me a PM

All my help is free. However, if you would like to make a donation, then please click here.



#2 User is offline   Billy O'Neal 

  • Bleepin Engineer
  • PipPipPipPipPipPip
  • Find Topics
  • Group: Malware Response Instructor
  • Posts: 10,080
  • Joined: 17-January 08
  • Gender:Male
  • Location:Cleveland, Ohio

Posted 07 July 2009 - 08:29 AM

Hello :thumbsup:

It's probably failing because the program's still open.

Kill(tempfolder & "/preview.html") <-- the HTML file is not what's running -- whatever displays the file is what's running. You'd have to enumerate the program that was actually used to open it from the HKEY_CLASSES_ROOT registry key and kill that process.

Billy3

#3 User is offline   aommaster 

  • I !<3 malware
  • PipPipPipPipPipPip
  • Find Topics
  • Group: Malware Response Team
  • Posts: 5,171
  • Joined: 08-June 08
  • Gender:Male
  • Location:Dubai

Posted 07 July 2009 - 08:57 AM

Hi Billy!

Thanks for your reply. Yes, that was a typo on my part because there are two files that need to be deleted (preview.html being one of them). How would the process go if I'd like to delete the help.chm file?
My website: http://www.aommaster.com
Posted Image
Please do not send me PM's requesting for help. The forums are there for a reason : )
If I am helping you and do not respond to your thread for 48 hours, please send me a PM

All my help is free. However, if you would like to make a donation, then please click here.



#4 User is offline   aommaster 

  • I !<3 malware
  • PipPipPipPipPipPip
  • Find Topics
  • Group: Malware Response Team
  • Posts: 5,171
  • Joined: 08-June 08
  • Gender:Male
  • Location:Dubai

Posted 07 July 2009 - 05:09 PM

Hi Billy!

Perhaps you could also provide me with a more efficient way of doing this. The reason I wanted to delete the file is that the chm file is created in a temporary directory and then opened. However, once the program is closed, I'd like the chm file to be deleted. I could just leave the file there, but I like to clean up after myself.

Would there be a way of perhaps embedding the chm file into the program? However, I can't see how to call the chm file from the my.resources once it has been embedded.

Edit: Solved my problem! :thumbsup: I used a function instead of a sub and manually allocated a process using the system.diagnostics.process.

Thanks Billy!

This post has been edited by aommaster: 08 July 2009 - 05:44 AM

My website: http://www.aommaster.com
Posted Image
Please do not send me PM's requesting for help. The forums are there for a reason : )
If I am helping you and do not respond to your thread for 48 hours, please send me a PM

All my help is free. However, if you would like to make a donation, then please click here.



Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users