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