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

Hi all! I really have probably a Windows question, but it's within my perl script.

What is the correct syntax for passing the username and password when trying to map a drive with NET USE? The string I'm using is:

NET USE x: \\jones\backup /USER: james /PASSWORD: xxxx
What is the proper way of passing the username and password? Everything else I'm doing works. Any suggestions?? I stumped!

Thanks!

:)

Replies are listed 'Best First'.
Re: NET USE to map drive with specified account & password
by marto (Cardinal) on Sep 27, 2005 at 22:15 UTC
    Hi,

    if you type net use /? from the command prompt you see the syntax of the command.
    However, I would suggest that you take a look at the module Win32::NetResource.

    I notice that this is your first post (as a registered user).
    I think it would be worth while having a read at the PerlMonks FAQ if you have not already done so.

    Hope this helps.

    Martin
Re: NET USE to map drive with specified account & password
by NetWallah (Canon) on Sep 28, 2005 at 00:14 UTC
    NET HELP USE produces more detailed information than NET USE /?

    The syntax you seek is something like:

    NET USE x: \\jones\backup YOURPASSWORDHERE /USER:DOMAINNAME\james
    Note - NO Space between "USER:" and the name.

    For greater security, replace YOURPASSWORDHERE by "*" - this will prompt you for a password.

         "Man cannot live by bread alone...
             He'd better have some goat cheese and wine to go with it!"

Re: NET USE to map drive with specified account & password
by davidrw (Prior) on Sep 27, 2005 at 22:41 UTC
    What's your perl code that's launching the "NET USE" command? Besides marto's note of net use /? for the proper syntax, be sure to check your command string with a debug statement -- especially make sure you've escaped the backslashes properly...
    my $cmd = "NET USE x: \\jones\backup /USER: james /PASSWORD: xxxx"; warn $cmd; # whoops!! system($cmd); # because of the bad value of $cmd (see output), this w +ill not do what you want.