by Whaat » Tue Jul 14, 2009 11:31 pm
From the little research I have done, it seems like the only way to ready values from the Windows registry is to use the WinOLE library. Is there a way to do it without using a library?
Can someone post some sample code for how to ready values from the registry using an external library?
Thanks in advance!
-
Whaat
- PluginStore Author

-
- Posts: 1077
- Joined: Wed Nov 14, 2007 9:51 pm
- Location: Saskatchewan, Canada
- Name: Whaat
- Operating system: Windows
- SketchUp version: 2017
- License type: Pro
- SketchUp use: architecture
- Level of SketchUp: Advanced
-
by thomthom » Wed Jul 15, 2009 12:22 am
You could make calls to the Windows API directly. I just started calling the Windows API to call file functions that support Unicode characters.
Or are you looking for an abstracted way of calling the registry?
-

thomthom
- PluginStore Author

-
- Posts: 19457
- Joined: Tue Nov 13, 2007 12:47 pm
- Location: Trondheim, Norway
- Name: Thomas Thomassen
- Operating system: Windows
- SketchUp version: 2019
- License type: Pro
- SketchUp use: other
- Level of SketchUp: Advanced
-
by Whaat » Wed Jul 15, 2009 3:23 am
I'm just not familiar with the Windows API and I was wondering if you can access the registry without using it. I am guessing not.
-
Whaat
- PluginStore Author

-
- Posts: 1077
- Joined: Wed Nov 14, 2007 9:51 pm
- Location: Saskatchewan, Canada
- Name: Whaat
- Operating system: Windows
- SketchUp version: 2017
- License type: Pro
- SketchUp use: architecture
- Level of SketchUp: Advanced
-
by TIG » Wed Jul 15, 2009 9:24 am
http://code.google.com/apis/sketchup/do ... ad_default ? reads .ini on Mac and Registry on Win/PC ?? But you need to know what you are looking up... You can also write .bat/.cmd files for Windows that read/write registry values, using them inside SUp might mean they are ineffective - SUp reads the registry settings on startup and writes the current settings on close, so any changes tou have made to the Registry in between might get lost ?
TIG
-

TIG
- Global Moderator
-
- Posts: 20380
- Joined: Mon Nov 12, 2007 7:24 pm
- Location: Northumbria UK
- Name: TIG
- Operating system: Windows
- License type: Pro
- SketchUp use: architecture
- Level of SketchUp: Advanced
by thomthom » Wed Jul 15, 2009 9:38 am
Seems that the Win32 module already got some wrappers for the registry: http://ruby-doc.org/stdlib/libdoc/Win32 ... istry.html
-

thomthom
- PluginStore Author

-
- Posts: 19457
- Joined: Tue Nov 13, 2007 12:47 pm
- Location: Trondheim, Norway
- Name: Thomas Thomassen
- Operating system: Windows
- SketchUp version: 2019
- License type: Pro
- SketchUp use: other
- Level of SketchUp: Advanced
-
by Whaat » Thu Jul 16, 2009 2:54 am
Aha...I recently came across that too, Thomthom! I think that 'registry.rb' is the ticket. While it is part of the Win32 API, it looks quite simple to use. Thanks!
-
Whaat
- PluginStore Author

-
- Posts: 1077
- Joined: Wed Nov 14, 2007 9:51 pm
- Location: Saskatchewan, Canada
- Name: Whaat
- Operating system: Windows
- SketchUp version: 2017
- License type: Pro
- SketchUp use: architecture
- Level of SketchUp: Advanced
-
by Chris Fullmer » Thu Jul 16, 2009 5:15 am
Dale I recently tried to include the registry.rb and ran into problems. Probably not due to Ruby or SU, but just because I didn't know what I was doing. So I would be interested in what you do to make the registry.rb file work. I felt like there was some circular "require"ing going on, and I never quite figured it out. So if you do, I'd like to know how to do it please. I am looking at writing a script that needs to access the registry. Thanks!
Chris
-

Chris Fullmer
- SketchUp Team

