Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

batch command won't run at startup - reconnect network drive 3

Status
Not open for further replies.

bpwiz

IS-IT--Management
Feb 12, 2010
10
US
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!
 
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?
 
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!
 
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.
 
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.."
 
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.
 
Very helpful suggestions, all. I will have to wait until midafternoon my time to test this again. I will report back with my findings!
 
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.
 
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.

 
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

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"
 
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.
 
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.
 
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

Many thanks again to all who gave helpful input into this thread, and I hope somebody is helped by this info!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top