I have the following code inserted into a script I am working on and need
some help with two items.
1. How can I get the totalsize formated into MB
2. The strFile.WriteLine at the bottom keeps giving me an error. IT doesn't
seem to like the double )). How do I fix this.

Please bear in mind that noob status would mean I know more than I currently
do. Be gentle.

The code below is a snippet from my script.

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colDisks = objWMIService.ExecQuery _
("Select * from Win32_LogicalDisk Where DriveType = 3")
For Each objDisk in colDisks
intFreeSpace = objDisk.FreeSpace
intTotalSpace = objDisk.Size
strFile.WriteLine(intTotalSpace)
pctFreeSpace = intFreeSpace / intTotalSpace
strFile.WriteLine(objDisk.DeviceID, FormatPercent(pctFreeSpace))
Next

Thanks,

Aaron

Re: Disk Space help by Tom

Tom
Fri Jan 25 07:56:58 CST 2008

On Jan 25, 8:39 am, "AaronK" <aar...@fake-email.com> wrote:
> I have the following code inserted into a script I am working on and need
> some help with two items.
> 1. How can I get the totalsize formated into MB
> 2. The strFile.WriteLine at the bottom keeps giving me an error. IT doesn't
> seem to like the double )). How do I fix this.
>
> Please bear in mind that noob status would mean I know more than I currently
> do. Be gentle.
>
> The code below is a snippet from my script.
>
> Set objWMIService = GetObject("winmgmts:" _
> & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
> Set colDisks = objWMIService.ExecQuery _
> ("Select * from Win32_LogicalDisk Where DriveType = 3")
> For Each objDisk in colDisks
> intFreeSpace = objDisk.FreeSpace
> intTotalSpace = objDisk.Size
> strFile.WriteLine(intTotalSpace)
> pctFreeSpace = intFreeSpace / intTotalSpace
> strFile.WriteLine(objDisk.DeviceID, FormatPercent(pctFreeSpace))
> Next
>
> Thanks,
>
> Aaron

If I understand you correctly, I believe the answers are ...

1.
intTotalSpace = objDisk.Size \ 1048576

2.
strFile.WriteLine objDisk.DeviceID, FormatPercent(pctFreeSpace)

The error is something like "subroutine cannot have perentheses",
right? IMHO, it's a problem with the documentation that consistently
shows them around single arguments in the examples. In that case, it
acts to convert the argument to a ByRef and doesn't throw an error.
However, when there are multiple arguments, VBS complains. Go figure.

Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/

Re: Disk Space help by Pegasus

Pegasus
Fri Jan 25 07:58:44 CST 2008


"AaronK" <aaronk@fake-email.com> wrote in message
news:%23qxTJf1XIHA.3652@TK2MSFTNGP02.phx.gbl...
>I have the following code inserted into a script I am working on and need
>some help with two items.
> 1. How can I get the totalsize formated into MB
> 2. The strFile.WriteLine at the bottom keeps giving me an error. IT
> doesn't seem to like the double )). How do I fix this.
>
> Please bear in mind that noob status would mean I know more than I
> currently do. Be gentle.
>
> The code below is a snippet from my script.
>
> Set objWMIService = GetObject("winmgmts:" _
> & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
> Set colDisks = objWMIService.ExecQuery _
> ("Select * from Win32_LogicalDisk Where DriveType = 3")
> For Each objDisk in colDisks
> intFreeSpace = objDisk.FreeSpace
> intTotalSpace = objDisk.Size
> strFile.WriteLine(intTotalSpace)
> pctFreeSpace = intFreeSpace / intTotalSpace
> strFile.WriteLine(objDisk.DeviceID, FormatPercent(pctFreeSpace))
> Next
>
> Thanks,
>
> Aaron

"strFile.WriteLine" is not a valid VB Script command. Try this instead:

NL = Chr(10)
strcomputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strcomputer & "\root\cimv2")
Set colDisks = objWMIService.ExecQuery _
("Select * from Win32_LogicalDisk Where DriveType = 3")
For Each objDisk In colDisks
intFreeSpace = objDisk.FreeSpace / 1000000
intTotalSpace = objDisk.Size / 1000000
WScript.Echo NL & "Drive " & objDisk.DeviceID
WScript.Echo FormatNumber(intTotalSpace, 0, 0, -2) & " MBytes"
pctFreeSpace = intFreeSpace / intTotalSpace
WScript.Echo FormatPercent(pctFreeSpace) & " free"
Next



Re: Disk Space help by AaronK

AaronK
Fri Jan 25 11:50:51 CST 2008

Tom,

That worked like a charm.

Thank You,

Aaron


"Tom Lavedas" <tglbatch@cox.net> wrote in message
news:06e06dd9-4529-45b2-b8d7-52cae913c7c1@i3g2000hsf.googlegroups.com...
> On Jan 25, 8:39 am, "AaronK" <aar...@fake-email.com> wrote:
>> I have the following code inserted into a script I am working on and need
>> some help with two items.
>> 1. How can I get the totalsize formated into MB
>> 2. The strFile.WriteLine at the bottom keeps giving me an error. IT
>> doesn't
>> seem to like the double )). How do I fix this.
>>
>> Please bear in mind that noob status would mean I know more than I
>> currently
>> do. Be gentle.
>>
>> The code below is a snippet from my script.
>>
>> Set objWMIService = GetObject("winmgmts:" _
>> & "{impersonationLevel=impersonate}!\\" & strComputer &
>> "\root\cimv2")
>> Set colDisks = objWMIService.ExecQuery _
>> ("Select * from Win32_LogicalDisk Where DriveType = 3")
>> For Each objDisk in colDisks
>> intFreeSpace = objDisk.FreeSpace
>> intTotalSpace = objDisk.Size
>> strFile.WriteLine(intTotalSpace)
>> pctFreeSpace = intFreeSpace / intTotalSpace
>> strFile.WriteLine(objDisk.DeviceID, FormatPercent(pctFreeSpace))
>> Next
>>
>> Thanks,
>>
>> Aaron
>
> If I understand you correctly, I believe the answers are ...
>
> 1.
> intTotalSpace = objDisk.Size \ 1048576
>
> 2.
> strFile.WriteLine objDisk.DeviceID, FormatPercent(pctFreeSpace)
>
> The error is something like "subroutine cannot have perentheses",
> right? IMHO, it's a problem with the documentation that consistently
> shows them around single arguments in the examples. In that case, it
> acts to convert the argument to a ByRef and doesn't throw an error.
> However, when there are multiple arguments, VBS complains. Go figure.
>
> Tom Lavedas
> ===========
> http://members.cox.net/tglbatch/wsh/



