Error when reading the registry

Error when reading the registry

GeeHaa
Collaborator Collaborator
676 Views
5 Replies
Message 1 of 6

Error when reading the registry

GeeHaa
Collaborator
Collaborator

Hi.

I have an installer that reads from the registry to find the AutoCAD version and location. It was working until recently. It seems the new computers being given out won't let the installer read from the registry. People have been running it as admin in the past but it doesn't accept this anymore. Has anyone run into this and if so what permissions do I need to ask IT for? They tried giving people admin rights but it doesn't seem to work..

 

Thanks

 ' Get the AutoCAD current version registry key 
Private Function GetAcadCurVerKey() As String
        Dim rkcu As Microsoft.Win32.RegistryKey = 
           Microsoft.Win32.Registry.CurrentUser
        Dim path As String = "Software\Autodesk\AutoCAD\"
        Using rk1 As Microsoft.Win32.RegistryKey = rkcu.OpenSubKey(path)
            path += rk1.GetValue("CurVer")
            Using rk2 As Microsoft.Win32.RegistryKey = rkcu.OpenSubKey(path)
                Return path & "\" & rk2.GetValue("CurVer")
            End Using
        End Using
    End Function
    ' Get the acad.exe location for the AutoCAD current version 
    Private Function GetAcadLocation() As String
        Dim rklm As Microsoft.Win32.RegistryKey = 
              Microsoft.Win32.Registry.LocalMachine
        Dim path As String = GetAcadCurVerKey()
        Using rk As Microsoft.Win32.RegistryKey = rklm.OpenSubKey(path)
            Return DirectCast(rk.GetValue("AcadLocation"), String)
        End Using
    End Function
0 Likes
Accepted solutions (1)
677 Views
5 Replies
Replies (5)
Message 2 of 6

_gile
Consultant
Consultant

Hi,

 

To access LocalMachine (64 bits)  you should do:

RegistryKey rklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 3 of 6

GeeHaa
Collaborator
Collaborator

Thanks for the response Giles. Sorry it took so long to respond but I had to find a new user with the problem.

I changed the line you recommended and it errors out in the same place when it hits this line 

Using rk1 As Microsoft .Win32.RegistryKey = rkcu.OpenSubKey(path)

The error is object reference not set to an instance of object.

Please note it works fine on my machine. But I have full admin rights.

I tried changing everything to 64 bit and it still errors out in the same place.

 

Thanks again.

 

0 Likes
Message 4 of 6

_gile
Consultant
Consultant

When I did such installers, I added an app.manifest file to the executable project (right click on the project in the Solution Explorer > Add > New Item > Application Manifest File) in which I replaced:

<requestedExecutionLevel level="asInvoker" uiAccess="false" />

with:

<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 5 of 6

GeeHaa
Collaborator
Collaborator
<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
    <security>
      <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
         <requestedExecutionLevel  level="requireAdministrator" uiAccess="false" />
       </requestedPrivileges>
    </security>
  </trustInfo>

I inserted the line above. And put both the manifest file and the executable in the same folder. It still crashes when trying to read the registry. The compiler created 5 files including the manifest file. Do I need to include them all? I was informed by IT that new users don't have admin rights.

0 Likes
Message 6 of 6

GeeHaa
Collaborator
Collaborator
Accepted solution

Thanks Giles, I finally have it working. IT gave me a new computer to test it on so I could use trial and error to get it working. I reverted require Administrator back to Asinvoker and Published the app(It wouldn't let me publish with RequireAdministrator). I guess all I needed to do was publish the app. Visual Studio Created an Application that didn't work because it was missing groups of files but since I didn't need the files included I just use the Executable it created. It runs perfectly now without running as administrator.

 

Thanks Again for your help.

 

0 Likes