Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Donate Today!

Do you enjoy these
technical forums?
Donate Today! Click Here

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

batch command won't run at startup - reconnect network driveHelpful Member!(3) 

bpwiz (IS/IT--Management) (OP)
12 May 11 16:21
Hi folks! I have two problems that are probably pretty common on XP. First is that I need to have a network drive accessible upon system startup (it's an XP server that needs to reboot daily). It is ostensibly connected automatically at startup but remains inaccessible to the program that needs it until I manually open the folder location. I want to automate this task, and have read that the most common solution is to explicitly connect to the drive using the 'net use' command in a batch file and run it at system startup. The second problem is that the 'net use' command works as desired to make the drive accessible when I launch it myself by double-clicking the batch file, but does not work when I run it as a startup command. The other program runs fine from the batch, but fails because it cannot access the drive. Argh! How is it that double-clicking the batch file works for net use, but putting it in the startup folder does not? Help greatly appreciated!
Helpful Member!  linney (TechnicalUser)
12 May 11 17:09
A couple of ideas for you to look at.

Can you make any use of this Policy Setting?

The policy "Always wait for the network at computer startup and logon" is found:

Computer Configuration/  Administrative Templates/  System/  Logon



What if you used Scheduled Tasks to run any Batch File, rather than the Startup Folder.  You may have to give the task Administrative Permissions?
 
Helpful Member!  BadBigBen (MIS)
12 May 11 17:42
also take a look at:

Mapped Drive Connection to Network Share May Be Lost
http://support.microsoft.com/kb/297684
 

Ben
"If it works don't fix it! If it doesn't use a sledgehammer..."
How to ask a question, when posting them to a professional forum.
Only ask questions with yes/no answers if you want "yes" or "no"

Helpful Member!  bpwiz (IS/IT--Management) (OP)
12 May 11 18:42
Thanks, linney, for your suggestions. The scheduled tasks idea I had tried already, but unfortunately that had the same result as the startup menu option.

The Policy Setting idea was a good one, though, and I hadn't thought about that one. Unfortunately, I enabled that option, rebooted several times and still no luck.

At the moment, I'm finding myself longing for the cron and shell scripting of the unix environment to which I'm accustomed. Windows can get tricky for this more technical stuff!
bpwiz (IS/IT--Management) (OP)
12 May 11 18:57
BBB: thanks for that tip. I went ahead and gave it a try, and it seems like a useful setting for my purposes anyway, but I don't think it directly relates to this startup issue. It looks to be more of an inactivity timeout concern. It did point me in the direction of a few more registry tweaks I could try. Thanks for the input.
Turkbear (TechnicalUser)
12 May 11 19:55
Hi,
Perhaps it is a startup order issue..The batch file may be trying to set up the net use link before the needed prerequisite services are running.

 

profile

To Paraphrase:"The Help you get is proportional to the Help you give.."

linney (TechnicalUser)
13 May 11 2:15
Maybe any batch file might benefit from a timeout delay or sleep command?

TIMEOUT.exe
http://ss64.com/nt/timeout.html
webrabbit (MIS)
13 May 11 11:48
Put the NET USE command in the same batch file that runs the other program.  Precede it with a NET USE /DELETE command so that it does not fail.
bpwiz (IS/IT--Management) (OP)
13 May 11 14:54
Very helpful suggestions, all. I will have to wait until midafternoon my time to test this again. I will report back with my findings!
rasETL (IS/IT--Management)
13 May 11 15:47
I agree with webrabbit.
If you already execute a batch/command file, add the "net use" command in it as a prior step.
Or, call the batch file that issues the net use from the file.
bpwiz (IS/IT--Management) (OP)
13 May 11 19:12
Currently, I have all the commands running from one batch script in the startup folder. The script currently waits for 10 seconds, then issues the net use command (which I have verified works to reconnect the drive)(I tried it with the /delete option, but that threw back an error message, will have to look more into it. For now, I'm running it with a start /wait command which ensures other processes do not run before it has completed) and then launches my program. No luck with this setup.

I also tried the "Delay mounting network drive at boot" link but it's for Win7 and the netlogon.bat file location/behavior is different for windows XP. That's another lead I'll research further. I'll have to do some more dicking around and report back! Thanks again for the continued suggestions.

 
BadBigBen (MIS)
13 May 11 21:01
OK, using the last script (see below) from the WINDOWS 7 link (see above), and saving it out as TEST.BAT, placed under C:\ (can be actually anyplace) and using the MMC to create a GroupPolicy startup script policy, works on my test XP system...

Script:

CODE

@echo off
set ServerIP=192.168.1.100
:Loop
ping %ServerIP% -n 2 | find /i "bytes=" > nul && goto Connect
ping localhost -n 180 > nul
goto Loop

:Connect
net use S: \\%ServerIP%\ShareName

and

How to: Add startup and shutdown scripts in Windows
http://www.tutorial5.com/content/view/157/47/

Ben
"If it works don't fix it! If it doesn't use a sledgehammer..."
How to ask a question, when posting them to a professional forum.
Only ask questions with yes/no answers if you want "yes" or "no"

bpwiz (IS/IT--Management) (OP)
14 May 11 18:55
Thanks, BBB and everyone, for all of your time investment into helping me solve this problem. Unfortunately, I tried the script and the group policy startup approach and still no dice. I have now, through additional testing, been able to confirm that the network drive is simply unavailable to the program until the desktop is shown - it's not listed as a potential drive. I've run the application that needs it in debugging mode, and it pops up a window during startup asking for the drive, and it's just not there. If I run your script from the .bat file myself after I've fully booted into the desktop, it works immediately. Very strange indeed. I'm not sure what other boot-order steps there are to try, but I'm starting to wonder if this specific application does not handle networking gracefully. I'd first thought it was an OS issue, but I'm starting to wonder. May have to contact the devs on Monday.
bpwiz (IS/IT--Management) (OP)
14 May 11 18:58
Another thought that just occurred to me: the app seems to be heavily reliant on the .NET framework, and I've heard of that bringing its own kettle of fish with it. Any possibility I might have to pass some commands the framework in the startup script? I know all of nothing about .NET.
bpwiz (IS/IT--Management) (OP)
21 Jun 11 19:50
Just thought I'd follow up with the solution that finally worked: I found these two registry entries:

HKLM\System\CurrentControlSet\Control\NetworkProvider\

Name: RestoreConnection
Type: REG_DWORD
Value: 1

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System

Name: EnableLinkedConnections
Type: REG_DWORD
Value: 1

Had to make a new entry for one, changed the other from 0 to 1 and it worked like a charm! Haven't tested them individually to see if only one was needed, so if you're the cautious type, try first one and then the other. After changing these, no startup script was necessary - I just put the app in the startup folder and I was up and running. Apparently, these work in Vista and Windows 7 as well.

For a very good thread that turned me on to these (and has many helpful suggestions), see
http://social.technet.microsoft.com/Forums/en-US/itprovistanetworking/thread/8f3e052a-8115-4dad-8d2a-b37ee5dc347a/

Many thanks again to all who gave helpful input into this thread, and I hope somebody is helped by this info!
BadBigBen (MIS)
22 Jun 11 1:47
Thanks for the follow up... and for posting the fix...
 

Ben
"If it works don't fix it! If it doesn't use a sledgehammer..."
How to ask a question, when posting them to a professional forum.
Only ask questions with yes/no answers if you want "yes" or "no"

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close