Solved

Batch Files: Running variables after an .exe

Posted on 2004-08-18
21
2,875 Views
Last Modified: 2008-01-09
I am trying to run a batch file that will install the client piece of software.  However, it hangs when I try to run th exe because of variables that are behind it.  It is does not matter if you are not familiar with the software in the REMark below.  Here is what I have so far:

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
@ECHO off
 
REM Silent Install for Password Policy Enforcer client. 08-18-04
REM http://www.anixis.com/products/ppe/default.htm

net use B: /d
 
IF %OS% == Windows_NT GOTO WINXP

IF NOT %OS% == Windows_NT WIN98
 
:WINXP

IF EXIST %system%\system32\PPEc32.dll GOTO END
IF NOT EXIST %system%\system32\PPEc32.dll GOTO STARTXP

:STARTXP
 
net use B: /d
net use B: \\servername\share
CD\
CD B:
CD B:\PPE
COPY PPEc32.dll %system%\system32

ClntIns.exe install ppeclnt.cfg /q
 
net use B: /d GOTO END

:WIN98

IF EXIST %system%\system32\PPEc9x.dll GOTO END
IF NOT EXIST %system%\system32\PPEc9x.dll GOTO START98

:START98

net use B: /d
net use B: \\servername\share
CD\
CD B:
CD PPE
COPY PPEc9x.dll %system%\system32
ClntIns.exe install ppeclnt.cfg /q

net use B: /d GOTO END

 
:END

net use B: /d
 
EXIT
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Here is the output:

The network connection could not be found.

More help is available by typing NET HELPMSG 2250.

The network connection could not be found.

More help is available by typing NET HELPMSG 2250.

The command completed successfully.

B:\
The system cannot find the file specified.
'ClntIns.exe' is not recognized as an internal or external command,
operable program or batch file.
A command was used with conflicting switches.

More help is available by typing NET HELPMSG 3510.

B: was deleted successfully.

The command completed successfully.

B:\
The system cannot find the file specified.
'ClntIns.exe' is not recognized as an internal or external command,
operable program or batch file.
A command was used with conflicting switches.

More help is available by typing NET HELPMSG 3510.

Press any key to continue . . .
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Here is the part that concearns me: It hangs at "ClntIns.exe install ppeclnt.cfg /q".  The error message I get is "'ClntIns.exe' is not recognized as an internal or external command, operable program or batch file.  A command was used with conflicting switches.  The program runs fun manually with those switches.  It appears that DOS does not like them.   Is there anyway around this?  Thanks.
0
Comment
Question by:mb2010
  • 8
  • 6
  • 3
  • +2
21 Comments
 

Author Comment

by:mb2010
ID: 11836645
The program runs fun manually with those switches. = The program runs fine manually with those switches.
0
 
LVL 11

Expert Comment

by:Eric
ID: 11838118
cd b:
 
b: is a drive not a directory correct?

i think you want
b:
cd\
to change prompt from  c:\blahblah\  to   b:\

try turning @echo on in the beggining
so you can see more details
alsue insert alot of pauses to see exactly what command is chokeing
0
 
LVL 11

Expert Comment

by:Eric
ID: 11838126
lol
i just tried cd b:
=======
C:\Documents and Settings\Eric>cd ..

C:\Documents and Settings>cd d:
D:\

C:\Documents and Settings>cd f:
F:\

C:\Documents and Settings>

===========

is it me or is that weird?  it says d:\ but does not actually do anything :|
0
 
LVL 18

Expert Comment

by:crissand
ID: 11841959
CD B:
CD PPE

change it to

b:
cd \ppe

if ppe is in the root of b:, otherwise give the absolute path to the cd command.

cd \path\ppe
0
 
LVL 15

Expert Comment

by:adamdrayer
ID: 11842661
IF NOT %OS% == Windows_NT WIN98

should be

IF NOT %OS% == Windows_NT GOTO WIN98

right?
0
 
LVL 15

Expert Comment

by:adamdrayer
ID: 11842689
net use B: /d GOTO END

should be

net use B: /d
GOTO END
0
 
LVL 15

Expert Comment

