Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: IF THEN statement in a Batch file  (Read 8247 times)

0 Members and 1 Guest are viewing this topic.

Woogi

    Topic Starter


    Rookie

    IF THEN statement in a Batch file
    « on: April 14, 2009, 03:30:42 PM »
    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

    Dias de verano

    • Guest
    Re: IF THEN statement in a Batch file
    « Reply #1 on: April 14, 2009, 03:43:19 PM »
    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.


    macdad-



      Expert

      Thanked: 40
      Re: IF THEN statement in a Batch file
      « Reply #2 on: April 14, 2009, 03:50:06 PM »
      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.
      If you dont know DOS, you dont know Windows...

      Thats why Bill Gates created the Windows NT Family.

      Woogi

        Topic Starter


        Rookie

        Re: IF THEN statement in a Batch file
        « Reply #3 on: April 14, 2009, 03:52:33 PM »
        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


        Helpmeh



          Guru

        • Roar.
        • Thanked: 123
          • Yes
          • Yes
        • Computer: Specs
        • Experience: Familiar
        • OS: Windows 8
        Re: IF THEN statement in a Batch file
        « Reply #4 on: April 14, 2009, 04:45:56 PM »
        See Comments in Red


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

        That's probably why...
        Where's MagicSpeed?
        Quote from: 'matt'
        He's playing a game called IRL. Great graphics, *censored* gameplay.

        Woogi

          Topic Starter


          Rookie

          Re: IF THEN statement in a Batch file
          « Reply #5 on: April 14, 2009, 08:03:57 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.

          Helpmeh



            Guru

          • Roar.
          • Thanked: 123
            • Yes
            • Yes
          • Computer: Specs
          • Experience: Familiar
          • OS: Windows 8
          Re: IF THEN statement in a Batch file
          « Reply #6 on: April 14, 2009, 08:05:58 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.
          Where's MagicSpeed?
          Quote from: 'matt'
          He's playing a game called IRL. Great graphics, *censored* gameplay.

          Dias de verano

          • Guest
          Re: IF THEN statement in a Batch file
          « Reply #7 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.


          Woogi

            Topic Starter


            Rookie

            Re: IF THEN statement in a Batch file
            « Reply #8 on: April 15, 2009, 07:40:03 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 VB

            Dias de verano

            • Guest
            Re: IF THEN statement in a Batch file
            « Reply #9 on: April 15, 2009, 10:12:35 AM »
            Yeah not that good with VB

            But you are running admin scripts?


            Woogi

              Topic Starter


              Rookie

              Re: IF THEN statement in a Batch file
              « Reply #10 on: April 17, 2009, 07:49:21 AM »
              But you are running admin scripts?



              And how do the two correlate?

              Reno



                Hopeful
              • Thanked: 32
                Re: IF THEN statement in a Batch file
                « Reply #11 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.

                Dias de verano

                • Guest
                Re: IF THEN statement in a Batch file
                « Reply #12 on: April 17, 2009, 09:26:49 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.

                Woogi

                  Topic Starter


                  Rookie

                  Re: IF THEN statement in a Batch file
                  « Reply #13 on: April 17, 2009, 03:14:07 PM »
                  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.

                  Woogi

                    Topic Starter


                    Rookie

                    Re: IF THEN statement in a Batch file
                    « Reply #14 on: April 17, 2009, 03:14:43 PM »
                    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.