Prabhu Prabhu - 1 year ago 95
Perl Question

Path from Active perl in Windows 7 does not work

I have installed Activeperl in Windows 7 machine. Everything is okay, but it cannot read a config file from the given path. The code I used is

use constant CONFIG_FNAME => '/windows/system32/softwareconfig.txt';
$self->{"config"} = &read_config_file($CONFIG_FNAME);
warn "read_config_file(CONFIG_FNAME) returned undef" if !defined($self->{"config"});

It always returns the warning. It works if I use the
in the same directory and
CONFIG_FNAME => 'softwareconfig.txt'

This code runs perfectly in windows xp. I also tried following paths, but none seems to work. These all work perfectly in xp.

CONFIG_FNAME => 'c:/windows/system32/softwareconfig.txt'
CONFIG_FNAME => 'c:\\windows\system32\softwareconfig.txt'
CONFIG_FNAME => 'c:\\windows\\system32\\softwareconfig.txt'
CONFIG_FNAME => "c:\\windows\\system32\\softwareconfig.txt"
CONFIG_FNAME => '\\windows\\system32\\softwareconfig.txt'

What can be done to correct this?

Answer Source

Your problem likely has nothing to do with Perl. Windows\system32 is a protected system directory, and Vista and later are rather protective of that location.

I do not recognize the file name 'softwareconfig.txt' as being a standard Windows file. If you are putting your own configuration files in protected system directories, stop doing that.

Environment::SpecialFolder Enumeration gives you the list of special folders on Windows.

If the configuration file is for a specific user, then a subdirectory under ApplicationData is appropriate. If it is for all users, then a subdirectory under CommonApplicationData is appropriate.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download