There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
 
DOS/PDA/Other
Tag Cloud
adware audio bios blue screen boot bsod computer connection crash dell desktop email error excel firefox freeze freezing google hard drive hardware hijackthis install internet laptop linux malware network no sound outlook problem recovery router screen slow sound speakers spyware startup trojan usb video virus vista vundo webcam windows windows 7 windows vista windows xp wireless
Search
Search for:
Tech Support Guy Forums > Operating Systems > DOS/PDA/Other >
Solved: diskpart utility question

Tip: Click here to scan for System Errors and Optimize PC performance
[ Sponsored Link ]

Closed Thread
 
Thread Tools
scrfix's Avatar
Computer Specs
Senior Member with 249 posts.
 
Join Date: May 2009
Experience: Computer Repair Expert
29-Jun-2009, 11:33 AM #1
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
__________________
Wayne Leiser, Spectacular Computer Repair Computer Repair, Computer Services
World Famous Gift Baskets: Gift Baskets, Corporate Gifts
Resources LLC: Water Treatment Coagulation, Water Recycling
Squashman's Avatar
Distinguished Member with 14,920 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: IIAHYAYCESA,YAADA!
29-Jun-2009, 12:51 PM #2
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.
TheOutcaste's Avatar
Computer Specs
Distinguished Member with 5,315 posts.
 
Join Date: Aug 2007
Location: Oregon, USA
Experience: Intermediate
29-Jun-2009, 03:59 PM #3
Quote:
Originally Posted by Squashman View Post
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:
  1. Undetermined
  2. Removable
  3. Hard Drive
  4. Network Drive
  5. CD-ROM
  6. 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?
scrfix's Avatar
Computer Specs
Senior Member with 249 posts.
 
Join Date: May 2009
Experience: Computer Repair Expert
29-Jun-2009, 05:33 PM #4
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.
__________________
Wayne Leiser, Spectacular Computer Repair Computer Repair, Computer Services
World Famous Gift Baskets: Gift Baskets, Corporate Gifts
Resources LLC: Water Treatment Coagulation, Water Recycling
TheOutcaste's Avatar
Computer Specs
Distinguished Member with 5,315 posts.
 
Join Date: Aug 2007
Location: Oregon, USA
Experience: Intermediate
29-Jun-2009, 07:06 PM #5
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?
scrfix's Avatar
Computer Specs
Senior Member with 249 posts.
 
Join Date: May 2009
Experience: Computer Repair Expert
30-Jun-2009, 12:48 AM #6
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.
TheOutcaste's Avatar
Computer Specs
Distinguished Member with 5,315 posts.
 
Join Date: Aug 2007
Location: Oregon, USA
Experience: Intermediate
30-Jun-2009, 01:43 AM #7
Quote:
Originally Posted by scrfix View Post
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?
scrfix's Avatar
Computer Specs
Senior Member with 249 posts.
 
Join Date: May 2009
Experience: Computer Repair Expert
30-Jun-2009, 01:47 AM #8
Thanks,

So in your batch you really had %%I and you had ^,

Is that correct?
TheOutcaste's Avatar
Computer Specs
Distinguished Member with 5,315 posts.
 
Join Date: Aug 2007
Location: Oregon, USA
Experience: Intermediate
30-Jun-2009, 02:22 AM #9
Yes, the first code block is the line in the file:
Quote:
Originally Posted by TheOutcaste View Post
Code:
 For /F "tokens=*" %%I In ('wmic logicaldisk get DeviceID^,DriveType') Do @Echo %%I 
Closed Thread Bookmark and Share

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.

Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -5. The time now is 03:06 PM.
Copyright © 1996 - 2009 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.
Powered by Cermak Technologies, Inc.