Deleting All Selected Checked files

G

Guest

Thank you in advance for any and all assistance. I have an application that
pulls files, folders and registry keys of installed programs. I'm wanting to
with a context menu selection of "Delete Selected", delete "ALL" of the
checked selected files, folders, registry keys. Can someone show me some code
to do this please?
 
Z

zacks

eSolTec said:
Thank you in advance for any and all assistance. I have an application that
pulls files, folders and registry keys of installed programs. I'm wanting to
with a context menu selection of "Delete Selected", delete "ALL" of the
checked selected files, folders, registry keys. Can someone show me some code
to do this please?

I don't have the time to enter a bunch of code, but basically you can
use the File.Delete method to delete files, Directory.Delete method to
delete folders, and the RegistryKey.DeleteValue,
RegistryKey.DeleteSubKey or RegistryKey.DeleteSubKeyTree (depending on
your needs) to delete registry entries.

Help has samples for all.
 
G

Guest

Zack,

thank you for your reply, but I'm using a treeview with an array in it and
the RegistryKey.Delete from MyComputer didn't work. So I would appreciate
someone either taking the time to show me some code for deleting files,
folders and registry keys. Thank you again for any and all assistance.
 
G

Guest

Zacks,

I have a Treeview (array list) of items that are registry keys, file names,
folder names that I wish to programmatically delete from their locations. Any
help for code would be greatly appreicated. Most are Registry Keys that I
wish to programmatically delete. I have looked at System.IO and also the
RegistryKey.Delete in the MyComputer Class and nothing so far has worked.
 
P

Patrice

Try something like :
My.Computer.Registry.CurrentUser.DeleteSubKeyTree("Software\MyCompany")

My.Computer.FileSystem.DeleteDirectory("c:\MyDirectory",
FileIO.DeleteDirectoryOption.DeleteAllContents)

Generally it's always better that YOU show us what you do. For example my
first thought would be that you try to delete something you are not allowed
to delete (in which case our code wouldn't work better, also we could
provide VB2005 code when you are using VB 2003).

Also please always include an accurate description of the result you have
instead of just saying it didn't work...
 
G

Guest

Patrice,

Thank you for your tips. I greatly appreciate it.

VB 2005
Treeview: tv_Results
Code:
If MessageBox.Show("Delete all selected registry keys?",
"Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question,
MessageBoxDefaultButton.Button2) = Windows.Forms.DialogResult.Yes Then
Dim FileList As ArrayList
My.Computer.Registry.CurrentUser.DeleteSubKey(FileList.ToString)

End If

Most of the keys are from programs that would be considered rogue or stuborn
to find an uninstaller or to uninstall from a computer. I'm building a tech
tool for my non-profit organization. Using messagebox to confirm the delete
first as you can see.
 
P

Patrice

Just print out what is returned by FileList.ToString. You'll see this is not
what you expect (it prints out the class name).

(plus FileList is empty and I'm not sure what a FileList have to do with
registry key names but this is not the problem for now).

As you see we would never have spotted this without seeing YOUR code...

Hope it helps.
 
Z

zacks

eSolTec said:
Patrice,

Thank you for your tips. I greatly appreciate it.

VB 2005
Treeview: tv_Results
Code:
If MessageBox.Show("Delete all selected registry keys?",
"Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question,
MessageBoxDefaultButton.Button2) = Windows.Forms.DialogResult.Yes Then
Dim FileList As ArrayList
My.Computer.Registry.CurrentUser.DeleteSubKey(FileList.ToString)

End If

FileList is an arraylist. DeleteSubKey takes a single sub key name in a
string. If the FileList array contains a list of string values that
represent the names of sub keys to delete, something this should work:

Dim sFile as String

For Each sFile in FileList
My.Computer.Registry.CurrentUser.DeleteSubKey(sFile)
Next
 

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

Top