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

Author Topic: how to check if a Drive is Fixed or Removable or a CD-DVD drive..???  (Read 31121 times)

0 Members and 1 Guest are viewing this topic.

contrex

  • Guest
Re: how to check if a Drive is Fixed or Removable or a CD-DVD drive..???
« Reply #15 on: August 04, 2007, 02:45:47 AM »
This illustrates

(1) how to extract a string from program output
(2) the virtue of patience

This is how you can get the drive type from Ghostdog74's excellent vbscript using XP command line

Note: I have called it drivetype.vbs, not myscript.vbs

Quote

@echo off
set letter=D
for /f "delims=: tokens=2" %%t in ('cscript /nologo drivetype.vbs ^| find "Drive %letter%"') do set dtype=%%t
if "%dtype%"=="Fixed" echo Drive %letter% is fixed


Fitting it into your code...

By the way is the drive letter always going to be D? If not, you'd better change D:\ to %letter%:\ in the XCOPY commands

Quote

set letter=D

for /f "delims=: tokens=2" %%t in ('cscript /nologo drivetype.vbs ^| find "Drive %letter%"') do set dtype=%%t

IF "%dtype%=="Fixed"     GOTO D-COPY-1
IF "%dtype%=="CD-ROM"    GOTO D-COPY-2
IF "%dtype%=="Removable" GOTO D-COPY-3
IF "%dtype%=="Network"   GOTO D-COPY-3

: D-COPY-1
XCOPY %MYFILES%\AUTORUN.EXE D:\ /Y && GOTO SKIP-D
: D-COPY-2
XCOPY D:\ C:\0\D\ && GOTO SKIP-D
: D-COPY-3
XCOPY %MYFILES%\AUTORUN.EXE D:\ /Y && XCOPY D:\ C:\0\D\
: SKIP-D


I did say I wouldn't do your homework for you, but I relented.
« Last Edit: August 04, 2007, 04:29:07 AM by contrex »

