How to Delete Cookies & Temp Files Using Visual Basic 6

Written by jim campbell
  • Share
  • Tweet
  • Share
  • Email

Visual Basic is a Microsoft programming language that allows you to create and delete files on a computer. Cookie files are created by the Web browser when you browse a Web page. Temp files are created when you install a program or open a file. A temp file creates a backup, so your changes are saved periodically in case your computer crashes. Cookie and temp files take up space on a computer, and Visual Basic provides syntax to delete these files.

Skill level:


  1. 1

    Click the Windows "Start" button. Click "All Programs," "Microsoft .NET Framework" and then the "Visual Studio" shortcut. This opens your Visual Studio programming tool.

  2. 2

    Double-click your Visual Basic project name. Visual Studio opens all of your project files and shows them in a panel labelled "Solution Explorer." Right-click the file you want to use to delete the files. Select "View Code" to display the Visual Basic code file.

  3. 3

    Type in the following code to delete cookie files:

    Dim cookie As HttpCookie

    cookie = New HttpCookie("cookie_name")

    cookie.Expires = DateTime.Now.AddDays(-1D)


    Replace "cookie_name" with the name of the cookie file you want to delete. This code sets the expiration date of the cookie in the past, which makes Windows delete the file from the system.

  4. 4

    Type in the following code to delete temp files:

    My.Computer.FileSystem.DeleteFile("C:\Local Settings\Temp*.*")

    The "." syntax deletes all files in the Temp directory. If you only want to delete one file, type the name of the file instead of ".."

  5. 5

    Click the "Save" option to save your code. Click "Run" to view the changes in the Visual Studio debugger.

Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.