by:adamdrayer
ID: 11842718
also, be careful when you use the word "hangs".  This program is not hanging, it is failing.  hanging is when you lose control over the system input because the CPU is caught in some kinda loop
0
 
LVL 11

Expert Comment

by:Eric
ID: 11842867
ok good crissand agrees with that cd B: issue.. im not crazy
because I tested it and it does not work.

0
 
LVL 18

Expert Comment

by:crissand
ID: 11843055
Sometimes the os does'n't allow you to use the B: letter, since it is a legacy from the times when computers use to have two floppy drives. The drive change can also fail if the network mapping is not working.
0
 
LVL 83

Accepted Solution

by:
oBdA earned 250 total points
ID: 11846226
There are several errors in your batch.
One of the net use B: /d commands will be enough; that's what causes the two "The network connection could not be found." errors; you're deleting the drive at the very beginning and then again right before mapping it.
This will fail in Win9x, because the %OS% variable isn't defined, and because you missed the "goto" in the Win98 line:
> IF %OS% == Windows_NT GOTO WINXP
> IF NOT %OS% == Windows_NT WIN98
You need quotation marks around the %OS% and Windows_NT.
The target paths are completely wrong; in Win9x, it's %WinDir%\system, in NT it's %Systemroot%\system32:
> IF EXIST %system%\system32\PPEc32.dll GOTO END
This command is not necessary, neither is the label; if the file exists, the former command will already have jumped out.
> IF NOT EXIST %system%\system32\PPEc32.dll GOTO STARTXP
> :STARTXP

As stated before, the path change is incorrect, this needs to be "B:" followed by "cd \PPE":
> CD B:
> CD B:\PPE
The target path is wrong again:
> COPY PPEc32.dll %system%\system32
And this command fails, because you're not on the B: drive:
> ClntIns.exe install ppeclnt.cfg /q
As stated before, this needs to be separated into two lines. Because it isn't, the script will just continue with the Win9x part (that's the "A command was used with conflicting switches." error):
> net use B: /d GOTO END
> :WIN98

As before, the target path is incorrect, and the second line as well as the label are not necessary:
> IF EXIST %system%\system32\PPEc9x.dll GOTO END
> IF NOT EXIST %system%\system32\PPEc9x.dll GOTO START98
> :START98
As before, incorrect directory change:
> CD\
> CD B:
> CD PPE
And the incorrect target path again:
> COPY PPEc9x.dll %system%\system32
The failing command again, because you're not on the B: drive:
> ClntIns.exe install ppeclnt.cfg /q
And the missin gline break:
> net use B: /d GOTO END
And another unnecessary network drive removal:
> net use B: /d


Try this instead; it's currently in test mode, so it will only display the commands it would otherwise run. To run it for real, remove the "ECHO"s and the "PAUSE" command where indicated.

@echo off
REM Silent Install for Password Policy Enforcer client. 08-19-04
REM http://www.anixis.com/products/ppe/default.htm

REM *** Set the defaults for Win9x:
set TargetPath=%WinDir%\System
set PPEDLL=PPEc9x.dll
REM *** If it's NT, change the settings accordingly:
if "%OS%"=="Windows_NT" set TargetPath=%Systemroot%\system32
if "%OS%"=="Windows_NT" set PPEDLL=PPEc32.dll

REM *** Leave if the dll already exists:
if exist "%TargetPath%\%PPEDLL%" goto leave

REM *** Installation necessary; map the network drive and start the install:
net use B: /d
net use B: \\Server\Share
if errorlevel 1 goto err_Mapping
B:
cd \PPE
REM *** Test mode: Remove the "ECHO" in front of the following line to run the script for real:
ECHO copy %PPEDLL% "%TargetPath%\%PPEDLL%"
ECHO ClntIns.exe INSTALL ppeclnt.cfg /q
REM *** Test mode: Remove the "PAUSE" line to continue automatically after the installation:
PAUSE
net use P: /d
goto leave

:err_Mapping
echo Error mapping network drive.
pause

:leave
0
Network it in WD Red

There's an industry-leading WD Red drive for every compatible NAS system to help fulfill your data storage needs. With drives up to 8TB, WD Red offers a wide array of solutions for customers looking to build the biggest, best-performing NAS storage solution.  

 

