Need help getting Registry.GetValue to work correctly

I have a simple setup project that is no longer working and it seems like a windows update is the cause.  I am using Visual Studio 2010 on Windows 7.  The project is 64bit.  It still works on some computers but it does not work on any computers that have had updates recently.

Here is the original code:

Dim appPath As String = Registry.GetValue("HKEY_CURRENT_USER\SOFTWARE\Our Company Inc.\SoftwareName.exe", "Path", "Not Found")

        appPath &= "Colorbar.col"

        Dim sid : sid = "S-1-1-0"
        Dim objWMI : objWMI = GetObject("winmgmts://./root\cimv2")
        Dim objSID : objSID = objWMI.Get("Win32_SID='" & sid & "'")

        Dim userAccount As String = objSID.AccountName
        Dim fileInfo As IO.FileInfo = New IO.FileInfo(appPath)
        Dim fileAcl As New FileSecurity

        fileAcl.AddAccessRule(New FileSystemAccessRule(userAccount, FileSystemRights.FullControl, AccessControlType.Allow))

        fileInfo.SetAccessControl(fileAcl)

I have put the key value pair of "Path" and "[TARGETDIR]" in the registry editor and have the output from this installer class (the code above) in the Install and Commit custom actions.

This code that used to work now returns "Exception has been thrown by the target of an invocation -> C:\Windows\SYSWOW64\Colorbar.col"

I have checked the registry when this message appears and the path is correct so I don't know where SYSWOW64 is coming from.

I have tried to change getting the appPath using this code:

Dim regKey As RegistryKey = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry64)
        regKey = regKey.OpenSubKey("SOFTWARE\Our Company Inc.\SoftwareName.exe")
        Dim appPath As String = regKey.GetValue("Path").ToString

This returns an "Object reference not set to an instance of an object" error.

I have made a test Windows Form application and put both versions of code in a button event.  Everything works as expected.  Any ideas why the code does not work in a setup project anymore?

Thanks in advance.
B178Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ess KayEntrapenuerCommented:
the quck but bad fix would be to do replace

bla.getvalue(bla).replace("syswow64/","")
0
Ess KayEntrapenuerCommented:
upon reading your question again,  looks like this is the line not working,  correct?

regKey.GetValue("Path").ToString

try path with lowercase

they may have changed the name there
0
B178Author Commented:
That is correct.  GetValue either returns the wrong location or it returns nothing.  I have tried your suggestion and unfortunately it did not resolve the issue.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Ess KayEntrapenuerCommented:
can you post a screenshot of regex  
HKEY_CURRENT_USER\SOFTWARE\Our Company Inc.\SoftwareName.exe
0
B178Author Commented:
regScreenShot.PNG
0
Ess KayEntrapenuerCommented:
can you manually remove path,  and add it back as a DWORD
0
Ess KayEntrapenuerCommented:
also please try this in the code,  what does the message box say
Dim regaddress = "SOFTWARE\Our Company Inc.\SoftwareName.exe"
Dim readValue = My.Computer.Registry.GetValue(regaddress
    , "Path", Nothing)
MsgBox ("The value of " & regaddress & "  is " & vbcrlf & readValue)
0
B178Author Commented:
Using the code:
        Dim regaddress = "HKEY_CURRENT_USER\SOFTWARE\Stress Photonics Inc.\DeltaVision.exe"
        Dim readValue = My.Computer.Registry.GetValue(regaddress, "Path", Nothing)
        MsgBox("The value of " & regaddress & "  is " & vbCrLf & readValue)

The message box returns this when I run the installer

regError.PNG

However, the same code returns this when I put it behind a button click event of a windows form

regBtnClick.PNG
I assume that this windows update is the culprit as I am trying to read from the registry with a custom action script:

https://technet.microsoft.com/en-us/library/security/ms15-074.aspx

I plan to use the file system editor to place the file I need in a known folder location rather than keep it in the application folder for now.
0
B178Author Commented:
Finally have it working again.  I got around using the registry by using CustomActionData and setting it to:

/name="[TARGETDIR]\"

I was then able to access it in my installer class by using this line of code:

Dim appPath As String = Context.Parameters.Item("name")

 Once the path was set, everything else worked as expected.  

Thanks for your help.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
B178Author Commented:
Using CustomActionData resolved the issue.  It seems windows update ms15-074 prevents reading from the registry during the installation process if using a custom action script.  Since it is no longer necessary to read from the registry, I have accepted my own comment regarding CustomActionData as the solution.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.