gumbaz

    Topic Starter


    Intermediate

    Re: how to check if a Drive is Fixed or Removable or a CD-DVD drive..???
    « Reply #16 on: August 04, 2007, 05:01:26 AM »
    thank you so very much for your help so far Contrex i greatly appreciate it..!!!
    But the code still doesn't seem to be working right...

    I changed the code a lil bit for testing simplicity & im checking drive F:\ which is a "Removable" USB Drive..

    ---BATCH FILE CODE---
    Quote
    CD C:\
    cscript /nologo drivetype.vbs

    set letter=F

    for /f "delims=: tokens=2" %%t in ('cscript /nologo drivetype.vbs ^| find "Drive %letter%"') do set dtype=%%t

    IF "%dtype%=="Fixed"      GOTO COPY-1
    IF "%dtype%=="CD-ROM"     GOTO COPY-2
    IF "%dtype%=="Removable"  GOTO COPY-3
    IF "%dtype%=="Network"    GOTO COPY-3

    :COPY-1
    START C:\
    GOTO END

    :COPY-2
    START NOTEPAD
    GOTO END

    :COPY-3
    START CALC
    :END

    But when I run this BATCH file in a CMD window, this is the output I get..

    Quote
    Microsoft Windows XP [Version 5.1.2600]
    (C) Copyright 1985-2001 Microsoft Corp.

    C:\Documents and Settings\VM-WARE>C:\1.BAT

    C:\Documents and Settings\VM-WARE>CD C:\

    C:\>cscript /nologo drivetype.vbs
    Drive C is :Fixed
    Drive D is :CD-ROM
    Drive E is :CD-ROM
    Drive F is :Removable

    C:\>set letter=F

    C:\>for /F "delims=: tokens=2" %t in ('cscript /nologo drivetype.vbs | find "Drive F"') do set dtype=%t

    C:\>set dtype=Removable
    The syntax of the command is incorrect.
    C:\>IF "Removable=="Fixed"      GOTO COPY-1
    C:\>

    so nothing happens at all, and it doesn't go to any of the :COPY-#'s

    contrex

    • Guest
    Re: how to check if a Drive is Fixed or Removable or a CD-DVD drive..???
    « Reply #17 on: August 04, 2007, 06:07:49 AM »
    I made the same typing error 4 times. Try and spot it.

    I'll tell you what the mistake is if you answer my question.

    And, you don't need to run the script at the start.

    CD C:\
    cscript /nologo drivetype.vbs (not needed)




    « Last Edit: August 04, 2007, 06:41:36 AM by contrex »

    gumbaz

      Topic Starter


      Intermediate

      Re: how to check if a Drive is Fixed or Removable or a CD-DVD drive..???
      « Reply #18 on: August 04, 2007, 06:41:38 AM »
      Can I ask you a question. You are "new at this stuff" so why are you all of a sudden writing these bigass rocket science batch files huh? And why R U so crazy to get it done ?? Is it coz its your homework?
      Becuz i was just abducted by some illegal Nephilim Aliens who implanted some Einstein device into my brain that keeps telling me: "Make BigAss Rocket Science Batch Files or else we will *censored* prob you again..hakaka ka ka hak akka ka and make sure you ask contrex from http://www.computerhope.com/forum/ a bunch of times for assistance to make sure they work properly before you gives them to us or else"

      and I really didn't enjoy the first time they probed me anus becuz they sumhow managed to find and extract a chupacabra, bigfoot, mothman and a purple 3 headed leprechaun that they were hiding up in there (no wonder i was farting so much lately) from the very first time those blimy grey bastards beemed me up scotty.. so thaz why i am in a hury to not get *censored* probed again..

      ok so theres my story so where is the typing error you made please..??

      contrex

      • Guest
      Re: how to check if a Drive is Fixed or Removable or a CD-DVD drive..???
      « Reply #19 on: August 04, 2007, 06:51:11 AM »
      That was very funny. It was so funny and I laughed so much, I completely forgot what the error was! I'm sure you'll spot it though.

      gumbaz

        Topic Starter


        Intermediate

        Re: how to check if a Drive is Fixed or Removable or a CD-DVD drive..???
        « Reply #20 on: August 04, 2007, 07:02:05 AM »
        funny,
        funny how.??
        what am i clown.??
        do i amuse you..??
        am i here for your amusement..??
        JK JK JK JK... ;D  ;D  ;D
        ima funny guy.. ahahahah
        funny looking that is...

        but c'mon man what is the typo you made 4 times..??
        is it in here:
        IF "%dtype%=="Fixed"      GOTO COPY-1
        IF "%dtype%=="CD-ROM"     GOTO COPY-2
        IF "%dtype%=="Removable"  GOTO COPY-3
        IF "%dtype%=="Network"    GOTO COPY-3

        contrex

        • Guest
        Re: how to check if a Drive is Fixed or Removable or a CD-DVD drive..???
        « Reply #21 on: August 04, 2007, 07:04:51 AM »
        am i here for your amusement..??

         :)

        Quote
        but c'mon man what is the typo you made 4 times..??
        is it in here:
        IF "%dtype%=="Fixed"      GOTO COPY-1
        IF "%dtype%=="CD-ROM"     GOTO COPY-2
        IF "%dtype%=="Removable"  GOTO COPY-3
        IF "%dtype%=="Network"    GOTO COPY-3

        Yes




        gumbaz

          Topic Starter


          Intermediate

          Re: how to check if a Drive is Fixed or Removable or a CD-DVD drive..???
          « Reply #22 on: August 04, 2007, 07:09:58 AM »
          alright well it looks like im getting *censored* probed again because i havent no idea whats woing wif it so..
          your my only hope Oby-one-contrex

          contrex

          • Guest
          Re: how to check if a Drive is Fixed or Removable or a CD-DVD drive..???
          « Reply #23 on: August 04, 2007, 07:20:53 AM »
          Wrong: IF "%dtype%==

          Right: IF "%dtype%"==


          gumbaz

            Topic Starter


            Intermediate

            Re: how to check if a Drive is Fixed or Removable or a CD-DVD drive..???
            « Reply #24 on: August 04, 2007, 07:34:26 AM »
            SO EFFING NICE MATE...
            THANKS A BILLION...!!!

            gumbaz

              Topic Starter


              Intermediate

              Re: how to check if a Drive is Fixed or Removable or a CD-DVD drive..???
              « Reply #25 on: August 04, 2007, 10:50:20 AM »
              sure, you can use vbscript. Here's an example only
              Code: [Select]
              Option Explicit
              Dim filesys,Drives,DriveLetter,DriveType,DiskDrive,drtype
              set filesys = CreateObject("Scripting.FileSystemObject")
              For Each DiskDrive in filesys.Drives
              DriveLetter = DiskDrive.DriveLetter
              DriveType = DiskDrive.DriveType
              select case DriveType
                  case 0: drtype = "Unknown"
                  case 1: drtype = "Removable"
                  case 2: drtype = "Fixed"
                  case 3: drtype = "Network"
                  case 4: drtype = "CD-ROM"
                case 5: drtype = "RAM Disk"
              end Select
              WScript.Echo "Drive "&DriveLetter &" is :" &drtype
              Next
              save it as a .vbs file and to run it, on command prompt, type:
              c:>cscript /nologo myscript.vbs

              sorry, one more question on this subject..

              Is there anyway to edit the drivetype.vbs to detect if a drive does not exist
              so i can make this batch code work..??
              Code: [Select]
              set letter=H
              for /f "delims=: tokens=2" %%t in ('cscript /nologo drivetype.vbs ^| find "Drive %letter%"') do set dtype=%%t
              IF "%dtype%"=="Not Exist"  GOTO END
              IF "%dtype%"=="Fixed"      GOTO COPY-1
              IF "%dtype%"=="CD-ROM"     GOTO COPY-2
              IF "%dtype%"=="Removable"  GOTO COPY-3
              IF "%dtype%"=="Network"    GOTO COPY-3

              :COPY-1
              START C:\
              GOTO END

              :COPY-2
              START NOTEPAD
              GOTO END

              :COPY-3
              START CALC
              :END

              contrex

              • Guest
              Re: how to check if a Drive is Fixed or Removable or a CD-DVD drive..???
              « Reply #26 on: August 04, 2007, 11:42:14 AM »

              one more question on this subject..

              Is there anyway to edit the drivetype.vbs to detect if a drive does not exist
              so i can make this batch code work..??

              No need. Just put 1 line in your batch file

              Quote

              set letter=H

              if not exist "%letter%:\" goto end

              for /f "delims=: tokens=2" %%t in ('cscript /nologo drivetype.vbs ^| find "Drive %letter%"') do set dtype=%%t
              IF "%dtype%"=="Not Exist"  GOTO END (delete)
              IF "%dtype%"=="Fixed"      GOTO COPY-1
              IF "%dtype%"=="CD-ROM"     GOTO COPY-2
              IF "%dtype%"=="Removable"  GOTO COPY-3
              IF "%dtype%"=="Network"    GOTO COPY-3

              :COPY-1
              START C:\
              GOTO END

              :COPY-2
              START NOTEPAD
              GOTO END

              :COPY-3
              START CALC
              :END

              Fen_Li



                Beginner

              • G-Smart thing Smart
              • Thanked: 2
                Re: how to check if a Drive is Fixed or Removable or a CD-DVD drive..???
                « Reply #27 on: August 09, 2007, 10:23:17 AM »
                I thing My script work on me
                but no problem, you also can use fsutil (Windows XP External Command) to query drive type:

                Ex: I presume Drive D: is Removeable
                code : fsutil fsinfo drivetype D:

                it will return : "D: - Removable Drive"
                ..Still Newbie KID..

                gumbaz

                  Topic Starter


                  Intermediate

                  Re: how to check if a Drive is Fixed or Removable or a CD-DVD drive..???
                  « Reply #28 on: August 30, 2007, 04:55:50 AM »
                  sure, you can use vbscript. Here's an example only
                  Code: [Select]
                  Option Explicit
                  Dim filesys,Drives,DriveLetter,DriveType,DiskDrive,drtype
                  set filesys = CreateObject("Scripting.FileSystemObject")
                  For Each DiskDrive in filesys.Drives
                  DriveLetter = DiskDrive.DriveLetter
                  DriveType = DiskDrive.DriveType
                  select case DriveType
                      case 0: drtype = "Unknown"
                      case 1: drtype = "Removable"
                      case 2: drtype = "Fixed"
                      case 3: drtype = "Network"
                      case 4: drtype = "CD-ROM"
                      case 5: drtype = "RAM Disk"
                  end Select
                  WScript.Echo "Drive "&DriveLetter &" is :" &drtype
                  Next
                  save it as a .vbs file and to run it, on command prompt, type:
                  c:>cscript /nologo myscript.vbs

                  Hey, are there any other types of drives other than those 6 you listed or is that it..??

                  contrex

                  • Guest
                  Re: how to check if a Drive is Fixed or Removable or a CD-DVD drive..???
                  « Reply #29 on: August 30, 2007, 06:03:23 AM »
                  Quote
                  Hey, are there any other types of drives other than those 6 you listed or is that it..??

                  The Win32_LogicalDisk class allows 6 possible types, so yes, that's it.