Re: Disk Space help by ekkehard

ekkehard
Sat Jan 26 07:44:45 CST 2008

Tom Lavedas schrieb:
> On Jan 25, 8:39 am, "AaronK" <aar...@fake-email.com> wrote:
>> I have the following code inserted into a script I am working on and need
>> some help with two items.
[...]
>> 2. The strFile.WriteLine at the bottom keeps giving me an error. IT doesn't
>> seem to like the double )). How do I fix this.
[...]
>> strFile.WriteLine(objDisk.DeviceID, FormatPercent(pctFreeSpace))
[...]
> If I understand you correctly, I believe the answers are ...
[...]
> 2.
> strFile.WriteLine objDisk.DeviceID, FormatPercent(pctFreeSpace)
>
> The error is something like "subroutine cannot have perentheses",
> right? IMHO, it's a problem with the documentation that consistently
> shows them around single arguments in the examples. In that case, it
> acts to convert the argument to a ByRef and doesn't throw an error.
Putting a parameter of a Sub/Function call in () passes the parameter
*By Value* (copy).
> However, when there are multiple arguments, VBS complains. Go figure.
The simple rule is: No parameter list () if calling a Sub (or a Function
as a Sub).

Re: Disk Space help by ekkehard

ekkehard
Sat Jan 26 07:55:45 CST 2008

Pegasus (MVP) schrieb:
> "AaronK" <aaronk@fake-email.com> wrote in message
> news:%23qxTJf1XIHA.3652@TK2MSFTNGP02.phx.gbl...
>> I have the following code inserted into a script I am working on and need
>> some help with two items.
[...]
>> 2. The strFile.WriteLine at the bottom keeps giving me an error. IT
>> doesn't seem to like the double )). How do I fix this.
[...]
>> strFile.WriteLine(objDisk.DeviceID, FormatPercent(pctFreeSpace))
[...]
>
> "strFile.WriteLine" is not a valid VB Script command. Try this instead:
>
> NL = Chr(10)
> strcomputer = "."
> Set objWMIService = GetObject("winmgmts:" _
> & "{impersonationLevel=impersonate}!\\" & strcomputer & "\root\cimv2")
> Set colDisks = objWMIService.ExecQuery _
> ("Select * from Win32_LogicalDisk Where DriveType = 3")
> For Each objDisk In colDisks
> intFreeSpace = objDisk.FreeSpace / 1000000
> intTotalSpace = objDisk.Size / 1000000
> WScript.Echo NL & "Drive " & objDisk.DeviceID
> WScript.Echo FormatNumber(intTotalSpace, 0, 0, -2) & " MBytes"
> pctFreeSpace = intFreeSpace / intTotalSpace
> WScript.Echo FormatPercent(pctFreeSpace) & " free"
> Next
"strFile.Writeline <Whatever>" can be valid, if the (badly named)
variable strFile holds an open TextStream.

[I wouldn't nit pick on this, if trying to use parameter () in Sub
calls - and committing fraud by using bad variable names - weren't
causing problems so frequently.]

Re: Disk Space help by Tom

Tom
Sat Jan 26 10:01:14 CST 2008

On Jan 26, 8:44 am, "ekkehard.horner" <ekkehard.hor...@arcor.de>
wrote:
> Tom Lavedas schrieb:
>
> > On Jan 25, 8:39 am, "AaronK" <aar...@fake-email.com> wrote:
> >> I have the following code inserted into a script I am working on and need
> >> some help with two items.
> [...]
> >> 2. The strFile.WriteLine at the bottom keeps giving me an error. IT doesn't
> >> seem to like the double )). How do I fix this.
> [...]
> >> strFile.WriteLine(objDisk.DeviceID, FormatPercent(pctFreeSpace))
> [...]
> > If I understand you correctly, I believe the answers are ...
> [...]
> > 2.
> > strFile.WriteLine objDisk.DeviceID, FormatPercent(pctFreeSpace)
>
> > The error is something like "subroutine cannot have perentheses",
> > right? IMHO, it's a problem with the documentation that consistently
> > shows them around single arguments in the examples. In that case, it
> > acts to convert the argument to a ByRef and doesn't throw an error.
>
> Putting a parameter of a Sub/Function call in () passes the parameter
> *By Value* (copy).> However, when there are multiple arguments, VBS complains. Go figure.
>
> The simple rule is: No parameter list () if calling a Sub (or a Function
> as a Sub).

Yes, your right of course. I can't keep the terminology straight. I
realized my error a while after my post, but decided to leave it be.
Thanks for fixing my mistake.

Tom Lavedas
===========