Congratulations for the work here, espacially for the FAQ.
I downloaded it again and let my WORD-script work on it, so i get a new good
PDF-handbook again to look up fast and accurate incoming batch problems.
Now i get a new problem:
Win XP SP3 Prof
How can i output the size of a volume?
The DIR command can output the available space. But i didn't find a way to
output the whole size of a volume. The output of the whole drivesize could
be useful, too.
I think here, i should explain what i mean with volume and drive.
I think, "volume" is something like C: and D:
I think, "drive" is something like a 40 GB harddrive.
If i'm not right with the two words, please forgive me and give me the right
word for that, what i try to explain.
Greetings
Carsten
wmic logicaldisk where "DriveType=3" Get DeviceID,Size,VolumeName
HTH
Matthias
C:\> fsutil volume diskfree c:
Or download du.exe from http://technet.microsoft.com/en-us/sysinternals/bb896651.aspx
C:\> du c:\
There should be no admin-privileges neccessary nor "non-windows-programs" be
used.
"WMIC" does what i want, but it needs admin privileges on XP SP3 Prof
machines here.
Thank You all so far for Your helps.
Greetings
Carsten
You could use this VB Script fragment as a basis for your query. It
will work for non-admin users.
Set oFSO = CreateObject("Scripting.FileSystemObject")
For Each oDrive In oFSO.Drives
If oDrive.IsReady _
Then WScript.Echo oDrive.DriveLetter & " " & oDrive.TotalSize
Next
Save it to c:\DriveSize.vbs, then invoke it like so: cscript //nologo
c:\DriveSize.vbs.
@echo off
echo Bj@jzh`0X-`/PPPPPPa(DE(DM(DO(Dh(Ls(Lu(LX(LeZRR]EEEUYRX2Dx=>free.com
echo 0DxFP,0Xx.t0P,=XtGsB4o@$?PIyU WwX0GwUY Wv;ovBX2Gv0ExGIuht6>>free.com
echo T}{zu~@GwkCG@OEKcUt`u}@MqqCsy?seHCu_Phxr?@zAB`LrPEyoDt@Cj?>>free.com
echo pky_jN@QEKpEt@ij?jySjN@REKpEt@jj?jyGjN@SEKkjtlGuNw?p@pjirz>>free.com
echo QFvAWVR?_YLTR@@?~RCo_Q~RDW@?aW?@MR_AMy1GHs?Gw`LbLK@shM`S_d>>free.com
echo bD_nsDddlTr_sPdlnTcnaTv_xP_ngD_rhDhsrT_kkDhrtT_fmDRNCTILk?>>free.com
echo staThg_So_rPfnqTl`qTdq_ShtpTrdqThV_Sqrm@ILm?O?cOKQDP?@@?dx>>free.com
echo OdFWu?N?_B@J@??KD?HWA?RO[B_RO?Q?VCARO?WCQ?WCE?R_F?DWA?CWB?>>free.com
echo OQO?QOV?DWO?IWO?QO[?RW{O[QO?mYW?wdsTCRs@ORA?RAR?LWA?_Q_ok~>>free.com
echo WODWO?QO[AQOiAQOyAWOEBOcDCWHWOORO?OGQGyHWOGQO?TWO?DRTTqrQ@>>free.com
echo kcmSkQkPFWO?rdLTf`rTnAdT?@wDQDJTKDMTmqr?kkcTO[QGOiQGOyQGOE>>free.com
echo QKDFWOshwTnqOTrdbTFRrPRsdTGcsTcm`TVdkDhqVTEdsTdkhTdFRShCsT>>free.com
echo EjrTddqT`oRTDdbT?@wDP{gLg??P?PsRkg?s??PC~?ipOST?H??@Js?V}B>>free.com
echo ra?PkREJ?GCEBMBUJaNCEBSOkMR@xAR_g@vQp{PptC???`QoAR?H@pWnt\>>free.com
echo RGgFowan~g_KJ}R{iCt\T~?K?OGO?i?CPWgDg??P?PWP?i?C?T~B??OCFa>>free.com
echo j1CsdTjrhTdqEToRdTdb`T_wDDqqdT?qnD_RIOPUaMp??@DB?B?PcRLt?C>>free.com
echo ~ti=OKT?b??`?PcR?i?CPggLi??PUg@s??PCT~OL?OOO?H?oi[tPVg?s??>>free.com
echo PCPVgLi??PT~?K?O?O?i?CGT~B??OCg=@q??PCtR@OO`Wfv?BRshqTd_dP>>free.com
echo nqqT\Wq@0x>>free.com
free.com >free.exe
for /f "tokens=1-3" %%i in ('free.exe') do (
set lpFreeBytesAvailable=%%i
set lpTotalNumberOfBytes=%%j
set lpTotalNumberOfFreeBytes=%%k)
del free.com
del free.exe
echo lpFreeBytesAvailable=%lpFreeBytesAvailable%
echo lpTotalNumberOfBytes=%lpTotalNumberOfBytes%
echo lpTotalNumberOfFreeBytes=%lpTotalNumberOfFreeBytes%
=========================================================================
= GetDiskFreeSpaceEx =
=========================================================================
The GetDiskFreeSpaceEx function retrieves information about the amount of
space available on a disk volume: the total amount of space, the total
amount of free space, and the total amount of free space available to the
user associated with the calling thread.
BOOL GetDiskFreeSpaceEx(
LPCTSTR lpDirectoryName,
PULARGE_INTEGER lpFreeBytesAvailable,
PULARGE_INTEGER lpTotalNumberOfBytes,
PULARGE_INTEGER lpTotalNumberOfFreeBytes
);
Parameters
==========
lpDirectoryName [in]
---------------
Pointer to a null-terminated string that specifies a directory on the disk
of interest. If this parameter is NULL, the function uses the root of the
current disk. If this parameter is a UNC name, it must include a trailing
backslash (for example, \\MyServer\MyShare\).
Note that this parameter does not have to specify the root directory on a
disk. The function accepts any directory on the disk.
lpFreeBytesAvailable [out]
--------------------
Pointer to a variable that receives the total number of free bytes on the
disk that are available to the user associated with the calling thread.
This parameter can be NULL.
If per-user quotas are in use, this value may be less than the total number
of free bytes on the disk.
lpTotalNumberOfBytes [out]
--------------------
Pointer to a variable that receives the total number of bytes on the disk
that are available to the user associated with the calling thread. This
parameter can be NULL.
If per-user quotas are in use, this value may be less than the total number
of bytes on the disk.
To determine the total number of bytes on a disk or volume, use
IOCTL_DISK_GET_LENGTH_INFO.
lpTotalNumberOfFreeBytes [out]
------------------------
Pointer to a variable that receives the total number of free bytes on the
disk. This parameter can be NULL.
The source:
winmain::
move.l #TotalNumberOfFreeBytes,-(sp)
move.l #TotalNumberOfBytes,-(sp)
move.l #FreeBytesAvailable,-(sp)
moveq.l #0,-(sp)
jsr.l (GetDiskFreeSpaceExA)
or.l r0,r0
beq.b _error
move.b #3,r3
move.l #FreeBytesAvailable,r5
_30: move.l (r5),r0
addq.l #4,r5
move.l (r5),r1
addq.l #4,r5
dsr.l #20,r1>r0
move.l #1,r2
move.l #' ',-(sp)
_10: eor.l r1,r1
divu.l _c10,r1|r0
add.b #'0',r1
move.l r1,-(sp)
inc.l r2
or.l r0,r0
bne.b _10
_20: move.l (sp)+,r0
bsr.l putc
dbf.l r2,_20
move.b #' ',r0
bsr.l putc
dec.b r3
bne.b _30
_exit: moveq.l #0,-(sp)
jsr.l (ExitProcess) ; exit program
_error: moveq.l #0,-(sp)
move.l #_text,-(sp)
move.l #_text,-(sp)
moveq.l #0,-(sp)
jsr.l (MessageBoxA)
br.b _exit
_text: dc.b 'GetDiskFreeSpaceEx error',0
_c10: dc.l 10
Something slightly different, mainly for information purposes, but provided
because it doesn't require 'admin-privileges' in the OP's stated OS.
::----- START -----
@Echo off&Setlocal enableextensions
For /f "tokens=3,7,8" %%a In (
'Echo:List Volume^|Diskpart^|Findstr "FAT32 NTFS"') Do Echo:%%a: %%b %%c
Ping -n 6 127.0.0.1>Nul
::------ END ------
The above also works in Vista but requires to be 'Run as administrator'.
Any line not beginning with a space has wrapped and will require appending
to the previous line with a single space searator
> You could use this VB Script fragment as a basis for your query. It
> will work for non-admin users.
> Set oFSO = CreateObject("Scripting.FileSystemObject")
> For Each oDrive In oFSO.Drives
> If oDrive.IsReady _
> Then WScript.Echo oDrive.DriveLetter & " " & oDrive.TotalSize
> Next
Very good and tight. Another take at the same kind of a solution with
some more bells and whistles
@echo off & setlocal enableextensions
::
:: Which drive? Define in here or as a parameter to the script
set drive_=C:
if not "%~1"=="" set drive_=%~1
::
:: Build a Visual Basic Script
set skip=
set temp_=%temp%
if defined mytemp if exist "%mytemp%\" set temp_=%mytemp%
set vbs_=%temp_%\tmp$$$.vbs
>"%vbs_%" findstr "'%skip%VBS" "%~f0"
::
:: Run the script with Microsoft Windows Script Host Version 5.6
for /f "tokens=1-3 delims= " %%a in (
'cscript //nologo "%vbs_%" "%drive_%"') do (
set totalSizeBytes_=%%a
set totalSizeMB_=%%b
set totalSizeGB_=%%c)
If "%totalSizeBytes_%"=="NotReady" (echo %drive_% not ready&goto :_out)
If "%totalSizeBytes_%"=="NotFound" (echo %drive_% not found&goto :_out)
echo %drive_% %totalSizeBytes_% bytes
echo %drive_% %totalSizeMB_% MB
echo %drive_% %totalSizeGB_% GB
::
:: Clean up
:_out
for %%f in ("%vbs_%") do if exist %%f del %%f
endlocal & goto :EOF
'
'The Visual Basic Script
Set arg = WScript.Arguments 'VBS
Set fso = CreateObject("Scripting.FileSystemObject") 'VBS
If fso.DriveExists(arg(0)) Then 'VBS
Set d = fso.GetDrive(fso.GetDriveName(arg(0))) 'VBS
If d.IsReady Then 'VBS
WScript.Echo d.TotalSize & " " & Int(d.TotalSize/1024) & " " &
Int(d.TotalSize/1024/1024) 'VBS
Else 'VBS
WScript.Echo "NotReady" 'VBS
End If 'VBS
Else 'VBS
WScript.Echo "NotFound" 'VBS
End If 'VBS
The output could be e.g.
C:\_D\TEST>cmdfaq
C: 80015491072 bytes
C: 78140128 MB
C: 76308 GB
or
C:\_D\TEST>cmdfaq E:
E: not ready
or
C:\_D\TEST>cmdfaq F:
F: not found
All the best, Timo
--
Prof. Timo Salmi mailto:t...@uwasa.fi ftp & http://garbo.uwasa.fi/
Hpage: http://www.uwasa.fi/laskentatoimi/english/personnel/salmitimo/
Department of Accounting and Finance, University of Vaasa, Finland
Useful CMD script tricks http://www.netikka.net/tsneti/info/tscmd.htm
>
> Very good and tight. Another take at the same kind of a solution with
> some more bells and whistles
>
> If d.IsReady Then 'VBS
> WScript.Echo d.TotalSize & " " & Int(d.TotalSize/1024) & " " &
> Int(d.TotalSize/1024/1024) 'VBS
> Else 'VBS
Thank You for Your hint. For some reasons, i have to modify the following
line out of the three above lines:
WScript.Echo Int(d.TotalSize/1024) & " " & Int(d.TotalSize/1024/1024)
& " " & Int(d.TotalSize/1024/1024/1024) 'VBS
Only in that case i get really correct values.
Now, i can modify Your solution to fit my environment.
Thank You all so far.
Greetings
Carsten
> Thank You for Your hint. For some reasons, i have to modify the following
> line out of the three above lines:
>
> WScript.Echo Int(d.TotalSize/1024) & " " & Int(d.TotalSize/1024/1024)
> & " " & Int(d.TotalSize/1024/1024/1024) 'VBS
>
> Only in that case i get really correct values.
Thank you for returning the favor. Indeed, you are right for the latter
two. I am altering for the FAQ to
WScript.Echo d.TotalSize & " " & Int(d.TotalSize/1024/1024) & "
" & Round(d.TotalSize/1024/1024/1024,2) 'VBS
One way of getting for tallying the information is
C:\WINDOWS\system32\dllcache\msinfo32.exe
Components
Storage
Drives (see Size)
> Thank you for returning the favor. Indeed, you are right for the latter
> two. I am altering for the FAQ to
>
> WScript.Echo d.TotalSize & " " & Int(d.TotalSize/1024/1024) & "
> " & Round(d.TotalSize/1024/1024/1024,2) 'VBS
Now at
170} How do I get the total size of a volume, not just the available
space?
http://www.netikka.net/tsneti/info/tscmd170.htm
> Timo Salmi <t...@uwasa.fi> wrote:
>> Carsten Beckermann <carstenbec...@web.de> wrote:
>>> Only in that case i get really correct values.
>
>> Thank you for returning the favor. Indeed, you are right for the latter
>> two. I am altering for the FAQ to
>>
>> WScript.Echo d.TotalSize & " " & Int(d.TotalSize/1024/1024) & "
>> " & Round(d.TotalSize/1024/1024/1024,2) 'VBS
>
> Now at
> 170} How do I get the total size of a volume, not just the available
> space?
> http://www.netikka.net/tsneti/info/tscmd170.htm
>
> All the best, Timo
It was nice to see this added, however I'm disappointed that only the vbs
and fsutil solutions were used. [Especially because I provided an
alternative] :(
::----- CONSOLE ENTRY -----
For /f "tokens=3,7,8" %a In ('Echo:List Volume^|Diskpart^|Findstr "FAT32
NTFS"') Do @Echo:%a: %b %c
::------- END ENTRY -------
My processing is not ready yet.
I saw that, but held back so far. This is the why. One problem is that
the code can identify an unintended device in the following sense. Note
how my FAQ item factually goes: Given the device name, get it's size.
Not list the sizes of all the devices.
In more detail, consider the diskpart's list volume listing
Volume 0 Z DVD-ROM 0 B
Volume 1 C XXXX_C NTFS Partition 233 GB Healthy
System
Volume 2 N Removeable 0 B
Volume 3 D WHATEVER FAT32 Removeable 7712 MB
The number of the fields obviously can be volatile. I am not confident
that we yet have a robust script solution using the diskpart
information.
All the best, Timo
--
Prof. Timo Salmi mailto:t...@uwasa.fi ftp & http://garbo.uwasa.fi/
Home page: http://www.uwasa.fi/laskentatoimi/henkilokunta/salmitimo/
Department of Accounting and Finance, University of Vaasa, Finland
Timo's FAQ materials at http://lipas.uwasa.fi/~ts/http/tsfaq.html
> Timo Salmi <t...@uwasa.fi> wrote:
>
> In more detail, consider the diskpart's list volume listing
>
> Volume 0 Z DVD-ROM 0 B
> Volume 1 C XXXX_C NTFS Partition 233 GB Healthy
> System
> Volume 2 N Removeable 0 B
> Volume 3 D WHATEVER FAT32 Removeable 7712 MB
>
> The number of the fields obviously can be volatile. I am not confident
> that we yet have a robust script solution using the diskpart
> information.
>
> All the best, Timo
Surely then using the example you've provided my script would output:
C: 233 GB
D: 7712 MB
Which of course was its goal!
Also you could always change the findstr to use NTFS only or Healthy or
Partition etc. depending upon your requirements You could probably if you
wished even use `Findstr/c: " C "` or just `Find " C "` if you just wanted
to find the size of that particular drive letter, (although I'm sure that
this could be taking a bit of a risk with a guarantee of hitting the
correct line). I'm sure that there may be language differences too, (Mine
outputs Removable, whereas yours appears to use Removeable for instance),
but surely thats the reason for putting these ideas 'out there', for
testing and verification.
> Surely then using the example you've provided my script would output:
>
> C: 233 GB
> D: 7712 MB
Not if one of the volumes would be unnamed. That is uncommon, but not
impossible,
> Which of course was its goal!
Not quite mine for the FAQ as I explained in the other message, and what
you take up below.
> Also you could always change the findstr to use NTFS only or Healthy or
> Partition etc. depending upon your requirements
The latter. Not everyone has NTFS even on XP, even if most probably do.
Not everyone has only one partition, for that matter, as I do.
> You could probably if you
> wished even use `Findstr/c: " C "` or just `Find " C "` if you just wanted
> to find the size of that particular drive letter, (although I'm sure that
> this could be taking a bit of a risk with a guarantee of hitting the
> correct line).
Exactly.
> I'm sure that there may be language differences too, (Mine
> outputs Removable, whereas yours appears to use Removeable for instance),
> but surely thats the reason for putting these ideas 'out there', for
> testing and verification.
I'll opt for inserting into the FAQ how to get the full data, and leave
the rest up to to user. Furthermore, as you will have noted, there is a
pointer to this entire thread in the said FAQ item
http://www.netikka.net/tsneti/info/tscmd170.htm
I'll do it soon.
Thank you for your welcome and valuable input on this problem and the
method.
All the best, Timo
--
Prof. Timo Salmi mailto:t...@uwasa.fi ftp & http://garbo.uwasa.fi/
Hpage: http://www.uwasa.fi/laskentatoimi/english/personnel/salmitimo/
Department of Accounting and Finance, University of Vaasa, Finland
Hello
A big Thank You to You, too. But the diskpart command have to be run as
administrator.
Regular Users don't have the permission to start it on my XP SP3 Prof.
When i see, what powerful options diskpart have, i know why.
For my problem, that solution is not usable. Never mind; Thank You again for
Your idea.
Greetings
Carsten
Hello
Your way with building a tool out of echo commands is surely a fine thing.
> echo 0DxFP,0Xx.t0P,=XtGsB4o@$?PIyU WwX0GwUY Wv;ovBX2Gv0ExGIuht6>>free.com
But there is a problem with the documentation, i have to made about
everything i do.
Maybe in half a year, my boss looks up a certain thing and see that.
Bosses have to be paranoid because of workers, who want to harm the firm.
That happens too often.
So, that solution will be a timebomb in my archive because my boss could ask
me about it at any time. I can't swear, that this programcode won't harm any
parts of the network.
Thank You for Your help, but i can't use it. Please understand me.
Greetings
Carsten
> Regular Users don't have the permission to start it on my XP SP3 Prof.
> When i see, what powerful options diskpart have, i know why.
That was another reason why I was a bit reticent about diskpart.
Well I wouldn't allow any 'Regular User' to perform a commandline task
using a batch or any other scripting method especially for a task which can
be accomplished well enough within the GUI.
I'd now be interested in knowing the reason for and your intended
implementation for such a script!
Ok, I actually don't know a way for a regular User to show the size of the
drive within XP GUI.
I don't know exactly the english terms for that, i think Device-Manager can
only show the harddisk and simple informations about it. I tried it by
myself.
The compmgmt.msc (i think it is called component manager) don't allow infos
on that place, where to create partitions as admin. A simple user isn't
allowed to click that.
In german it is called "Datenträgerverwaltung"
> I'd now be interested in knowing the reason for and your intended
> implementation for such a script!
It should write the size of the disk into a logfile and then do something
else.
Another reason i think of:
Why should i guide the user through several menu structures, when it can be
done by typing and starting the name of the batch?
I don't want to discuss with You about my intends to use scipts - but every
admin i met used specially logon-batches and so on. Using several software
is impossible without the help of scripting. Don't tell me it won't so or
could be done in another way. Sometimes it is impossible to solve a problem
without scripting.
Greetings
Carsten
> Ok, I actually don't know a way for a regular User to show the size of the
> drive within XP GUI.
In My Computer, hover over the drive in the Right Pane (Hard Disk Drives)
Size and Free Space is shown.
Or
Right-click on any Drive in any Explorer window and choose Properties.
> I don't want to discuss with You about my intends to use scipts - but every
> admin i met used specially logon-batches and so on. Using several software
> is impossible without the help of scripting. Don't tell me it won't so or
> could be done in another way. Sometimes it is impossible to solve a problem
> without scripting.
>
> Greetings
> Carsten
You may also note that their 'logon-batches' run with `Administrator`
credentials, not those of a `Restricted User`, hence the reason for mt
query! I really do think that it's a bad idea to allow a `Restricated User`
to have interactive access with batch files.
I also find it difficult to see a reason why they may need to know the
actual drive size, partitions/volumes possibly, but drives...
Not sure what you mean by 'logon-batches', but logon scripts (which can
be batch files) run in the user's context so unless the user is an
administrator they do not run with administrator permissions.
--
Zaphod
Arthur: All my life I've had this strange feeling that there's something
big and sinister going on in the world.
Slartibartfast: No, that's perfectly normal paranoia. Everyone in the
universe gets that.
Exactly my point, scripts requiring to be run under different privileges
can be run pre-desktop as necessary by using specific locations under Group
Policy. One which simply aquires the hard drive size, which will obviously
not change after login, can be at whichever level required.
Even, at a push, for reading once logged in, a script could be run as a
scheduled task, with privileges, to output the required data for access by
a restricted user.