[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2931
  • Last Modified:

Batch Files: Running variables after an .exe

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
mb2010
Asked:
mb2010
  • 8
  • 6
  • 3
  • +2
2 Solutions
 
mb2010Author Commented:
The program runs fun manually with those switches. = The program runs fine manually with those switches.
0
 
EricIT ManagerCommented:
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
 
EricIT ManagerCommented:
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
crissandCommented:
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
 
adamdrayerCommented:
IF NOT %OS% == Windows_NT WIN98

should be

IF NOT %OS% == Windows_NT GOTO WIN98

right?
0
 
adamdrayerCommented:
net use B: /d GOTO END

should be

net use B: /d
GOTO END
0
 
adamdrayerCommented:
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
 
EricIT ManagerCommented:
ok good crissand agrees with that cd B: issue.. im not crazy
because I tested it and it does not work.

0
 
crissandCommented:
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
 
oBdACommented:
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
 
mb2010Author Commented:
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
 
adamdrayerCommented:
cd B:\PPE


should be

cd \PPE

don't specify drives in "cd" commands
0
 
mb2010Author Commented:
OKay.  I changed that, but still have the same symptoms.
0
 
adamdrayerCommented:
what does the echo show on the command line during the copy?
0
 
adamdrayerCommented:
oh wait, you're only testing for NT, you have no if statements for 9x
0
 
adamdrayerCommented:
sorry, i didn't see the "not"s in there.  nevermind
0
 
adamdrayerCommented:
take the ECHOs out before the "copy" and install lines.  Echo only writes to the screen, it will not process the command.
0
 
mb2010Author Commented:
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
 
crissandCommented:
take out the echo's!
0
 
mb2010Author Commented:
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
 
mb2010Author Commented:
Works like a charm!  Thanks for all the awesome input.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 8
  • 6
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now