 | Senior Member with 269 posts. | | Join Date: May 2009 Experience: Computer Repair Expert | | Solved: diskpart utility question I am checking for utilized drive letters on a computer. I know this can be done because HP does it with their printers however i keep running into an error. VISTA
The command is: diskpart
Wait for about 2-3 seconds
then list volume
This is great when I am doing this directly from the command line howeve when I attempt to batch it, the program hangs every time.
What am I doing wrong? Do I have to utilize Delayed Expansion or something? Code: @echo off
diskpart
delay 10
list volume
pause
| | Distinguished Member with 14,983 posts. | | Join Date: Apr 2003 Location: 1265 Lombardi Ave Experience: IIAHYAYCESA,YAADA! | | I believe you would need to do it as a diskpart script.
Inside your batch file you would do this.
diskpart /s myscript.txt
Put all your diskpart commands in the myscript.txt file and end it with the exit command. | | Distinguished Member with 5,485 posts. | | Join Date: Aug 2007 Location: Oregon, USA Experience: Intermediate | | Quote:
Originally Posted by Squashman I believe you would need to do it as a diskpart script.
Inside your batch file you would do this.
diskpart /s myscript.txt
Put all your diskpart commands in the myscript.txt file and end it with the exit command. | Correct, diskpart starts it's own interface, so your delay 10 command won't even be run until diskpart exits. And unlike netsh or wmic, it won't accept commands on the command line; you have to use a script.
Dispart will not show mapped drives, so you would need to run the net use command to check for those, or you can use wmic to get them all: wmic logicaldisk get DeviceID,DriveType
This will list all drive letters and the type of drive: - Undetermined
- Removable
- Hard Drive
- Network Drive
- CD-ROM
- RAM Disk
Keep in mind that Mapped Drives are user specific, so in Vista, if you run wmic from an Admin Prompt, you will only see drives mapped using the Administrator account, not drives mapped for the current user.
Net Use on Vista will show drives from other user accounts, on XP it won't.
Jerry
__________________ Microsoft MVP - Windows Desktop Experience
Of course I know all the answers  ; I just don't always match the answers to the right questions Are you aware of the New Signature Limitations? | | Senior Member with 269 posts. | | Join Date: May 2009 Experience: Computer Repair Expert | | Jerry,
That is brilliant. I had no clue that WMIC could do that. I attempted it on my XP box and it stated it had to install it. After it installed, it worked absolutely wonderfully.
Is there a way to check to see if it is already installed and if it is not installed, then install it before I run the command. | | Distinguished Member with 5,485 posts. | | Join Date: Aug 2007 Location: Oregon, USA Experience: Intermediate | | Should be able to just run the command, it will install automatically. It does mess with the output a bit, but if you skip the first line it shouldn't matter.
I ran the following line in a batch file on a XP system that doesn't have WMIC installed, the output is below: Code: For /F "tokens=*" %%I In ('wmic logicaldisk get DeviceID^,DriveType') Do @Echo %%I
Note that the comma has to be escaped. Code: Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
C:\>test.cmd
C:\>For /F "tokens=*" %I In ('wmic logicaldisk get DeviceID,DriveType') Do @Echo %I
Please wait while WMIC is being installed.DeviceID DriveType
A: 2
C: 3
D: 5
C:\>
It just sat for a few seconds while it was installing, then completed just fine. Skipping the first line should work whether it's installed or not. If you need the column headers, you can use substring replacement to remove the install message, however, I have seen it list a different message:
Please wait while WMIC compiles updated MOF files.DeviceID DriveType
This happened when I ended the batch before WMIC finished installing. There could be other messages as well, and it's also possible that it will fail to install; I remember seeing that happen on a system that had a lot of services that refused to start.
You could also just run a WMIC /?>Nul command which would install it if not already installed.
__________________ Microsoft MVP - Windows Desktop Experience
Of course I know all the answers  ; I just don't always match the answers to the right questions Are you aware of the New Signature Limitations? | | Senior Member with 269 posts. | | Join Date: May 2009 Experience: Computer Repair Expert | | Jerry,
Off the subject. Does the %I mean something in a FOR statement or can I use %F.
Why is there only 1 % vs 2 %'s?
Last edited by scrfix : 30-Jun-2009 01:04 AM.
| | Distinguished Member with 5,485 posts. | | Join Date: Aug 2007 Location: Oregon, USA Experience: Intermediate | | Quote:
Originally Posted by scrfix Jerry,
Off the subject. Does the %I mean something in a FOR statement or can I use %F.
Why is there only 1 % vs 2 %'s? | You can use any single character for the loop variable. Help says A-Z and a-z, but you can use punctuation and numbers. That can get tricky if you need more than 1, as you need to know the proper order. Numbers could be confused for batch parameters instead of a loop variable. Special characters like ", &, <, and > need to be escaped. ! may work if delayed expansion is disabled, but might not work if it's enabled, or may need to be escaped. I haven't tried using % yet, but I imagine it would be a pain.
So for example, instead of A and B, you can use Z and [.
For loops in BASIC (similar to For /L) were often used to access an array element, so the the letter I (for Index) was often used, so I tend to use I in loops a lot.
You only use two %'s in a batch file. At the command prompt, you only need one, and if Echo is ON, you'll see that it only displays one % when executing the line in the batch file. The above is the output from the batch file, so there is only one %. You'll notice the ^ wasn't displayed either.
__________________ Microsoft MVP - Windows Desktop Experience
Of course I know all the answers  ; I just don't always match the answers to the right questions Are you aware of the New Signature Limitations? | | Senior Member with 269 posts. | | Join Date: May 2009 Experience: Computer Repair Expert | | Thanks,
So in your batch you really had %%I and you had ^,
Is that correct? | | Distinguished Member with 5,485 posts. | | Join Date: Aug 2007 Location: Oregon, USA Experience: Intermediate | | Yes, the first code block is the line in the file: Quote:
Originally Posted by TheOutcaste Code: For /F "tokens=*" %%I In ('wmic logicaldisk get DeviceID^,DriveType') Do @Echo %%I | |  THIS THREAD HAS EXPIRED.
Are you having the same problem?
We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.
|
Smart Search
| Find your solution! | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | | |  WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.
| You Are Using: |
Advertisements do not imply our endorsement of that product or service.
All times are GMT -5. The time now is 09:51 PM.
Copyright © 1996 - 2009 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd. | |
|