basic map drive scripts

Discussion in 'Scripting' started by Chris, Jul 8, 2008.

  1. Chris

    Chris Guest

    Hello,

    i need a basic map drive script which i've got.. but what happens if it is
    already mapped? is there a similair /peristent option? or does it disconnect
    automatically?

    Set objNetwork = CreateObject("WScript.Network")
    objNetwork.MapNetworkDrive "x:" , "\\server\share"
     
    Chris, Jul 8, 2008
    #1
    1. Advertisements

  2. Why don't you run a little test to see what happens if the drive
    letter is already mapped?
     
    Pegasus \(MVP\), Jul 8, 2008
    #2
    1. Advertisements

  3. Chris

    Chris Guest

    Hi Pegasus,

    This is my job tomorrow. lol. It's been sort of dropped on me and i have a
    tight deadline so was trying to do as much prep as i can.. Currently
    trawling google aswell. :)
     
    Chris, Jul 8, 2008
    #3
  4. Since you're sitting at a PC, it will take you less than a minute
    to find out for yourself. Map Q: to \\YourPC\C$ manually,
    then run your VB Script. You don't need a server to test such
    a simple issue!
     
    Pegasus \(MVP\), Jul 8, 2008
    #4
  5. Chris

    Chris Guest

    I have done that and received the error. I am unsure if it will be different
    via a gpo. Unfortunately i can't test that here. i've never ran scripts
    this way before as always done it via the user account.

    Cheers
    Chris
     
    Chris, Jul 8, 2008
    #5
  6. Group Policy is about user rights and settings - it has no effect
    whatsoever on the mechanism that controls the mapping of a
    drive on top of an existing mapping. If you want to write a robust
    script that works no matter what then you should test for
    existing connections, e.g. like so: If objfso.DriveExists("D:") . . .
     
    Pegasus \(MVP\), Jul 8, 2008
    #6
  7. Chris

    Chris Guest

    Cheers Pegasus :)

     
    Chris, Jul 9, 2008
    #7
  8. //Script fo network drive mapping with error processing
    //sorry, I'm lazy for wrinting VBS analog :)

    var WshNetwork = WScript.CreateObject("WScript.Network");
    var objNetDrivers = WshNetwork.EnumNetworkDrives();

    DriveConnector("X:",\\\\Server\\Share1);
    DriveConnector("Y:",\\\\Server\\Share2);
    ////////////////////////////////////////////////////////////////////////
    // Function for network drive mapping //
    ///////////////////////////////////////////////////////////////////////
    function DriveConnector(DrvName,UNCPath)
    {
    var DrivePresent = false;
    for(var i=0;i<=objNetDrivers.Count()-1;i++)
    {
    if(objNetDrivers.item(i) == DrvName)
    DrivePresent = true;
    }
    if(!DrivePresent)
    {
    ErrorConnect = false;
    try
    {
    WshNetwork.MapNetworkDrive(DrvName,UNCPath,true);
    }
    catch(e)
    {
    if(e != 0)
    {
    WScript.Echo("Error network drive " + DrvName + "
    connection. " + e.description);
    ErrorConnect = true;
    }
    }
    if(!ErrorConnect)
    WScript.Echo("Network drive " + DrvName + " connected");
    }
    }
     
    Andrew Mishechkin, Aug 13, 2008
    #8
  9. Chris

    Joe Guest

    I tried using this script and get an error line 1 char. 57.
    Anyway - to Pegasus

    You have a guy come on here and ask a question because obviously this is all
    new to him and you give him this expert response. Well I wish I could help
    you but I am just going to bust your balls a little bit.

    Chris - Did you ever find out how to do this?

    I am in the same boat as you -
     
    Joe, Sep 18, 2008
    #9
  10. Chris

    Al Dunbar Guest

    That could be because you were expecting a vbscript but were supplied a
    jscript. rename your file from whatever.vbs to whatever.js, and it might
    just work.

    /Al
     
    Al Dunbar, Sep 19, 2008
    #10
    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.