Author Comment

by:mb2010
ID: 11847150
Wow!  Thanks for all the replies.  

The script seems to run much better, but for some reason it does not want to copy the file over from the network share.  It appears like it copies it over.  There are no errors except the initial "network connection could not be found" when there is no B: drive to delete before mapping the B: drive.  When I check the C:\Windows\System32 directory on my WinXP test machine, there is no PPEc32.dll file in there.  I did a search of the entire C: drive with "show hidden files" option checked and could not find it anywhere.  Here is what I have:

@echo off
REM Silent Install for Password Policy Enforcer client. 08-19-04
REM http://www.anixis.com/products/ppe/default.htm

REM *** Set the defaults for Win9x:
if not "%OS%"=="Windows_NT" set TargetPath=%WinDir%\System
if not "%OS%"=="Windows_NT" set PPEDLL=PPEc9x.dll

REM *** If it's NT, change the settings accordingly:
if "%OS%"=="Windows_NT" set TargetPath=%Systemroot%\system32
if "%OS%"=="Windows_NT" set PPEDLL=PPEc32.dll

REM *** Leave if the dll already exists:
if exist "%TargetPath%\%PPEDLL%" goto leave

REM *** Installation necessary; map the network drive and start the install:
net use B: /d
net use B: \\servername\Share
if errorlevel 1 goto err_Mapping
cd\
B:
cd B:\PPE
REM *** Test mode: Remove the "ECHO" in front of the following line to run the script for real:
ECHO copy %PPEDLL% "%TargetPath%\%PPEDLL%"
ECHO ClntIns.exe INSTALL ppeclnt.cfg /q
REM *** Test mode: Remove the "PAUSE" line to continue automatically after the installation:
PAUSE
C:
net use B: /d
goto leave

:err_Mapping
echo Error mapping network drive.
pause

:leave
0
 
LVL 15

Expert Comment

by:adamdrayer
ID: 11847230
cd B:\PPE


should be

cd \PPE

don't specify drives in "cd" commands
0
 

Author Comment

by:mb2010
ID: 11847288
OKay.  I changed that, but still have the same symptoms.
0
 
LVL 15

Expert Comment

by:adamdrayer
ID: 11847318
what does the echo show on the command line during the copy?
0
 
LVL 15

Expert Comment

by:adamdrayer
ID: 11847336
oh wait, you're only testing for NT, you have no if statements for 9x
0
 
LVL 15

Expert Comment

by:adamdrayer
ID: 11847372
sorry, i didn't see the "not"s in there.  nevermind
0
 
LVL 15

Assisted Solution

by:adamdrayer
adamdrayer earned 150 total points
ID: 11847517
take the ECHOs out before the "copy" and install lines.  Echo only writes to the screen, it will not process the command.
0
 

Author Comment

by:mb2010
ID: 11847642
Here is the output before the PAUSE:

C:\temp>caah01ppe
The network connection could not be found.

More help is available by typing NET HELPMSG 2250.

The command completed successfully.

copy PPEc32.dll "C:\WINDOWS\system32\PPEc32.dll"
ClntIns.exe INSTALL ppeclnt.cfg /q
Press any key to continue . . .

After pressing enter:

B: was deleted successfully.

C:\>
0
 
LVL 18

Expert Comment

by:crissand
ID: 11847854
take out the echo's!
0
 

Author Comment

by:mb2010
ID: 11847873
That did the trick on the local machine.  I'll be out of the office on Friday, returning Monday.  I'll post again when I am back in and after I have tested everything fully from the server group policy.  I may have to split some points for at least two of you since you all have been so helpful.  :-)
Thanks again.
0
 

Author Comment

by:mb2010
ID: 11903858
Works like a charm!  Thanks for all the awesome input.
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Join & Write a Comment

Sometimes you might need to configure routing based not only on destination IP address, but also on a combination of destination IP address (or hostname) and destination port number. I will describe a method how to accomplish this with free tools. …
Have you ever set up your wireless router at home or in the office to find that you little pop-up bubble in the bottom right-hand corner of Windows read "IP Conflict - One of more computers on the network have been assigned the following IP address"…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now