[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Updating path in windows

Berger, Daniel

11/6/2003 2:16:00 PM

> -----Original Message-----
> From: Harry Ohlsen [mailto:harryo@qiqsolutions.com]
> Sent: Wednesday, November 05, 2003 10:22 PM
> To: ruby-talk ML
> Subject: Updating path in windows
>
>
> I'm writing a simple install script for some software. The
> final thing I need to do is to add into the path the
> directory where the software has been written.
>
> Using Win32::Registry, I can update what I think are the
> right registry entries (for either the user, or the system
> overall), but they don't seem to end up in the path if I open
> a new DOS window.
>
> However, if I change the same variables via
> ControlPanel/System/Advanced/EnvironmentVariables things work
> OK. It seems as though that tool is doing something else
> over and above changing the registry.
>
> I assume there must be some API call I need to make to get
> Windows to re-read the values from the registry?
>
> Anyone have any ideas?
>
> Cheers,
>
> Harry O.

I haven't looked at Win32::Registry, but this is from the MSDN site:

To programmatically add or modify system environment variables, add them
to the HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session
Manager\Environment registry key, then broadcast a WM_SETTINGCHANGE
message. This allows applications, such as the shell, to pick up your
updates.

So, perhaps there's some sort of "update" method that broadcasts the
WM_SETTINGCHANGE. Otherwise, your option is OS.reboot. :)

Regards,

Dan

6 Answers

Harry Ohlsen

11/6/2003 9:55:00 PM

0

Berger, Daniel wrote:

> I haven't looked at Win32::Registry, but this is from the MSDN site:
>
> To programmatically add or modify system environment variables, add them
> to the HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session
> Manager\Environment registry key, then broadcast a WM_SETTINGCHANGE
> message. This allows applications, such as the shell, to pick up your
> updates.
>
> So, perhaps there's some sort of "update" method that broadcasts the
> WM_SETTINGCHANGE. Otherwise, your option is OS.reboot. :)

Yes!

I eventually found some C++ code that did what SETX does. SETX is a command-line utility that comes with some kind of windows administration kit. It does basically what I was trying to do. By looking at the C++ source code I could see that it was broadcasting the WM_SETTINGCHANGE after updating the registry.

Since I'm definitely not much of a Windows programmer, it took me a while to find all the magic numbers, and work out the right types to specify for the parameters to Win32API::new, but I eventually got it working.

Fortunately, I have MSVC++ here at work, so I was able to search the header files to find the magic numbers.

Does anyone know whether there's a way to get those magic numbers (eg WM_SETTINGCHANGE) directly out of some DLL or something that comes standard with Windows? If not, maybe I'll write a script that runs through all the Windows C++ header files and generates a Ruby script that defines them all ... more likely a bunch of them, to allow pulling in only what a given script needs.

The other thing that would be really nice would be a way to generate the array of strings that Win32API::new takes to specify the parameter types for the system call. Does anyone have an idea how one might be able to do that?

Cheers,

Harry O.



nobu.nokada

11/7/2003 1:55:00 AM

0

Hi,

At Fri, 7 Nov 2003 06:55:07 +0900,
Harry Ohlsen wrote:
> Does anyone know whether there's a way to get those magic
> numbers (eg WM_SETTINGCHANGE) directly out of some DLL or
> something that comes standard with Windows? If not, maybe
> I'll write a script that runs through all the Windows C++
> header files and generates a Ruby script that defines them
> all ... more likely a bunch of them, to allow pulling in only
> what a given script needs.

I don't guess it is possible to get them from DLL. Try
http://www.moonwolf.com/ruby/archive/win32module_2000122...

--
Nobu Nakada

Harry Ohlsen

11/7/2003 4:03:00 AM

0

> I don't guess it is possible to get them from DLL. Try
> http://www.moonwolf.com/ruby/archive/win32module_2000122...

Wow! There's a lot of stuff in there!

Which script do I run to see what it does?

Harry O.



nobu.nokada

11/7/2003 4:17:00 AM

0

Hi,

At Fri, 7 Nov 2003 13:03:26 +0900,
Harry Ohlsen wrote:
> > I don't guess it is possible to get them from DLL. Try
> > http://www.moonwolf.com/ruby/archive/win32module_2000122...
>
> Wow! There's a lot of stuff in there!

Fundamentally, files you need should be under win32 directory.

> Which script do I run to see what it does?

$ grep -nr SETTING win32/
win32/winuser.rb:1199: WM_SETTINGCHANGE = 26

--
Nobu Nakada

Harry Ohlsen

11/7/2003 4:22:00 AM

0

> $ grep -nr SETTING win32/
> win32/winuser.rb:1199: WM_SETTINGCHANGE = 26

Ah!

Did you already have this around or did you just build it?

H.



nobu.nokada

11/7/2003 8:07:00 AM

0

Hi,

At Fri, 7 Nov 2003 13:21:36 +0900,
Harry Ohlsen wrote:
> > $ grep -nr SETTING win32/
> > win32/winuser.rb:1199: WM_SETTINGCHANGE = 26
>
> Ah!
>
> Did you already have this around or did you just build it?

Already, but it's not me, by MoonWolf.

--
Nobu Nakada