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 !
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
::make sure you can see the interwebs
ping %ServerIP% -n 2 | find /i "bytes=" > nul && goto Connect
ping localhost -n 180 > nul
::once you can see the interwebs, run your net use batch
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
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:\\"