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

#!/usr/bin/perl use strict; use CGI; use Win32::OLE; my $objNetwork; my $query=new CGI; my $strDrive = 'Z:'; my $strPath = '\\PC116597\print'; $objNetwork = Win32::OLE->CreateObject('WScript.Network'); $objNetwork->MapNetworkDrive($strDrive, $strPath) || print "failed map +ping!\n"; print Win32::OLE->LastError();
Here's the error: OLE exception from "WSHNetwork.MapNetworkDrive": The network name cannot be found. Win32::OLE(0.1704) error 0x80070043: "The network name cannot be found" in METHOD/PROPERTYGET "MapNetworkDrive"

Replies are listed 'Best First'.
Re: error mapping drive ('\\')
by tye (Sage) on Jan 11, 2007 at 21:42 UTC

    '\\PC11659­7\print' is the same as '\PC116597\print' or '\\PC116597\\print'. I suggest you use '\\\\PC116597\\print'. I think that relying on the fact that '\p' gets translated into the same thing as '\\p' is just the thing that leads to this type of mistake.

    Update: And including $strDrive and $strPath in your error message would have shown you the problem immediately, so you might want to reinforce that habit.

    - tye        

      funny, i tried \\\\PC116597\\print already and it didn't work, but it works now. I must have had something else wrong. I figured the single quotes would handle it. You're right, i should have outputted the path var. Well, it's successfully mapping the drive, but for some reason my error still comes true. This line:
      $objNetwork->MapNetworkDrive($strDrive, $strPath) || print "failed ma +pping $strPath\n";
      It still prints failed even though it worked... hmmm Thanks for your help!
        It still prints failed even though it worked

        WSH-methods which don't return some other "object", more often then not return nothing at all. So you can't check for a success/failure return value as in $obj->method() || die; with those methods.

        From your observation this seems to be the case here, too.

Re: error mapping drive
by ikegami (Patriarch) on Jan 11, 2007 at 21:26 UTC
    Are you running this as a CGI? Sounds like a permission issue... Maybe someone can suggest a fix? I'm out of my domain.
Re: error mapping drive
by jettero (Monsignor) on Jan 11, 2007 at 21:31 UTC

    It says the network name cannot be found. I'm no Win32::OLE expert, but I'd guess the name isn't right or the domain isn't searchable for some reason. Does it work by IP maybe?

    -Paul

      Thanks for the quick responses guys. I tried the IP address and FQDN (PC116567.a.city.ottawa.ca), neither work. I'm on windows domain, however this is a local folder (C:\print) that i'm trying to map. I've given myself, "domain users", and "everyone" full control
        Oh, and i'm running perl locally from the command line