4

I have an ubuntu 11.04 machine with a samba share, which I access from a Windows 7 machine. Both have same username and password. The network drive is mapped and remembered on Windows. When I reboot the Windows 7 machine and start 'cmd.exe' and type 'net use' I see the mapped share listed as 'unavailable'. When I try to access it by 'N:' is says ""the system cannot find the drive specified". When I look in Windows explorer there is a red X in it. As soon as I click on it in Windows explorer it becomes available and now works as expected from 'cmd.exe'. I really want to automate the startup instead of having to manually 'initialize' the share with Windows explorer after every reboot ... help !

3
  • Is the windows 7 a machine with a wireless network connection? Guessing that the drive mapping (and initial failure) happens at bootup, then you have a network connection available. At that point, when the remap is mannualy attempted its a case of "oh yeah, that mapped drive".
    – jdh
    Commented Feb 11, 2012 at 13:54
  • 1
    It's a wired connection. It also happens consistently with drive maps to my FreeNAS server. The servers are up and running fine. This has been a problem almost as long as I've used Windows, I just haven't needed to automate it before so can't figure out what to type in 'cmd.exe' that has the effect of looking at the mapped drive in explorer. Commented Feb 13, 2012 at 15:13
  • Had same issue in a workgroup setup with Win XP (should apply to win 7 too) just before doing a backup to persistent network share with status "Unavailable". I wrote script that checks if net use|find "drive:"|find /v "OK " is true issues net use drive: \\sharename this changes status to "OK". Has same effect as a opening drive with "disconnected drive" status in Windows explorer. If your part of a Domain use @ben's solution
    – Scott R
    Commented Feb 15, 2018 at 17:59

3 Answers 3

2

I would make a startup script and place it in the startup folder (see code below for location). Copy and modify the contents below into a text file, and save as a .bat


::C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup
::http://answers.microsoft.com/en-us/windows/forum/windows_7-networking/delay-mounting-network-drive-at-boot/e25538d4-6f85-442c-ac43-3f8ba2e9bf75
@echo off
::make sure you can see the interwebs
set ServerIP=www.google.com
:Loop
ping %ServerIP% -n 2 | find /i "bytes=" > nul && goto Connect
ping localhost -n 180 > nul
goto Loop
::once you can see the interwebs, run your net use batch
:Connect
net use /persistent:no
net use * /del /yes
::here you put your netuse command you want to run
net use w: \192.168.1.55\mascotdata /use:HOME\mtnchkn supersecretpassword /persistent:no


1
  • The approach of using 'net use' to delete and recreate the share worked (although I used a simpler syntax for 'net use' than that shown). Perhaps that's what Windows Explorer does as well. Commented May 4, 2012 at 21:36
2

By using "net delete" and "net use" you have to give full information including password in clear text. I do not like this.

My solution is the following batch file, placed into startup (with window mode in the startup-lnk set to "minimized").

You must adjust the drive letters to your needs.
Maybe the connect-waiting loop from Ben#s answer is needed (not in my situation).

@echo off
rem run Explorer minimized
start /min S:\
start /min N:\
rem wait a bit and close/kill both explorer windows (note: reverse order seems to matter)
timeout 2 /nobreak
taskkill /im explorer.exe /fi "WINDOWTITLE eq N:\\"
taskkill /im explorer.exe /fi "WINDOWTITLE eq S:\\"
rem repeat the close if it did not succeed
timeout 1 /nobreak
taskkill /im explorer.exe /fi "WINDOWTITLE eq S:\\"
taskkill /im explorer.exe /fi "WINDOWTITLE eq N:\\"
0

I had a similar issue and was able to workaround by adding the credentials to Generic Credentials in Credential Manager:

cmdkey /generic:yourIP /user:yourUser /pass:yourPass

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .