Link to home
Start Free TrialLog in
Avatar of Pkafkas
Pkafkas

asked on

What is the difference between these 2 batch files.

I am trying to get a batch file to run at start up that will map a drive to a computer that is directly connected through an Ethernt cable to another computer (shared folder).

1).  I have manually mapped the drive in explorer.

2).  I have created a batch file and if I run the batch file by double-clicking it, the batch file successfully maps a T: drive.
      a.  
net use T: \\192.168.X.XX\ShareFolder /persistent:yes /user:username password

Open in new window


3).  This computer has some security restrtictions on it by the vendor and I was told to place the batch file in a specific folder to have the batch file run at start up.
      a.  The batch file does not successfully map the drive.
      b.  Perhaps I should put a delay (Timeout 13) for 13 seconds and try it again.

4).  I was given a batch file that other companies are using and I do not see a difference between the batch file except that a message will be displayed of it cannot find the other pc.
      a.  The other batch file is shown below :

@echo
 
set MyServer=*192.168.X.XX*
set MyShare =*\\192.168.X.XX\ShareFolder*
 
%SystemRoot%\system32\ping.exe -n 1 %MyServer% >nul
if errorlevel 1 goto NoServer
 
echo %MyServer% is availabe.
rem set the username, domain and password here
net use *T*: %MyShare% /User:*Username* *Password*  /y
goto :EOF
 
:NoServer
echo %MyServer% is not availabe yet.
Timeout 10
goto :EOF

My questions are:

1).  What are the differences between the 2 x Batch files?  
       a.  The only think that I can see is that the other batch file has  a '/y/ flag in the bet use command.
       b,  What does the '/y/ flag do in the net use command, in the other batch file?

2).  Are there any other differences between the 2 x batch files so we can map a T: Drive?

3).  Should I try a delay when my (original) batch file executes to make sure that the other services have been started.
       a.  Such as the network connectivity to the other computer?
Avatar of Bill Prew
Bill Prew

The biggest difference I see is the second script uses PING to try and make sure the share server is online, whereas the first doesn't.  But in either case, if the server is not available, no mapping will be made.

I don't think the /Y is significant on the net use when assigning a drive, I've seen it on the /delete option, but it isn't documented even for that...

How are you running it "at startup"?  If via Task Scheduler then sometimes the account can be an issue, mappings done in one account aren't visible to other accounts, like administrator, etc.


»bp
My question would be:  "Does the person logging in have permissions to map that drive?"  
If yes, my second question might be "Is the computer always connected to a network?"  

If the computer uses a wireless connection, or is waiting on DHCP information so it can join the network, the script may be running too soon in the startup process to be effective.  Have it run 30 seconds after a person logs in and see if that helps.
How are you initiating the batch file to run?
it should be done in the registry through RUN:
Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run

I don't see the /persistent:yes in the 2nd one.
I've done this sort of thing in the dim past and recall that we also *removed* the mapping up front in the script.
The first question is, does it work when you run the script manually?  If no, then your batch file has a problem.  If yes, then your startup location is wrong/has issues.
Avatar of Pkafkas

ASKER

Lee W, MVP:  My answer as stated in the description, is that when I manually run the batch file then the mapped drive successfully is created.

 Paul MacDonald / Wesley MIller: The computer is automatically logged on with a built in user account.  The vendor set that up and the vendor suggested that I place the batch file in a specific folder where other batch files are triggered at login.  

The computer only has 1 network Ethernet connection that is directly connected to another computer.  Both computers have static IP addresses and when I trigger the batch file then the drive gets mapped (by net us IP address...

I think perhaps I should try a delay 13 seconds when the batch file is triggered.  To ensure aother services have started as well.   
ASKER CERTIFIED SOLUTION
Avatar of Lee W, MVP
Lee W, MVP
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Pkafkas

ASKER

The vendor suggested a specific folder.  The vendor locked the computer down and it is not using any of the typical locations for startup files.  In fact if I put any new files on the C: Drive those files get deleted after a restart.

Plus I do not like telling too much about the company devices that we use; but, I cna say this teh vendor mentioned ot put the batch file in a folder on the computer's E: Drive.

The vendor stated that I should use this batch file instead; but, I do not see thatmaking a difference.  what I see might make a difference is if I put a timeout delay of 13 seconds at the top of the batch file.   What do you think?


Others covered the widely stated question and discussion.
first to address the misnomer, start up is when the user logs in versus when the system starts up.
With that out of the way. you only need to map the drive once and require that it be present at logon. This is an entry that is addedd to the registry MountPoint2.
/persistent:yes

As one of the questions asked, deals with the presence of the network at the time of the attempt. In a domain environment, you can set a GPO to require the network be present beofre a user is permitted to login.

Once the mapping exists, there is no need to run the mapping script.

if you run the net use T: in an open command window, do you get an error?
runing a batch file from the startup folder, means you see the command window popup and go away whether the mapping is successful or if it fails.

A stale session on the server might explain your attempt failing, though commonly these occur in an AD environment. though still possible.
Try the delay and see if it does.....

Otherwise You are not providing enough information for your issue to be addressed.....

You say the Vendor has locked it down, so does that mean you don't have administrative right to it?
 Can you circumvent that using using the Shift Restart to go into PE CMD mode?


It's up to you how important it is to resolve this.  If you provide sufficient information, we can assist you.  If you want to be circumspect, then your answers will be generic at best and not likely to resolve the issue.  There's something to be said for security, but security is a balance of ease of use (shared information) and protections (secured information).  If you don't understand what is significant and what isn't, then you protect everything and you may not get a (timely?) answer.
Going back to your original question, can you expand on this:

3).  This computer has some security restrictions on it by the vendor and I was told to place the batch file in a specific folder to have the batch file run at start up.
      a.  The batch file does not successfully map the drive.

Does the BAT script actually run?  If so does it display some sort of error?

If you are not sure, you could try adding a PAUSE statement to the end of the BAT script, so that it stays open after it completes, and you might be able to view it's window and see any errors.  But I don't know how it's being executed, so the window may or may not be hidden when it runs.

Another approach would be to add some logging into the BAT script, at least for testing.  Then after a restart check the log file for any errors.  Something like this, which will add to a log file in the same folder as the BAT script, just changing the extension to LOG.  So if the script is located at:

C:\Temp\EE29188995.bat

then the log file will be:

C:\Temp\EE29188995.log

@echo off
setlocal

rem Direct log file to same folder and base name as script, just using LOG as the extension
set LogFile=%~dpn0.log

rem Log starting time of this execution of script
echo ============================================================>>"%LogFile%" 2>&1
echo %DATE% %TIME%>>"%LogFile%" 2>&1
echo ============================================================>>"%LogFile%" 2>&1

rem Display drive mappings before
echo.>>"%LogFile%" 2>&1
echo ***** BEFORE *****>>"%LogFile%" 2>&1
net use>>"%LogFile%" 2>&1

rem Perform mapping
echo.>>"%LogFile%" 2>&1
echo ***** MAPPING *****>>"%LogFile%" 2>&1
net use T: \\192.168.X.XX\ShareFolder /persistent:yes /user:username password>>"%LogFile%" 2>&1

rem Display drive mappings before
echo.>>"%LogFile%" 2>&1
echo ***** AFTER *****>>"%LogFile%" 2>&1
net use>>"%LogFile%" 2>&1

Open in new window

Sample log file in testing here:

============================================================
Tue 07/21/2020  8:29:28.21
============================================================

***** BEFORE *****
New connections will be remembered.


Status       Local     Remote                    Network

-------------------------------------------------------------------------------
OK           M:        \\ds\music                Microsoft Windows Network
OK           S:        \\ds\shared               Microsoft Windows Network
OK           V:        \\ds\video                Microsoft Windows Network
The command completed successfully.


***** MAPPING *****
System error 58 has occurred.

The specified server cannot perform the requested operation.


***** AFTER *****
New connections will be remembered.


Status       Local     Remote                    Network

-------------------------------------------------------------------------------
OK           M:        \\ds\music                Microsoft Windows Network
OK           S:        \\ds\shared               Microsoft Windows Network
OK           V:        \\ds\video                Microsoft Windows Network
The command completed successfully.

Open in new window


»bp
Avatar of Pkafkas

ASKER

Thanks, I will try the delay when I have a chance.  I did get out of this discussion what I wanted:

1).  There is no difference from the 2 x Batch files.
2).  A delay time out feature may work and is worth a try.

I will have to schedule a time to attempt the timeout feature at a later time.  I have already inconvenience the user a few times and must plan the next window accordingly.
Avatar of Pkafkas

ASKER

Thank you for your thoughts.  I Shared the information that I felt comfortable with while getting the answers I was looking for.
Depending on the user and the issue, delaying the login after bootup, resumption from sleep/hibernation could resolve the issue
Have the user look at the network indicator before attempting to login.
Globe, bad, network status, good.
I Know you closed  this, but thought another possible way you might get the batch file to run after the automated account logs in you could use a envelope batch file to launch the other batch file
Example Create a Initiate.bat containing:
@echo off
Rem Iniate batch file located on E Drive, Path is where it is located, start is batch name
call "e:path\start"