-
- Posts: 6916
- Joined: Wed Nov 21, 2007 3:21 am
- Location: Boulder, CO
- Name: Chris Fullmer
- Operating system: Windows
- SketchUp version: 2013
- License type: Pro
- SketchUp use: landscape architecture
- Level of SketchUp: Advanced
-
by Whaat » Tue Aug 11, 2009 5:06 am
Ok, I am successfully reading the windows registry. However, I have run into a roadblock on Windows Vista systems. It seems as though Vista prevents access to reading the registry unless you are logged in as an administrator. If anyone knows how to get around this issue, please let me know! This is the code I am using: - Code: Select all
require 'Win32API' require 'registry'
Win32::Registry::HKEY_CURRENT_USER.open('Software\Glare Technologies\Indigo Renderer') do |reg| #this line works fine... reg_typ, reg_val = reg.read('InstalledVersion') #...but this line fails on Vista only. return reg_val end
-
Whaat
- PluginStore Author

-
- Posts: 1077
- Joined: Wed Nov 14, 2007 9:51 pm
- Location: Saskatchewan, Canada
- Name: Whaat
- Operating system: Windows
- SketchUp version: 2017
- License type: Pro
- SketchUp use: architecture
- Level of SketchUp: Advanced
-
by TIG » Tue Aug 11, 2009 7:58 am
Are you an 'Administrator' ? See Vista Users C'Panel...
TIG
-

TIG
- Global Moderator
-
- Posts: 20380
- Joined: Mon Nov 12, 2007 7:24 pm
- Location: Northumbria UK
- Name: TIG
- Operating system: Windows
- License type: Pro
- SketchUp use: architecture
- Level of SketchUp: Advanced
by remus » Tue Aug 11, 2009 8:10 am
TIG wrote:Are you an 'Administrator' ? See Vista Users C'Panel...
Not going to work for a lot of users, though.
-
remus
-
- Posts: 8044
- Joined: Fri Nov 30, 2007 8:48 am
- Location: UK
- Name: remus
-
by TIG » Tue Aug 11, 2009 8:52 am
remus wrote:TIG wrote:Are you an 'Administrator' ? See Vista Users C'Panel...
Not going to work for a lot of users, though.
Unfortunately, if you are not 'the' [or 'an'] Administrator then Vista is a pig ! SUp Ruby has built-in read/write registry methods, BUT often you can't write stuff that gets kept as SUp reverts on close... Sketchup.read_default("section","variable","default") Sketchup.write_default("section","variable","my_value")Have limited uses... You can also use external .bat or .cmd files to do stuff to the registry but again you could be prompted as user...
TIG
-

TIG
- Global Moderator
-
- Posts: 20380
- Joined: Mon Nov 12, 2007 7:24 pm
- Location: Northumbria UK
- Name: TIG
- Operating system: Windows
- License type: Pro
- SketchUp use: architecture
- Level of SketchUp: Advanced
by thomthom » Wed Nov 04, 2009 11:39 am
Whaat wrote:Ok, I am successfully reading the windows registry. However, I have run into a roadblock on Windows Vista systems. It seems as though Vista prevents access to reading the registry unless you are logged in as an administrator. If anyone knows how to get around this issue, please let me know! This is the code I am using: - Code: Select all
require 'Win32API' require 'registry'
Win32::Registry::HKEY_CURRENT_USER.open('Software\Glare Technologies\Indigo Renderer') do |reg| #this line works fine... reg_typ, reg_val = reg.read('InstalledVersion') #...but this line fails on Vista only. return reg_val end
Did you ever find a solution for that? Is it for any value you try to read? Any part of the registry? Or the specific part you tried to read? Maybe it was due to the permission set by the application that wrote the keys.
-

thomthom
- PluginStore Author

-
- Posts: 19457
- Joined: Tue Nov 13, 2007 12:47 pm
- Location: Trondheim, Norway
- Name: Thomas Thomassen
- Operating system: Windows
- SketchUp version: 2019
- License type: Pro
- SketchUp use: other
- Level of SketchUp: Advanced
-
by thomthom » Wed Nov 04, 2009 11:45 am
Chris Fullmer wrote:Dale I recently tried to include the registry.rb and ran into problems. Probably not due to Ruby or SU, but just because I didn't know what I was doing. So I would be interested in what you do to make the registry.rb file work. I felt like there was some circular "require"ing going on, and I never quite figured it out. So if you do, I'd like to know how to do it please. I am looking at writing a script that needs to access the registry. Thanks!
Chris
Where did you get the registry.rb?
-

