Page 1 of 1 1
Topic Options
#77291 - 2003-10-29 04:44 PM WMI
Bob Deerinwater Offline
Starting to like KiXtart

Registered: 2002-05-05
Posts: 101
Loc: Covina California
I have found a wmi script that will get the drive size, but it works half the time. it appears that if the drive is less than 10 gig it will not work. Here is the code
code:
 
$objWMIService = GetObject( "winmgmts://./root/cimv2" )
If @ERROR
GoTo ShowError
EndIf
$colItem1 = $objWMIService.ExecQuery( "Select * from Win32_Processor", , 48 )
$colItem2 = $objWMIService.ExecQuery( "Select * from Win32_LogicalMemoryConfiguration", , 48 )
$colItem3 = $objWMIService.ExecQuery( "Select * from Win32_DiskDrive", , 48 )

For Each $objItem In $colItem1
$clockspeed = $objItem.CurrentClockSpeed
Next
For Each $objItem In $colItem2
$memory=( ( $objItem.TotalPhysicalMemory + 1023 ) / 1024 )
Next
For Each $objItem In $colItem3
$Sice = $objItem.Size
$LSize = Len( $Sice )
$MSize = SubStr( $Sice, 1, $LSize - 3 )
$Size = ( 524288 + $MSize ) / 1048576
Next


Top
#77292 - 2003-10-29 05:18 PM Re: WMI
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
have a look at WMIQuery() UDF
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#77293 - 2003-10-29 06:16 PM Re: WMI
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
And what is this about?
code:
$Sice  = $objItem.Size
$LSize = Len( $Sice )
$MSize = SubStr( $Sice, 1, $LSize - 3 )
$Size = ( 524288 + $MSize ) / 1048576

Can you please explain the reasons for this, maybe even line by line?

.Size returns the size in bytes, it should be easy to convert to Megabytes or GigaBytes by dividing with the appropriate conversion factor.

[ 29. October 2003, 19:13: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.

Top
#77294 - 2003-10-29 06:57 PM Re: WMI
Bob Deerinwater Offline
Starting to like KiXtart

Registered: 2002-05-05
Posts: 101
Loc: Covina California
I copied this code from another place and after runing it out on paper it basically puthe the drive information into a 2 character number. that is what i am assuming at this time. i could be wrong. What i am going for is to put the drive into a one or 2 character number ie...4 10 20 to determine the drive in gigabytes. if there is another way i would be up for any suggestions
Top
#77295 - 2003-10-29 07:08 PM Re: WMI
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
$HD =WMIQuery("Size","Win32_DiskDrive")[0]
$hdGB =left($hd,len($hd)-9)
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#77296 - 2003-10-29 07:15 PM Re: WMI
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
code:
$KB=cdbl(WMIQuery("Size","Win32_DiskDrive")[0])/1024
$MB=$KB/1024
$GB=$MB/1024

would give you correct sizes.
_________________________
There are two types of vessels, submarines and targets.

Top
#77297 - 2003-10-29 07:23 PM Re: WMI
Bob Deerinwater Offline
Starting to like KiXtart

Registered: 2002-05-05
Posts: 101
Loc: Covina California
I feel just a little stupid right now. Did not even think of removing the last 9 characters. Thank You
Top
#77298 - 2003-10-29 07:26 PM Re: WMI
Bob Deerinwater Offline
Starting to like KiXtart

Registered: 2002-05-05
Posts: 101
Loc: Covina California
i am not using the wmiquery() udf as of now so this is what i did. I do not have any drive less that 1gig so it shouls work
code:
For Each $objItem In $colItem3
$hd = $objItem.Size
$hdGB =Left($hd,Len($hd)-9)
Next


Top
#77299 - 2003-10-29 07:38 PM Re: WMI
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Still, the issue is that $hdGB =Left($hd,Len($hd)-9) will give you incorrect values!
1024 Byte = 1 KiloByte
1024 KiloBytes = 1 MegaByte
1024 MegaBytes = 1 Gigabyte

What you do is 1000 bytes = 1 KiloByte !

Granted, HD manufacturers use this to artificially boots the capacity of the drive, but those nobers are just plain incorrect!
_________________________
There are two types of vessels, submarines and targets.

Top
#77300 - 2003-10-29 08:17 PM Re: WMI
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
it works fine for my 6, 10, 20, and 40 gb drives [Cool]
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#77301 - 2003-10-29 08:26 PM Re: WMI
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
yep, it takes about zillion zeros in the number to affect the meaningfull ones...
_________________________
!

download KiXnet

Top
#77302 - 2003-10-29 09:25 PM Re: WMI
Bob Deerinwater Offline
Starting to like KiXtart

Registered: 2002-05-05
Posts: 101
Loc: Covina California
I keep getting erro on expression when i use
code:
$mb=$kb/1024


Top
#77303 - 2003-10-29 09:30 PM Re: WMI
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
sure as your $kb is string.
you can't devide strings.

[ 29. October 2003, 21:41: Message edited by: Lonkero ]
_________________________
!

download KiXnet

Top
#77304 - 2003-10-29 09:36 PM Re: WMI
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
My $KB is double as I convert the initial byte number to double via CDBL().
_________________________
There are two types of vessels, submarines and targets.

Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 675 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.071 seconds in which 0.032 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org