Author Topic: I have try to get AutoCAD's registry key on Windows 7, 8 x64. But I can't do it.  (Read 3482 times)

0 Members and 1 Guest are viewing this topic.

Andrey Bushman

  • Swamp Rat
  • Posts: 864
I have try to get AutoCAD's registry key on Windows 7, 8 x64. But I can't do it. Some screens look below...
Pay attention to comments in my code.
Code - C#: [Select]
  1. // Fragment of common AutoCAD registry key, located in HKLM and HKCU.
  2. static readonly String ParrentAcadRegistryKey = IntPtr.Size == 4 ?
  3. @"SOFTWARE\Wow6432Node\Autodesk\AutoCAD" : @"SOFTWARE\Autodesk\AutoCAD";
  4.  
  5. RegistryKey regAcad;// AutoCAD registry key at HKLM
  6.  
  7. try {
  8.     // Check for HKEY_LOCAL_MACHINE\SOFTWARE\Autodesk\AutoCAD
  9.  
  10.     // parrentRegistry is the Registry.LocalMachine
  11.     Boolean software = parrentRegistry.GetSubKeyNames().Contains("SOFTWARE"); // true
  12.     if (software) {
  13.         RegistryKey rk_1 = parrentRegistry.OpenSubKey("SOFTWARE", false);
  14.         Boolean autodesk = rk_1.GetSubKeyNames().Contains("Autodesk"); // true
  15.         if (autodesk) {
  16.             RegistryKey rk_2 = rk_1.OpenSubKey("Autodesk", false);
  17.             Boolean _autocad = rk_2.GetSubKeyNames().Contains("AutoCAD"); // false
  18.  
  19.             Console.WriteLine("_autocad is {0}", _autocad);
  20.         }
  21.     }
  22.  
  23.     // Check for HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Autodesk\AutoCAD
  24.     regAcad = parrentRegistry.OpenSubKey(ParrentAcadRegistryKey, false); // null
  25.  
  26.     Console.WriteLine("regAcad is {0}", regAcad == null ? "null" : "not null");
  27. }
  28.  

I have got result:
Quote from: Console
_autocad is False
regAcad is null
Why I can't get necessary registry key for Windows 7, 8 x64? Where is my mistake?
« Last Edit: November 25, 2012, 02:02:37 AM by Andrey »

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
I do not think that 64bit applications will have registry keys in HKLM\SOFTWARE\Wow6432Node\

If the AutoCAD 2013 version installed is 64bit, then you will not find it there. 32bit applications have keys stored there but do not have them stored in HKLM\SOFTWARE\
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Andrey Bushman

  • Swamp Rat
  • Posts: 864
@Keith™
I know, but I try both variants, because I can't find necessary registry key. Both variants not help me find it.

I tried to learn the correct name of registry key (result is in comments):
Code - C#: [Select]
  1. // I got the "Software\Autodesk\AutoCAD\R19.0\ACAD-B001:409" value:
  2. String _x = AcDb.HostApplicationServices.Current.MachineRegistryProductRootKey;
  3.  
  4. // I got the "Software\Autodesk\AutoCAD\R19.0\ACAD-B001:409" value:
  5. String _y = AcDb.HostApplicationServices.Current.UserRegistryProductRootKey;
  6.  
Anybody knows a solving?
« Last Edit: November 25, 2012, 02:45:03 AM by Andrey »

Andrey Bushman

  • Swamp Rat
  • Posts: 864
If I run next code in AutoCAD plugin - all works fine:

Code - C#: [Select]
  1. // I got the "Software\Autodesk\AutoCAD\R19.0\ACAD-B001:409" value:
  2. String _x = AcDb.HostApplicationServices.Current.MachineRegistryProductRootKey;
  3.  
  4. // I got the "Software\Autodesk\AutoCAD\R19.0\ACAD-B001:409" value:
  5. String _y = AcDb.HostApplicationServices.Current.UserRegistryProductRootKey;
  6.  
  7. RegistryKey rk_1 = Registry.LocalMachine.OpenSubKey(_x, false); // not null
  8. RegistryKey rk_2 = Registry.LocalMachine.OpenSubKey(_y, false); // not null
  9.  
  10. RegistryKey rk_3 = Registry.LocalMachine.OpenSubKey(@"Software\Autodesk\AutoCAD", false); // not null
  11. RegistryKey rk_4 = Registry.LocalMachine.OpenSubKey(@"Software\Autodesk\AutoCAD", false); // not null
  12.  

But if I run next code in my external application, not AutoCAD plugin, then I get null values:

Code - C#: [Select]
  1. RegistryKey rk_3 = Registry.LocalMachine.OpenSubKey(@"Software\Autodesk\AutoCAD", false); // null
  2. RegistryKey rk_4 = Registry.LocalMachine.OpenSubKey(@"Software\Autodesk\AutoCAD", false); // null
  3.  

I compile my solutions as "AnyCPU".

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Question is solved... I am an inattentive donkey: my AutoCAD plugin, and my external library was compiled as "AnyCPU", but my test console project as "x86". I recompiled console project as "AnyCPU" - all works fine. I am sorry that I have spent your time for my silly question.  :oops: