Or for a simpler way to do the same thing, get Dave Roth's Win32::AdminMisc from his PPM repository at http://www.roth.net/perl/packages (If you don't have it, get it now. It can save you a lot of time.)
There is a function in there called SetEnvVar() that will do exactly what you need. -----Original Message----- From: $Bill Luebkert [mailto:dbe@;wgn.net] Sent: Tuesday, October 22, 2002 7:13 PM To: Voyer, Paul Cc: [EMAIL PROTECTED] Subject: Re: Changing Environment variable $Bill Luebkert wrote: > Voyer, Paul wrote: > >> Hello! >> >> I did a Perl script to do some automated setting... >> >> It is running on Windows 2000, a part on my script is using >> Win32::TieRegistry. >> I update environment variable, when I look in to the registry, the >> variable is >> updated correctly. Starting a new "cmd" window, the same variable has the >> previous value. >> >> I found on a site (http://www.codeproject.com/system/pcset.asp) that >> we have to >> broadcast the variable WM_SETTINGSCHANGE to all windows in the system >> after >> updating variable in to the registry. >> >> Is this apply? How can I do it in Perl? >> >> I use setx.exe as a patch right now... It is working, but I will >> prefer to use >> Perl only. > > > I think this should do it (untested in this form): > > notify_windows ('Environment'); > exit 0; > > sub notify_windows { > use Win32::API; > use constant HWND_BROADCAST => 0xFFFF; > use constant WM_SETTINGCHANGE => 0x001A; > > my $registry_key = shift; > print "Flushing key: $registry_key \n"; > my $SendMessage = new Win32::API("user32", "SendMessage", [qw(N N P P)], > 'N') or > die "Finding SendMessage: " . Win32::FormatMessage > (Win32::GetLastError ()); > my $result = $SendMessage->Call(HWND_BROADCAST, WM_SETTINGCHANGE, 0, > 'Environment'); Actually, that should be: my $result = $SendMessage->Call(HWND_BROADCAST, WM_SETTINGCHANGE, 0, $_[0] || 'Environment'); or you could leave the arg off on the call and leave it fixed at 'Environment'. > print "SendMessage result: $result \n"; > > } -- ,-/- __ _ _ $Bill Luebkert ICQ=162126130 (_/ / ) // // DBE Collectibles Mailto:dbe@;todbe.com / ) /--< o // // http://dbecoll.tripod.com/ (Free site for Perl) -/-' /___/_<_</_</_ Castle of Medieval Myth & Magic http://www.todbe.com/ _______________________________________________ Perl-Win32-Admin mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs _______________________________________________ Perl-Win32-Admin mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs