Announcement

Collapse
No announcement yet.

batch (for do if exist found set) and error on driveletter

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • batch (for do if exist found set) and error on driveletter

    when I run this batch file I get problems with the D: drive, this is an occasional cardreaderdrive on some workstations:

    Code:
    @ECHO OFF
    SETLOCAL ENABLEEXTENSIONS
    REM SETLOCAL ENABLEDELAYEDEXPANSION
    
    CALL SET "lksvdd=\\dc01.lksvdd.local"
    
    :: Log.Management
    IF EXIST "%systemRoot%\LOGS\LKSVDD\Tim" (CALL SET "LogsPath=%systemRoot%\LOGS\LKSVDD\Tim") ELSE CALL "%lksvdd%\netlogon\Log_management.cmd" >nul 2>&1 && CALL SET "LogsPath=%systemRoot%\LOGS\LKSVDD\Tim" >nul 2>&1
    
    :: Run_Once
    IF NOT EXIST "%LogsPath%\local_arkey_check.txt" (GOTO:Kill_Local_Arkey) ELSE GOTO:EOF
    GOTO:EXIT
    
    
    :Kill_Local_Arkey
    rem *CHECK*
    ECHO ***%DATE% %TIME%: START Search For Local Arkey @ %ComputerName% (%UserName%) >> "%lksvdd%\netlogon\Fix\Local_Arkey_Check\local_arkey_check.txt"
    
    SET "FOUND="
    for %%F in (
      "%SystemDrive%\Arkey5\"
      "D:\Arkey5\"
      "%SystemDrive%\Arkey6\"
      "D:\Arkey6\"
      "%SystemDrive%\Arkey7\"
      "D:\Arkey7\"
    ) do if exist %%F (echo %UserName% @ %ComputerName% : Found %%F >> "%lksvdd%\netlogon\Fix\Local_Arkey_Check\local_arkey_check.txt" & SET "FOUND=1")
    if not defined FOUND echo %ComputerName% (%UserName%) : NOTHING FOUND >> "%lksvdd%\netlogon\Fix\Local_Arkey_Check\local_arkey_check.txt"
    
    ECHO %ComputerName% (%UserName%) @ %DATE% %TIME%: EOF TimeStamp for RunTime check [#runTimeStamp by Check-4-Local_Arkey.cmd] >> "%lksvdd%\netlogon\Fix\Local_Arkey_Check\local_arkey_check.txt"
    
    GOTO:EXIT
    
    
    :EXIT
    ECHO ECHO #runTimeStamp -4- "Check-4-Local_Arkey.cmd" [%DATE% %TIME%] EOF > "%LogsPath%\local_arkey_check.txt" 2>&1
    rem echo.
    REM ECHO.Script date: 25-07-2013
    rem echo.
    REM PAUSE
    ENDLOCAL
    GOTO:EOF
    -> %systemdrive% goes well, the D: drive gives this next error on some workstations: there's no disk in this station...etc...
    What is the best way to surpress/workaround this? On most workstations there actually is a D: partition and needs to get checked, on some new workstations there's an occasional cardreader, if so no check is needed because the path to search for would never be on it.

  • #2
    Re: batch (for do if exist found set) and error on driveletter

    Maybe you can try something like this,
    Code:
    goto :begin of batch
    
    --- Sub Routines: ------------------------
    
    :DriveType
    for /f "Skip=2 tokens=*" %%* in (
       'wmic.exe logicaldisk where "DeviceID='%*'" get DriveType /format:value') do (
        Call SET %%* & exit /b 0
        ) > Nul 
    exit /b 1
    
    
    --- end of Routines: ---------------------
    
    
    :begin of batch
    @echo off & cls
    
    call:DriveType D:
    
    If not defined DriveType goto :EOF
    If %DriveType% NEQ 3 goto :EOF
    
    echo.    D: is a Local Disk
    
    pause
    /Rems

    This posting is provided "AS IS" with no warranties, and confers no rights.

    __________________

    ** Remember to give credit where credit's due **
    and leave Reputation Points for meaningful posts

    Comment


    • #3
      Re: batch (for do if exist found set) and error on driveletter

      You can test for the existence of "D:\nul".

      The test will fail if D: is a removable drive with no media, of if no such drive letter exists. The test will not result in an error message in either case.

      Comment


      • #4
        Re: batch (for do if exist found set) and error on driveletter

        @rems

        tried your example script but nothing happens?

        Comment


        • #5
          Re: batch (for do if exist found set) and error on driveletter

          The script in my previous post shows only results if the drive [D:] is actually a fixed disk, if it is not a fixed disk the script ends without showing results.

          The test script below shows results no matter what disk type it is,

          Code:
          goto :begin of batch
          
          --- Sub Routines: ------------------------
          
          :DriveType
          for /f "Skip=2 tokens=*" %%* in (
             'wmic.exe logicaldisk where "DeviceID='%*'" get DriveType /format:value') do (
              Call SET %%* & exit /b 0
              )
          exit /b 1
          
          
          --- end of Routines: ---------------------
          
          
          :begin of batch
          @echo off & cls
          
          call:DriveType D:
          
          SET DriveType
          echo.   0 = Unknown
          echo.   1 = No Root Directory
          echo.   2 = Removable Disk
          echo.   3 = Local Disk
          echo.   4 = Network Drive
          echo.   5 = Compact Disc
          echo.   6 = RAM Disk
          
          
          pause
          The OS should be Windows 7
          (although 'wmic.exe' is present also on Windows XP, there it can only be executed by users that have local admin privileges)

          Do you see any error messages when running the test script?

          /Rems

          This posting is provided "AS IS" with no warranties, and confers no rights.

          __________________

          ** Remember to give credit where credit's due **
          and leave Reputation Points for meaningful posts

          Comment


          • #6
            Re: batch (for do if exist found set) and error on driveletter

            crap, stupid me, now I see...
            your second script does say it's a "removable disk" on a test workstation

            THANK YOU VERY MUCH

            Comment


            • #7
              Re: batch (for do if exist found set) and error on driveletter

              is this the correct position to add the "if not defined..." & "if NEQ 3..." lines?
              -> before the "SET DriveType" line I presumed
              Code:
              CALL:DriveType D:
              
              if NOT defined DriveType GOTO:ERROR
              IF %DriveType% NEQ 3     GOTO:FAiL
              
              SET DriveType
              echo.   0 = Unknown
              echo.   1 = No Root Directory
              echo.   2 = Removable Disk
              echo.   3 = Local Disk
              echo.   4 = Network Drive
              echo.   5 = Compact Disc
              echo.   6 = RAM Disk

              Comment


              • #8
                Re: batch (for do if exist found set) and error on driveletter

                Originally posted by APOC View Post
                -> before the "SET DriveType" line I presumed
                The line SET DriveType doesn't do anything more than just expanding the value of the earlier in the script defined variable %DriveType% (echoing it in a typical way).
                If you like to keep the above line and the next lines starting with echo. ... in your script, then I would place the command IF %DriveType% NEQ 3 GOTO:FAiL after these lines.

                /Rems

                This posting is provided "AS IS" with no warranties, and confers no rights.

                __________________

                ** Remember to give credit where credit's due **
                and leave Reputation Points for meaningful posts

                Comment


                • #9
                  Re: batch (for do if exist found set) and error on driveletter

                  I do get a lot of these messages when running your script, weird thing is that it doesn't seem to happen on all workstations:
                  No Instance(s) Available.

                  Comment

                  Working...
                  X