I converted my VB6 code to VB.net and due to environment dependencies i have to stick to dotnet 2.0.
Now after converting there is only one piece of code that is failing which i am not able to fix.
Here is the code that fails and gives System.Io.exception: Bad File name or number:
Dim objShell As Object
Dim strPath As String
Dim strDirectory As String
strPathInstall = "HKEY_LOCAL_MACHINE\SOFTWARE\ABC\InstallInfo\"
strDrive = "INSTALLDRIVE"
objShell = CreateObject("Wscript.Shell")
strDirectory = objShell.ReadRegistry(strPathInstall & strDrive)
The objShell.ReadRegistry statement
creates the System.Io.Exception-Bad File name or number, in case the registry entry is not present on the host machine And that crashes my application. If registry is present then it successfully retrieves the value, else throws exception.
I want to handle this exception, i want it to continue to the next statement if it fails to find the registry item in the hostmachine or simply set strDirectory = ""
I cant give try catch to this statement because there are plenty of this readregistry statements in the code and its not good to give try catch to each and every readregistry statement.
is there any way i can fix this problem? Please suggest.
What I have tried:
I tried the dotnet approach, but in certain other scenarios the dotnet approach cant be implemented due to the existing logic.