Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Refreshing the Windows Registry

by Anonymous Monk
on Jan 15, 2004 at 15:43 UTC ( [id://321583]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello monks,

I've written a script to add registry entries using the Win32::TieRegistry module. It works very well. I'm also using the Win32::ODBC module adding a DSN for an ODBC Driver.

I've discovered that the script needs to be run twice due to the following:

once: to write the new regitsry entries for the ODBC Driver and copy the appropriate dll's. twice: add a DSN for the ODBC Driver after locating the driver installed in the previous step.
Does anyone know of a way to "refresh" the registry so the script can be run once? I've tried sleeping in a while loop until I see the new Driver in the Registry but I'm forced to stop the script and run it again.

Thanks

Replies are listed 'Best First'.
Re: Refreshing the Windows Registry
by BrowserUk (Patriarch) on Jan 15, 2004 at 16:20 UTC

    Your not supplying much information. What errors do you get, and from which modules/code?

    Posting the script in question, if it isn''t too big, would help a lot.

    I suspect that you aren't untying the registry, and hence your changes aren' being commited before you try to move on to the second step, but that's a guess.

    You might try using the Flush method, though the docs say that it isn't usually necessary.

    Flush( $bFlush ) Flushes all cached information about the Registry key so that future u +ses will get fresh data from the Registry. If the optional $bFlush is specified and a true value, then RegFlushKe +y() will be called, which is almost never necessary.

    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail
    Timing (and a little luck) are everything!

      I suspect that you aren't untying the registry, and hence your changes aren' being commited

      No, changes are committed when they are made. No need to close or untie or anything.

      You might try using the Flush method, though the docs say that it isn't usually necessary.

      No, the docs say (as you quoted) that "If the optional $bFlush is specified and a true value, then RegFlushKey() will be called, which is almost never necessary." which is not at all the same as saying that Flush() isn't usually necessary.

      Win32::TieRegistry doesn't listen for changes to the registry and fetches all values or subkey names for a key in a single batch. So once you fetch any of a key's contents, the object will only report things that were in that key at the time of that first fetch. To refresh the key's contents you need to Flush() (or destroy the object and get a fresh one).

                      - tye
Re: Refreshing the Windows Registry
by MADuran (Beadle) on Jan 15, 2004 at 16:35 UTC
    If I am reading correctly you want to use your new registry settings with out a reboot.

    IF I remember correctly you need to send a  WM_SETTINGCHANGE message to the windows OS. The WIN32::OLE::NLS module has SendSettingChange() function that does just that. This is untested and over a year old memory.

    update: I miss read the question. Still you will need to send the WM_SETTINGCHANGE message for open windows (the Command/CMD prompt) to know about your change.

    MADuran
    Who is in need of a spiffy sig

      That seems to work but after calling:
      Win32::OLE::NLS::SendSettingChange();
      The rest of my script hangs

      Any thoughts?

Re: Refreshing the Windows Registry
by jwillmore (Initiate) on Jan 15, 2004 at 15:50 UTC
    I'm just taking a shot in the dark here, but .... have you considered writing a script to call the script in question twice? My thinking is - if you have to run the script twice - and a 'sleep' doesn't work - maybe if you run the script twice from another script (or even a batch script), it *may* work. HTH
      I did consider that but I'm trying to keep everything contained in one script (easier to maintain that way)
        You could just have the script execute itself again with an extra argument if it wasn't run with that argument in the first place (thereby preventing an endless loop). This will allow you to keep it all in one script for ease of maintenance.

        - - Arden.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://321583]
Approved by xenchu
Front-paged by broquaint
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2024-04-16 19:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found