Vol/Ser# as a variable....
Results 1 to 9 of 9

Thread: Vol/Ser# as a variable....

Hybrid View

  1. #1
    Join Date
    Oct 2000
    Location
    Paterson, NJ, USA
    Posts
    968

    Vol/Ser# as a variable....

    Does anybody know how to put the disk volume label and the disk serial number into variables? For example, x=DOSDrive and y=ABC-123.

    [I need it in order to write a short script to ensure one Favorites folder for IE5 used on a multipartitioned, multi-OS HDD in a PC with a removable HD. Therefore the drive letters can change, depending on whether the removable drive is in or out.]

  2. #2
    Join Date
    Oct 1999
    Location
    Huntington Beach, CA, USA
    Posts
    3,137
    CDROM GOD version 5.5 included a file called FINDDRV.EXE. This file looks for the drive's label you specify and returns an errorlevel. You can have the batch set the variable for the drive.
    FINDDRV DOSDRIVE
    if errorlevel 3 set x=C:
    if errorlevel 4 set x=D:
    if errorlevel 5 set x=E:
    if errorlevel 6 set x=F:
    if errorlevel 7 set x=G:
    if errorlevel 8 set x=H:
    if errorlevel 9 set x=I:

    ------------------
    My

    Dennis
    Politalk

    [This message has been edited by Eeyore (edited 06-07-2001).]

  3. #3
    Join Date
    Feb 2000
    Location
    26.03°N 80.14°W
    Posts
    9,410
    Code:
    @echo off
    if (%1)==() goto Begin
    if (%1)==(?) goto Syntax
    if (%1)==(/?) goto Syntax
    if exist %1\nul goto Begin
    echo Drive "%1" does not exist
    goto End
    :Syntax
    echo Syntax: %1 [d:]
    goto End
    :Begin
    vol %1
    echo.
    vol %1|find "drive">~.bat
    echo set vsdrv=%%3>volume.bat
    echo set vsvol=%%5>>volume.bat
    call ~.bat
    vol %1|find "Serial">~.bat
    echo set vsser=%%4>volume.bat
    for %%x in (call del) do %%x ~.bat
    del volume.bat
    if (%vsvol%)==(no) set vsvol={none}
    echo vsdrv=%vsdrv%
    echo vsvol=%vsvol%
    echo vsser=%vsser%
    echo.
    set cmdline=
    :End
    I'm in a bit of a hurry this morning and don't have the time to supply in-depth detail. On my computer it's named vs.bat (Volume Serial number). You can either type:

       vs

    or:

       vs d:

    where d: is a valid drive letter.

    The environment variables that will be created are "vsdrv", "vsvol" and "vsser", (drive letter, volume label and volume serial number respectively).

    vs.bat simply gathers all of this information from the internal DOS VOL command. (Type VOL at any DOS prompt). It requires the DOS FIND.EXE utility (somewhere in the PATH) and roughly 45 free bytes of space in the environment.

    If you need more detail, just post the questions here. (i.e, "I'll Be Back!" )
    Vernon Frazee, Microsoft MVP (Windows - Shell/User)

    Defenses Up!
    Tip: When prompted for a password, give an incorrect one first. A phishing site will accept it; a legitimate one won't.


    Inside Spyware: A Guide to Finding, Removing and Preventing Online Pests


    If you don't keep up with security fixes, your computer|network won't be yours for long.

  4. #4
    Join Date
    Oct 2000
    Location
    Paterson, NJ, USA
    Posts
    968
    Thanks for the replies. Someone else suggested something simple that does what I need:

    ::getvol.bat
    @echo off

    vol D: |find /i "drive" > out.bat
    echo set vol=%%5> volume.bat
    call out.bat

    vol D: |find /i "serial" > out.bat
    echo set serial=%%4> volume.bat
    call out.bat

    del out.bat
    del volume.bat

    I've tried it, and it works. Maybe someone can help me with the following problem....

    =============================================
    I just finished putting the following DOS batch program together (with some help; line numbers are only there for the discussion that follows):

    1 @echo off
    2 vol D: |find /i "drive" > out.bat
    3 echo set vol=%%5> volume.bat
    4 call out.bat
    5 del out.bat
    6 del volume.bat
    7 if %vol%==IMAGES goto dline
    8 regedit.exe regE.txt
    9 goto end
    10 :dline
    11 regedit.exe regD.txt
    12 :end

    BRIEF DESCRIPTION: Lines 2 - 6 put the volume label of drive D into %vol%. Line 7 tests to see if the volume label is 'correct'. If 'incorrect', it switches to line 11. If 'correct', it excecutes line 8 instead and then exits. ['Correct' means it has the volume label I'm looking for.]

    Both regD.txt and regE.txt are the registry entries I want depending on what the volume label is.

    PROBLEM: I use this batch file in the Startup Folder in Windows98fe. It works, but the result of line 8 or 11 is two windows that require action (one is confirmation for the registry change, the other recognition that the change has been made). I want the whole process automated; no action required. How do I do it?

    Thanks again.


  5. #5
    Join Date
    Oct 2000
    Location
    Paterson, NJ, USA
    Posts
    968
    Thanks again Mosaic1. I appreciate your efforts to help. When I get something that completely works, I'll be sure to report it here.

    Give me some time to review and try your latest suggestions. I'll probably give them a try first thing tomorrow.

  6. #6
    Join Date
    Oct 2000
    Location
    Paterson, NJ, USA
    Posts
    968
    PRELIMINARY
    -----------
    Mosaic1: Do you mean the post regarding changing the NOTEPAD default directory? Seems like other people have a similar requirement to mine. Maybe this post will help.

    The final result is about as simple as I know how to get it. I think the regD/E files might be made shorter. My understanding of the registry is.... make a change in one handle key and the "other" is automatically changed. I don't remember which ones are connected, so I've yet to check into this improvement.

    FINAL STEPS
    -----------
    Here's the happily-ever-after ending to this story. I think anything past this would be refinement -- for example, making it work in a more general fashion for any PC. The end result works perfectly, is PC specific (see details below) and now works completely in the background during bootup.

    The following lines are added to Autoexec.bat:

    vol D: |find /i "drive" > out.bat
    echo set volab=%%5> volume.bat
    call out.bat
    del out.bat
    del volume.bat
    if %volab%==IMAGES goto dline
    regedit.exe regE.reg
    goto end
    :dline
    regedit.exe regD.reg
    :end
    set volab=


    Also, the files regD.reg and regE.reg need to be in the DOS path (for example, both of mine are in C directory).


    DETAILS
    --------
    The first and sixth lines are specific to my PC. However, this file can be adapted to anyone's particular setup.

    The first line specifies the D: drive (actually partition in my case) as the place from which to extract the volume label. This is because I keep my Favorites folder (moved using TweakUI) on the IMAGES partition. When I boot, either this partition or my removable drive ends up being labeled as "D:" by System Commander.

    When I have the removable drive tray out, IMAGES is D. When the drive tray is in, the removable drive (whatever that is, regardless of volume label on the disk it holds) is D. Hence, line 6. The 6-th line is where the volume label of the D drive is tested. If it is "IMAGES", then regD.reg is imported into the registry in real DOS mode (hence, no confirmation messages!). The registry file regD.reg changes ALL Windows registry entries necessary to ensure Windows points all "Favorites activities" to the current D drive/partition.

    If the label on D is NOT "IMAGES" (therefore, the removable tray is in), then regE.reg is imported. This registry file points Windows to the E-drive/partition, because IMAGES becomes the E drive when the tray is in.

    Hope this is clear enough. The only other thing anyone needs in order to use this fix for their own PC are the registry files to import. I'm giving the regD.reg file here. (NOTE: The "{" and "}" indicate the beginning and end of the file. They are NOT to be included in the file. WARNING: The carriage return at the end of the file is REQUIRED!!! The last registry entry will not be imported without it. There is no guarantee that these particular registry entries are compatible with any PC other than my own. If you want to use this fix, review your particular registry entries, and create your own file if necessary.)

    {REGEDIT4

    [HKEY_USERS\.DEFAULT\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders]
    "Favorites"="D:\\Favorites"

    [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders]
    "Favorites"="D:\\Favorites"

    [HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\explorer\User Shell Folders]
    "Favorites"="D:\\Favorites"

    [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders]
    "Favorites"=hex(2):44,3a,5c,46,61,76,6f,72,69,74,65,73,00

    [HKEY_USERS\.DEFAULT\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders]
    "Favorites"=hex(2):44,3a,5c,46,61,76,6f,72,69,74,65,73,00

    [HKEY_CURRENT_USER\Software\Microsoft\Advanced INF Setup\IE UserData\RegBackup\0]
    "84569d41a3ab9004"=hex:2c,53,4f,46,54,57,41,52,45,5c,4d,69,63,72,6f,73,6f,66,\
    74,5c,57,69,6e,64,6f,77,73,5c,43,75,72,72,65,6e,74,56,65,72,73,69,6f,6e,5c,\
    45,78,70,6c,6f,72,65,72,5c,53,68,65,6c,6c,20,46,6f,6c,64,65,72,73,2c,46,61,\
    76,6f,72,69,74,65,73,2c,00,01,00,00,00,15,00,00,00,44,3a,5c,46,61,76,6f,72,\
    69,74,65,73,00

    [HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Toolbar\ShellBrowser]
    "{0E5CBF21-D15F-11D0-8301-00AA005B4383}"=hex:21,bf,5c,0e,5f,d1,d0,11,83,01,00,\
    aa,00,5b,43,83,22,00,1c,00,08,00,00,00,06,00,00,00,01,00,00,00,00,00,00,00,\
    00,00,00,00,00,00,00,00,4c,00,00,00,01,14,02,00,00,00,00,00,c0,00,00,00,00,\
    00,00,46,03,00,00,00,10,00,00,00,20,f3,e0,a4,8b,f0,c0,01,00,e0,f3,7c,cf,ef,\
    c0,01,00,ab,d9,a5,8b,f0,c0,01,00,00,00,00,00,00,00,00,01,00,00,00,00,00,00,\
    00,00,00,00,00,00,00,00,00,6a,00,14,00,1f,0f,e0,4f,d0,20,ea,3a,69,10,a2,d8,\
    08,00,2b,30,30,9d,19,00,23,45,3a,5c,00,00,00,00,00,00,00,00,00,00,00,00,00,\
    00,00,00,00,e9,05,21,00,31,00,00,00,00,00,c9,2a,41,13,10,00,46,61,76,6f,72,\
    69,74,65,73,00,46,41,56,4f,52,49,7e,31,00,1a,00,31,00,00,00,00,00,c9,2a,5b,\
    13,10,00,4c,69,6e,6b,73,00,4c,49,4e,4b,53,00,00,00,48,00,00,00,1c,00,00,00,\
    01,00,00,00,1c,00,00,00,34,00,00,00,00,00,00,00,47,00,00,00,18,00,00,00,03,\
    00,00,00,b2,bd,b1,bd,10,00,00,00,53,54,4f,52,41,47,45,00,44,3a,5c,46,61,76,\
    6f,72,69,74,65,73,5c,4c,69,6e,6b,73,00,00,10,00,00,00,05,00,00,a0,06,00,00,\
    00,4e,00,00,00,00,00,00,00
    }

    The regE.reg file can be constructed from this by changing every reference to the D drive to E. How to do this correctly is obvious for the first three entries. The last four require interpreting the hex values. The safest way to locate the exact position on your PC might be to enter the registry and view the interpretation of the binary value by right-clicking on the particular entry and selecting modify. Look in the right-most column for what the numbers actually mean.

    In my example, values in the fourth and fifth registry entries in the regD.reg file need the first number (44 in my example) changed. "D" is 44. "E" would be 45.

    In my example, the last two registry entries require the first "44" found from the end of the string to be changed (each has a "3a" - representing the colon[:] to its right). Again, "D" is 44 and "E" is 45.

    My thanks to everyone for their help, especially Mosaic1 who followed through the whole process without giving up so easily!

    Have fun

    BWBarbieri

    [This message has been edited by bwbarbieri (edited 06-10-2001).]

    [This message has been edited by bwbarbieri (edited 06-10-2001).]

    [This message has been edited by bwbarbieri (edited 06-10-2001).]

  7. #7
    Join Date
    Oct 2000
    Location
    Paterson, NJ, USA
    Posts
    968
    One short note for those interested in this problem. Additional information can be found at http://computing.net/dos/wwwboard/forum/7062.html

    Someone by the name tsuji responded to my question on that site. He also covers the use of inf files.

  8. #8
    Join Date
    Feb 2000
    Location
    26.03°N 80.14°W
    Posts
    9,410
    Try it like this Mosaic:
    Code:
    @echo off
    if exist d:\favori~1\nul goto Documents
    regedit c:\e.reg
    goto End
    :Documents
    regedit c:\d.reg
    :End
    And bwbarbieri, yours could be shortened to:
    Code:
    vol d:|find/i "images"
    if errorlevel 0 if not errorlevel 1 goto Dline
    regedit c:\regE.reg
    goto End
    :Dline
    regedit c:\regD.reg
    :End
    Vernon Frazee, Microsoft MVP (Windows - Shell/User)

    Defenses Up!
    Tip: When prompted for a password, give an incorrect one first. A phishing site will accept it; a legitimate one won't.


    Inside Spyware: A Guide to Finding, Removing and Preventing Online Pests


    If you don't keep up with security fixes, your computer|network won't be yours for long.

  9. #9
    Join Date
    Feb 2000
    Location
    26.03°N 80.14°W
    Posts
    9,410
    You're Welcome. Glad I was able to help.

    Vernon Frazee, Microsoft MVP (Windows - Shell/User)

    Defenses Up!
    Tip: When prompted for a password, give an incorrect one first. A phishing site will accept it; a legitimate one won't.


    Inside Spyware: A Guide to Finding, Removing and Preventing Online Pests


    If you don't keep up with security fixes, your computer|network won't be yours for long.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •