in reply to Determine Standard Windows Paths

I prefer to ask Windows about where the stuff is instead of guessing myself, but on the other side, knowledge about these functions is well-buried in the MSDN (and in the dark recesses of my mind, back from the days when I programmed a low level language).

The Windows System directory (C:/WINNT and/or C:/WINDOWS or wherever your admin chose to install it. Note that you can have C:/WINDOWS on an NT machine even when not changing the defaults if you upgrade from Win9x or Win311 to Windows NT...). The code as posted isn't completely correct though, it won't work (or I think that it won't) under Win32s, as there is no kernel32.exe there. So some checks should be added before loading Win32::API.

use Win32::API; my $GetWindowsDirectory = new Win32::API( "KERNEL32","GetWindowsDirectoryA","PN","N" ); sub GetWindowsDirectory { my $buffer = "\0" x 255; $GetWindowsDirectory->Call($buffer,length $buffer); $buffer =~ tr/\0//d; return $buffer; }; print GetWindowsDirectory();

I'm still searching for the information on how to get at the directories for the Desktop, the Program Files and other stuff, but I guess this will be found within the next hour and then posted as an update to this node. These paths are stored in the registry somewhere, but taking them straight out of there is considered bad manners - you are supposed to obtain them via some Windows API call.

Update: The call in question is SHGetSpecialFolderLocation - I'll try out the prototype and post it soon.

perl -MHTTP::Daemon -MHTTP::Response -MLWP::Simple -e ' ; # The $d = new HTTP::Daemon and fork and getprint $d->url and exit;#spider ($c = $d->accept())->get_request(); $c->send_response( new #in the HTTP::Response(200,$_,$_,qq(Just another Perl hacker\n))); ' # web

Replies are listed 'Best First'.
Re: Re: Determine Standard Windows Paths
by demerphq (Chancellor) on Feb 12, 2002 at 15:30 UTC
    Hey Corion. Spurred on by your comments I implemented the update I posted above.

    I had to change your Win32::API calls a bit though :-)

    Anyway, I wasn't able to get anything working with SHGetSpecialFolderLocation as I couldnt figure out how to pass/manipulate ppidl or ITEMIDLIST objects properly. (I believe they would have to passed on to SHGetPathFromIDList which has pointer/memory management issues that frankly I didnt want to research into...)

    So instead I used SHGetSpecialFolderPath and to use that I spent a bit of time looking into the CSIDL enumeration (which was a bit of a pain) so if you get SHGetSpecialFolderLocation happening you should be able to use my CSIDL data.

    Anyway, hope my new version meets with your approval.

    :-)

    Yves / DeMerphq
    --
    When to use Prototypes?