-
Sep 18th, 2017, 12:46 PM
#1
Thread Starter
New Member
Help with Console Display and Variable DeleteDirectory
I am trying to write a VB script to for other users at my company to remove a Solidworks EPDM file vault that is locked without clearing certain keys from the registry first. So far the system works as intended except for two details.
1: The console window does not show what has been done and if there are any errors. I would like to be able to see that each step has either been performed or skipped due to an error in the console window as it runs. Right now, it just shows the "Press any button...." message and nothing else.
2: The other issue is that I need to remove the folder from the explorer favorites sidebar (C:\Users\{each user}\Links\MTC-PDM). This has to happen after the directory is removed in line 13, but a couple of different codes I have tried have failed to complete this.
The current code is attached:
Code:
Module Module1
Sub Main()
On Error Resume Next
My.Computer.Registry.LocalMachine.DeleteSubKey("SOFTWARE\SolidWorks\Applications\PDMWorks Enterprise\Databases\MTC-PDM")
My.Computer.Registry.LocalMachine.DeleteSubKey("SOFTWARE\Wow6432Node\SolidWorks\Applications\PDMWorks Enterprise\Databases\MTC-PDM")
My.Computer.Registry.CurrentUser.DeleteSubKey("Software\Solidworks\Applications\PDMWorks Enterprise\ConisioAdmin\Servers\Jeffepdmarc1\FileVaults\MTC-PDM")
My.Computer.Registry.CurrentUser.DeleteSubKey("Software\Solidworks\Applications\PDMWorks Enterprise\ConisioAdmin\Servers\Jeffepdmarc1\FileVaults")
My.Computer.Registry.CurrentUser.DeleteSubKey("Software\Solidworks\Applications\PDMWorks Enterprise\ConisioAdmin\Servers\Jeffepdmarc1")
My.Computer.Registry.Users.DeleteSubKey("S-1-5-21-3095125127-1407775085-1823089326-1106\Software\Solidworks\Applications\PDMWorks Enterprise\ServerExe\MTC-PDM")
My.Computer.Registry.Users.DeleteSubKey("S-1-5-21-3095125127-1407775085-1823089326-1106\Software\Solidworks\Applications\PDMWorks Enterprise\Vaults\MTC-PDM")
My.Computer.FileSystem.DeleteDirectory("C:\MTC-PDM", FileIO.UIOption.OnlyErrorDialogs, FileIO.RecycleOption.DeletePermanently)
For Each Folder As String In IO.Directory.GetDirectories("C:\users\")
If Folder.Contains("MTC-PDM") Then
My.Computer.FileSystem.DeleteDirectory(Folder, FileIO.UIOption.OnlyErrorDialogs, FileIO.RecycleOption.DeletePermanently)
End If
Next
Console.Write("Press any Key to Continue")
Console.ReadLine()
End Sub
End Module
-
Sep 18th, 2017, 04:34 PM
#2
Re: Help with Console Display and Variable DeleteDirectory
1) use Console.WriteLine to show progress ... as for errors.... because you're using on error resume next... you'll need to test after each command if there was an error and display it. Personally I'd use the Try...Catch blocks to handle that.
2) you need to change how your're getting the directory listing. As you have it, it only scans the users folder, none of the sub folders. What you may want to do is get the username, then assemble the complete path, check to see if it exists, then if it does, then delete it.
-tg
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
|