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

Win32::OLE and Explorer.exe

by flyingmoose (Priest)
on Dec 09, 2003 at 21:23 UTC ( [id://313539]=perlquestion: print w/replies, xml ) Need Help??

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

Fellow monksters: I would like to open explorer.exe (aka windows file manager) from a Perl script and want to point it at a specific directory. This sounds easy enough, but for some reason, things are not going well.

Using ActiveState B633 (5.6.1), the following code segment is sufficient for WinNT and Win2k but does not work under Windows XP or Windows 2003:

if (-f "c:\\windows\\explorer.exe") { exec("c:\\windows\\explorer.exe ."); } else { exec("c:\\winnt\\explorer.exe ."); }

I was wondering if there was a way to do this with Win32::OLE. Looking around Google, CPAN, Super Search, and the Active State docs, I can't find an OLE example for manipulating Windows Explorer. There are excellent examples for Excel, Word, and Internet Explorer. Any ideas?

Replies are listed 'Best First'.
Re: Win32::OLE and Explorer.exe
by Corion (Patriarch) on Dec 09, 2003 at 21:52 UTC

    I don't remember an OLE interface to Explorer.exe, but the following works for me by spawning an Explorer window:

    my $explorer = 'c:/winnt/system32/explorer.exe'; my $directory = 'D:\\'; system($explorer,$directory) == 0 or die "Error starting $explorer : $!/$?";
    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
Re: Win32::OLE and Explorer.exe
by Anonymous Monk on Dec 09, 2003 at 21:59 UTC
    I open explorer windows that way regularly, and it has never failed - on Win2K ;-)

    Check ms support and the syntax "explorer ." isn't even documented. What is documented is the /root switch.

    explorer /root,c:\winnt opens a window view of c:\winnt.

      Excellent, that appears to be it. They changed or deprecated the syntax....
      The information in this article applies to: * Microsoft Windows XP Home Edition * Microsoft Windows XP Professional * Microsoft Windows XP 64-Bit Edition
      Next time when I RTFM, maybe I'll pick the right FM! :)
Re: Win32::OLE and Explorer.exe
by NetWallah (Canon) on Dec 09, 2003 at 21:51 UTC
    Is there a reason you are specifying the full path to "explorer.exe" ? Normally, it would always be available in your PATH, so you can simply exec "explorer.exe .", and it will be found and executed.

    The following works just as expected on my Windows XP machine:

    perl -e " exec qq(explorer.exe F:\\)" perl -e " exec qq(explorer.exe .)"
    The first opens Explorer pointing to the F: drive (at the root), the second opens the current directory.

    "We are enthusiastically pro-laugh, we are pro-choice as well. We respect each and every individual’s right not to laugh. If you want to be miserable, go right ahead. Whatever makes you happy."
Re: Win32::OLE and Explorer.exe
by Arbogast (Monk) on Dec 10, 2003 at 01:00 UTC
    use Win32::Process;

    Win32::Process::Create($job,
    "C:\\Windows\\explorer.exe",
    "explorer d:\\Sams_Data",
    0,
    NORMAL_PRIORITY_CLASS,
    ".")|| die ErrorReport();

    $job->Wait(INFINITE);
Re: Win32::OLE and Explorer.exe
by Roger (Parson) on Dec 10, 2003 at 00:19 UTC
    I don't think Microsoft Windows will ever allow you to interact with the Windows Explorer (explorer.exe) via Win32::OLE, for obvious security reasons. I see that your immediate problem can be resolved by suggestions from other monks, so I will not comment on it.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2024-03-28 17:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found