win xp - permanently map a network drives from command line?

15,557

Solution 1

net use V: \\compg\dir /persistent:yes

is what you are looking for. Same as checking the "Connect automatically at boot" check box.

Also, net use /delete v: to remove it

Solution 2

Set WshShell = CreateObject("WScript.Shell") WshShell.Run chr(34) & "C:\Yourfile.bat" & Chr(34), 0 Set WshShell = Nothing

Use this in a VBS....reference your path where C:\yourfile.bat is. It pops up a quick vbs screen (maybe half a sec) and you cant close it if you try to in my experience. By the time you try anyway the batch is already launched. Hope this helps

Share:
15,557

Related videos on Youtube

barlop
Author by

barlop

Updated on September 17, 2022

Comments

  • barlop
    barlop over 1 year

    I can open "My Computer"..tools..map network drive. Check "Reconnect at logon". And it is permanent. But I may want to clear the shares, and create them quickly. So I want to automatically do a few, so I want a fast way of doing it. I suppose I could write a batch and have it load with the command prompt. Lines like net use V: \\compg\dir But I want the network shares to load automatically when windows starts. I could put the bat in startup folder, but I don't want a command prompt opening up on every windows restart.

    I was hoping there might be a command to do it so it is permanent. or perhaps a windows scripting method..

    What are my options? I'm interested in what ways this can be done.

  • barlop
    barlop over 13 years
    didn't need a pic ;-) I thought of that - minimized setting, but it's not that seamless and doesn't compare to how it happens automatically if done in the GUI, with no cmd prompt opening every restart. I can probably one-up that in a sense, and hide the command prompt window, using HSTART. or there is a way in vbs, to run a batch file in a hidden command window. I was hoping for other ways though. maybe best way is hiding the cmd window when running a bat, or having a reg file that creates the mapped drives accordingly.
  • barlop
    barlop over 13 years
    hmm, last time I tried that and restarted, it didn't work.. i'll try it again.
  • barlop
    barlop over 13 years
    according to chicagotech.net/mapping.htm that persistent:yes option is the default. So I think it doesn't do what you think. slight chance it saves login info for next time or something. But it's default according to that link. And we know default doesn't keep the mapping on restart.
  • Dustin
    Dustin over 13 years
    @barlop, /persistent:yes in my experience has never been the default, unless that has changed in Win Vista / Win 7. Back in Os/2 days, it wasn't the default, and with Win XP, I always had to add it if I wanted it to persist.
  • Dustin
    Dustin over 13 years
    It isn't & is the default... From MS: /persistent:{yes | no} : Controls the use of persistent network connections. The default is the setting used last. Deviceless connections are not persistent. Yes saves all connections as they are made, and restores them at next logon. No does not save the connection being made or subsequent connections. Existing connections are restored at the next logon. Use /delete to remove persistent connections. microsoft.com/resources/documentation/windows/xp/all/proddoc‌​s/…
  • barlop
    barlop over 13 years
    @Benjamin That is an intriguing quote, but what does it mean? Is it the same as "Reconnect at logon" when mapping a network drive via the GUI? I could try it again I suppose. It may be that the mapped drive is not saved, but the logging in aspect is. I want both, and I doubt persistent does that.
  • barlop
    barlop over 13 years
    Just tried persistent again. I logged off, logged back on. It prompted me again, so didn't save user/pass. (I know /savecred does), so not sure what persistent:yes does. and of course it certainly doesn't preserve the mapped networked drive.
  • barlop
    barlop over 13 years
    -1 'cos it had one vote I just removed it. simply 'cos the "persistent:yes" does not do what your post suggests it does / what my question wanted. Also, a nitpick, there is no option with the words you have in quotation marks, the option is the words "Reconnect at logon" as my question mentioned. The exact words are useful and especially when quoting.. for googling purposes.
  • barlop
    barlop about 13 years
    see my comment to Dennis's answer