vbscript and net use

Discussion in 'Scripting' started by Kris, Oct 17, 2005.

  1. Kris

    Kris Guest


    I'd like to set scheduled job to run vbscript. vbscript has to copy file
    between two servers. These servers are running in different independen
    domains (no trusts).

    In vbscript I use "net use":

    set objCMD0 = CreateObject("Wscript.Shell")
    command0="net use i: \\<server_IP>\<share> <password> /user: <domain>\<user>"
    objCMD0.Run command0

    and it doesnt work.

    When I do "net use i: \\<server_IP>\<share> <password> /user:
    <domain>\<user>" from cmd it works properly.

    Have You got any ideas what is wrong?

    Thanks for help.
    Kris, Oct 17, 2005
    1. Advertisements

  2. Kris

    Scott_FH Guest

    You may want to try "MapDriveNetwork" instead of net use if you just need to
    map a drive.

    Dim WshNetwork
    Set WshNetwork = WScript.CreateObject("WScript.Network")
    WshNetwork.MapNetworkDrive "E:", "\\Server\Public", , strUser, strPassword

    Here is a link to the documentation

    As for your current script you may just be missing some quotes in the
    command if there are any spaces in the share, domain, password.


    command0="net use i: ""\\<server_IP>\<share>"" ""<password>"" /user:
    Scott_FH, Oct 17, 2005
    1. Advertisements

  3. Kris

    Kris Guest

    I was tested net use and WshNetwork.MapNetworkDrive. Both work if I select
    "open" vbscript but if I select open with command prompt it fails (can't
    access to mapped network drive: the network drive is mapped but script can't
    do for example dir <drive_letter>).

    Kris, Oct 19, 2005
  4. Kris

    Scott_FH Guest

    Try something simple like the script below, or just mapping the drives and
    doing a copy cmd. if they do not work, they may give you a more descriptive
    error as to what the problem is.

    Dim WshNetwork
    Set WshNetwork = WScript.CreateObject("WScript.Network")
    WshNetwork.MapNetworkDrive "I:", "\\Server\share", , "domain\user", "Password"

    dim fso
    set fso = createobject("scripting.FileSystemObject")
    fso.CopyFile "c:\test.txt", "I:\path\"
    Scott_FH, Oct 19, 2005
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.