1.

Solve : IF THEN statement in a Batch file?

Answer»

So I am looking for some help. I need to do an IF THEN in a batch file. I currently have the below script removing some printers and installing others. But I would like to add an IF THEN so that if the new printer is installed, the bat file ends.

Any ideas?

Quote

@echo off
REM Date: 01/29/2009
REM Created By: John Wilganowski
REM Comments:
REM
REM The EXAMPLE removes
REM the calpine MACHINE that was
REM connected to hou-02svr and
REM connect the calpine on hou-17svr.
REM It uses the PRNMNGR.vbs that comes with windows
REM It will use the local copy of PRNMGR.vbs

REM EXAMPLE BELOW:

REM Cscript %windir%\system32\Prnmngr.vbs -d -p "\\hou-02svr\HOU-CalPine-PCL"
REM Cscript %windir%\system32\prnmngr.vbs -ac -p "\\hou-17svr\HOU-Calpine-PS"
REM exit




Cscript %windir%\system32\Prnmngr.vbs -d -p "\\hou-02svr\HOU-WhiteHouse-PCL"
Cscript %windir%\system32\Prnmngr.vbs -d -p "\\hou-02svr\HOU-WhiteHouse-PS"
Cscript %windir%\system32\prnmngr.vbs -ac -p "\\hou-02svr\HOU-Parthenon"

Cscript %windir%\system32\Prnmngr.vbs -d -p "\\hou-02svr\HOU-Pentagon-PCL"
Cscript %windir%\system32\Prnmngr.vbs -d -p "\\hou-02svr\HOU-Pentagon-PS"
Cscript %windir%\system32\prnmngr.vbs -ac -p "\\hou-02svr\HOU-Menil"
exit
Could you explain a bit more clearly what you want?

That isn't really a batch file, it's more a LIST of CALLS to the prnmngr VBS script.

Did you mean "if the new printer is already installed"? Please explain what you're doing and why and what you want to do and why.

He wants to have an IF statement that goes off when a new printer is added..

This doesn't seem possible unless you try printing a test page in a FOR loop and use ERRORLEVEL to indicate that the file couldn't be printed, thus saying that no new printer was installed, this would only work if he didn't already have a printer connected.See Comments in Red


Quote
@echo off
REM Date: 01/29/2009
REM Created By: John Wilganowski
REM Comments:
REM
REM The Example removes
REM the calpine machine that was
REM connected to hou-02svr and
REM connect the calpine on hou-17svr.
REM It uses the PRNMNGR.vbs that comes with windows
REM It will use the local copy of PRNMGR.vbs

REM EXAMPLE BELOW:

REM Cscript %windir%\system32\Prnmngr.vbs -d -p "\\hou-02svr\HOU-CalPine-PCL"
REM Cscript %windir%\system32\prnmngr.vbs -ac -p "\\hou-17svr\HOU-Calpine-PS"
REM exit



IF \\HOU-02SVR\HOU-Parthenon EXISIT
THEN GOTO STOP
ELSE



Cscript %windir%\system32\Prnmngr.vbs -d -p "\\hou-02svr\HOU-WhiteHouse-PCL"
Cscript %windir%\system32\Prnmngr.vbs -d -p "\\hou-02svr\HOU-WhiteHouse-PS"
Cscript %windir%\system32\prnmngr.vbs -ac -p "\\hou-02svr\HOU-Parthenon"

Cscript %windir%\system32\Prnmngr.vbs -d -p "\\hou-02svr\HOU-Pentagon-PCL"
Cscript %windir%\system32\Prnmngr.vbs -d -p "\\hou-02svr\HOU-Pentagon-PS"
Cscript %windir%\system32\prnmngr.vbs -ac -p "\\hou-02svr\HOU-Menil"
exit



:STOP
EXIT

Quote from: Woogi on April 14, 2009, 03:52:33 PM
See Comments in Red


Wrong syntax. IF EXIST \\HOU-02SVR\HOU-Parthenon GOTO STOP

That's PROBABLY why...Quote from: Helpmeh on April 14, 2009, 04:45:56 PM
Wrong syntax. IF EXIST \\HOU-02SVR\HOU-Parthenon GOTO STOP

That's probably why...

Well I am not saying that would even work, but that is the just what I am trying to do. I am trying to have the batch file check to see if a network printer is already installed, and if it is, quit the script, but if it isn't, then continue.Quote from: Woogi on April 14, 2009, 08:03:57 PM
Well I am not saying that would even work, but that is the just what I am trying to do. I am trying to have the batch file check to see if a network printer is already installed, and if it is, quit the script, but if it isn't, then continue.
Well, I just glanced over it, and that's what I saw.Woogi, you could use a vbs to enumerate the printers on a particular server and do something based on whether or not the printer you are asking about is in the list.

Quote from: Dias de verano on April 15, 2009, 12:16:06 AM
Woogi, you could use a vbs to enumerate the printers on a particular server and do something based on whether or not the printer you are asking about is in the list.



Yeah not that good with VBQuote from: Woogi on April 15, 2009, 07:40:03 AM
Yeah not that good with VB

But you are running admin scripts?

Quote from: Dias de verano on April 15, 2009, 10:12:35 AM
But you are running admin scripts?



And how do the two correlate?Code: [Select]cscript//nologo prnmngr.vbs -l | find/i "\\hou-02svr\HOU-Menil" || (
Cscript %windir%\system32\prnmngr.vbs -ac -p "\\hou-02svr\HOU-Menil"
)untested

however code will run faster in full vbscript.Quote from: Woogi on April 17, 2009, 07:49:21 AM
And how do the two correlate?

You are like a person paid as a truck driver who does not know how to operate the gears or clutch.Quote from: Dias de verano on April 17, 2009, 09:26:49 AM
You are like a person paid as a truck driver who does not know how to operate the gears or clutch.

No, I am like a truck driver who cant build a transmission. Ons inability to do one, does not prevent him from doing the other.Quote from: Reno on April 17, 2009, 09:19:20 AM
Code: [Select]cscript//nologo prnmngr.vbs -l | find/i "\\hou-02svr\HOU-Menil" || (
Cscript %windir%\system32\prnmngr.vbs -ac -p "\\hou-02svr\HOU-Menil"
)untested

however code will run faster in full vbscript.

Thank you for your help, I will try this out.


Discussion

No Comment Found