thomthom
- PluginStore Author

-
- Posts: 19457
- Joined: Tue Nov 13, 2007 12:47 pm
- Location: Trondheim, Norway
- Name: Thomas Thomassen
- Operating system: Windows
- SketchUp version: 2019
- License type: Pro
- SketchUp use: other
- Level of SketchUp: Advanced
-
by TIG » Wed Nov 04, 2009 12:24 pm
If this is a PC based tool then why not write a separate short batch file that examines the registry and then writes its findings to a temp file. You can run the xxx.bat file using UI.openURL("pathtoBATfile") and then read its temp file, then delete it to tidy up...
TIG
-

TIG
- Global Moderator
-
- Posts: 20380
- Joined: Mon Nov 12, 2007 7:24 pm
- Location: Northumbria UK
- Name: TIG
- Operating system: Windows
- License type: Pro
- SketchUp use: architecture
- Level of SketchUp: Advanced
by thomthom » Wed Nov 04, 2009 3:37 pm
So if you wanted to use the registry, did you copy the file from a standard Ruby installation? I extracted one from an 1.8.0 Build 10 package. I then managed to access the registry - but how would you package your plugin? What if other plugins also need registry access? Should I modify the registry.rb and wrap the code into my own namespace?
Or would it be fine to load only if Win32::Registry isn't defined? require 'C:\ruby\lib\ruby\1.8\win32\registry.rb' if defined?(Win32::Registry).nil?
-

thomthom
- PluginStore Author

-
- Posts: 19457
- Joined: Tue Nov 13, 2007 12:47 pm
- Location: Trondheim, Norway
- Name: Thomas Thomassen
- Operating system: Windows
- SketchUp version: 2019
- License type: Pro
- SketchUp use: other
- Level of SketchUp: Advanced
-
by RunnerPack » Wed Nov 04, 2009 7:43 pm
Why not just use a plain-text configuration file located in your plug-in's ".../Plugins/pluginname" folder. You could use INI, XML, JSON, RON, etc. This would have the advantages of working on both Vista and OSX transparently, and it would probably be more powerful and easier to implement, to boot. As a long-time Windows user, I think the registry was a terrible idea that was also quite poorly implemented. I understand that it was designed to make the job of administrators of large corporate networks easier, but as an individual computer user, I tend to prefer programs (and plug-ins  ) that use a human-readable ini file of some kind.
You might have noticed... I'm a bit of a ferpectionist.
-

RunnerPack
-
- Posts: 32
- Joined: Wed Apr 29, 2009 9:22 am
- Location: Springfield, MO
- Name: RunnerPack
- Operating system: Windows
- SketchUp version: pre-2013
- License type: Free/Make
- SketchUp use: hobby
- Level of SketchUp: Advanced
by thomthom » Wed Nov 04, 2009 7:51 pm
RunnerPack wrote:Why not just use a plain-text configuration file located in your plug-in's ".../Plugins/pluginname" folder. You could use INI, XML, JSON, RON, etc. This would have the advantages of working on both Vista and OSX transparently, and it would probably be more powerful and easier to implement, to boot. As a long-time Windows user, I think the registry was a terrible idea that was also quite poorly implemented. I understand that it was designed to make the job of administrators of large corporate networks easier, but as an individual computer user, I tend to prefer programs (and plug-ins  ) that use a human-readable ini file of some kind.
In my case I'm reading registry info of an application - not trying to store my settings.
-

thomthom
- PluginStore Author

