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.

Photo

Deleting a file in VB.Net


  • Please log in to reply
3 replies to this topic

#1 aommaster

aommaster

    I !<3 malware


  • Malware Response Team
  • 5,294 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Dubai
  • Local time:08:27 AM

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!

Edited by aommaster, 07 July 2009 - 05:17 AM.

My website: http://aommaster.com
unite_blue.png
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


BC AdBot (Login to Remove)

 


#2 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:09:27 PM

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
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

#3 aommaster

aommaster

    I !<3 malware

  • Topic Starter

  • Malware Response Team
  • 5,294 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Dubai
  • Local time:08:27 AM

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://aommaster.com
unite_blue.png
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


#4 aommaster

aommaster

    I !<3 malware

  • Topic Starter

  • Malware Response Team
  • 5,294 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Dubai
  • Local time:08:27 AM

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!

Edited by aommaster, 08 July 2009 - 05:44 AM.

My website: http://aommaster.com
unite_blue.png
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





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users