|
-
Nov 10th, 2020, 07:32 PM
#1
Thread Starter
New Member
In Need of Help Checking if object is deleted
Hey guys,
I am wracking my brains over trying to figure out what I assume should be simple. In my example code below that is running in a backgroundworker thread, I am getting selected usernames from a list box and attempting to delete them. If the delete is successful, I would like to print Profile {profile} succcessfully deleted, and if the delete is not successful, I would like to print Profile {profile} is locked. How would I go about doing this, as .Delete() throws an exception if the profile can’t be deleted, and I cannot do backgroundworker.reportprogress from inside an exception?
Code:
Dim resObjColl As ManagementObjectCollection
Dim resObj As ManagementObject
For Each profile In ListBoxProfiles.SelectedItems
resObjColl = WmiConn.ExecWmiQuery($"SELECT * FROM win32_UserProfile WHERE localpath = ""C:\\Users\\{profile}""")
For Each resObj In resObjColl
resObj.Delete()
BackgroundWorker4.ReportProgress(10, $"Profile {profile} successfully deleted.{vbCrLf}")
Next
Next
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|