-
- Posts: 19457
- Joined: Tue Nov 13, 2007 12:47 pm
- Location: Trondheim, Norway
- Name: Thomas Thomassen
- Operating system: Windows
- SketchUp version: 2019
- License type: Pro
- SketchUp use: other
- Level of SketchUp: Advanced
-
by Al Hart » Wed Nov 04, 2009 9:22 pm
This ruby uses Win32API to read the registry, and works on Vista. But it may not work if you are not an Administrator (who knows). It is looking for the entry: HKEY_LOCAL_MACHINE\SOFTWARE\Render Plus Systems\IRender_nxt_location So you will have to change it to the registry key you are looking for. - Code: Select all
class Your_class def self::get_reg_functions @@RegCloseKey = Win32API.new('advapi32', 'RegCloseKey', 'L', 'L') if @RegCloseKey == nil @@RegOpenKeyEx = Win32API.new('advapi32', 'RegOpenKeyEx', 'LPLLP', 'L') if @RegOpenKeyEx == nil @@RegQueryValueEx = Win32API.new('advapi32', 'RegQueryValueEx', 'LPLPPP', 'L') if @RegQueryValueEx == nil #@@RegCreateKeyEx = Win32API.new('advapi32'', 'RegCreateKeyEx', 'LPLLLLPPP' 'L') end#def
def self::get_registry_entry(key, sdefault = "") #trace("key: %s",key) get_reg_functions
key.tr!('/','\\') sret = sdefault # strip of section spos = key.Find('\\') if (spos < 1) do_error("Cannot parse registry key %s - Key must contain a backslash\n",key) return(sdefault) end#if
firstpiece = key.Left(spos) mainkey = key.Mid(spos+1) if (firstpiece == "HKEY_LOCAL_MACHINE") root = HKEY_LOCAL_MACHINE elsif (firstpiece == "HKEY_CURRENT_USER") root = HKEY_CURRENT_USER else printf("Registry key must start with HKEY: %s",key) return(sdefault) end#if # strip off final key spos = mainkey.ReverseFind('\\') if (spos < 1) printf("Cannot parse registry key %s - Key must contain a backslash\n",key) return(sdefault) end#if
lastpiece = mainkey.Mid(spos+1) mainkey = mainkey.Left(spos)
phkey = [0].pack('L') # a 4 byte string of 0's go get handle
ret = @@RegOpenKeyEx.call(root, mainkey, 0, KEY_READ, phkey) printf("ret: %s mainkey: %s\n",ret,mainkey) if (ret != 0) printf("key not found: %s\n",key); return(sdefault) end#if hkey = phkey.unpack('L').first # convert stron pointer to integer # create a buffer for the result buf = 0.chr * 1024 size = [buf.length].pack('L') # store size of buffer ret = @@RegQueryValueEx.call(hkey, lastpiece, 0, 0, buf, size) if (ret != 0) printf("location not found: %s\n",key); return(sdefault) end#if # if ret == ERROR_MORE_DATA, then we should call again with a larger buffer @@RegCloseKey.call(hkey) sret = buf.nstrip # stop at 0 byte printf("sret: %s length: %d key: %s\n",sret,sret.length,key) return sret end#def # this returns the location without a slash def self::find_application_folder(smodule) #skey = sprintf("HKEY_LOCAL_MACHINE\\SOFTWARE\\Render Plus Systems\\%s_location", smodule) skey = sprintf("HKEY_LOCAL_MACHINE/SOFTWARE/Render Plus Systems/%s_location", smodule) sloc = get_registry_entry(skey) printf("sloc: %s from skey: %s\n",sloc,skey) if (sloc && FileTest.exists?(sloc)) sloc.tr!('/','\\') #printf("RETURNING 1 sloc: %s\n",sloc) return(sloc) if sloc != nil end#if printf("Registry entry not found: %s\n", skey) return nil end#def
end#class Your_class
Your_class::find_application_folder("IRender_nxt")
-

Al Hart
- PluginStore Author

-
- Posts: 1623
- Joined: Sun Nov 18, 2007 3:54 pm
- Location: Centennial, Co
- Name: Al Hart
- Operating system: Windows
- SketchUp version: pre-2013
- License type: Pro
- SketchUp use: other
- Level of SketchUp: Advanced
-
by Ad Machine » 5 minutes ago
-
Ad Machine
- Robot
-
- Posts: 2012
-
Return to Developers' Forum
|