Page 1 of 1 1
Topic Options
#42430 - 2003-07-03 07:04 PM hardware inventory
anna Offline
Getting the hang of it

Registered: 2001-08-21
Posts: 71
Loc: Los Angeles, cA
Hi all,

I am using the following script, but when I write it to a file instead of getting the value for $memory and $model, I get $memory and $model. Can you guys see what am I doing wrong? thanks Anna

$file="c:\batch\mylog.txt"
go "C:"
SHELL 'CMD /X/C "WINMSD /S /F"'
OPEN(1, "@curdir\@WKSTA.TXT")=0
$counter=0
;**************************************
$LINE=READLINE(1)
WHILE @ERROR=0 and $counter<>2
IF INSTR($LINE,"Total Physical Memory")
$counter=$counter+1
$LINE=READLINE(1)
$memory=$LINE
ENDIF
IF INSTR ($line,"System Model")
$counter=$counter+1
$line=readline(1)
$model=$line
endif

IF INSTR($LINE,"Drives Report")
$counter=$counter+1
$LINE=READLINE(1)
$LINE=READLINE(1)
$total=instr($line,"Total:")
$free=instr($line,"KB"+chr(44)+" Free:")
$tot=substr($line,$total+7,$free-$total-7)

endif
$LINE=READLINE(1)
LOOP
$cl=CLOSE(1)
$wri=writeprofilestring ("$file","@wksta","Physical Memory", "$memory")
$wri=writeprofilestring ("$file","@wksta","System Model", "$model")
$wri=Writeprofilestring("$file","@wksta", "C: Drive Size","$tot")

Top
#42431 - 2003-07-03 07:15 PM Re: hardware inventory
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Please read in the KiXtart Manual under SETOPTION('NoVarsInStrings','ON').

You need to move the KiXtart variables to outside the quotes, e.g.
code:
? 'Memory = '+$memory
$wri=Writeprofilestring($file,@wksta, "C: Drive Size",$tot)

_________________________
There are two types of vessels, submarines and targets.

Top
#42432 - 2003-07-03 10:02 PM Re: hardware inventory
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
BTW - If these are W2k or better systems, you may want to look into the use of WMIQUERY() UDF.

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#42433 - 2003-07-03 10:11 PM Re: hardware inventory
anna Offline
Getting the hang of it

Registered: 2001-08-21
Posts: 71
Loc: Los Angeles, cA
Yes, all the computers are w2k. Is there something simple that I can do to get the CPU name, speed, manufacturer and RAM? Can we get these information from the registry?

thanks for all your help

Top
#42434 - 2003-07-03 10:14 PM Re: hardware inventory
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
anna,

I would suggest reading the responses of the UDF here - WMIQuery() - Execute a query against WMI enabled OSs as they provide many examples to help you along.

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#42435 - 2003-07-04 01:24 AM Re: hardware inventory
anna Offline
Getting the hang of it

Registered: 2001-08-21
Posts: 71
Loc: Los Angeles, cA
I read the threads for the WMIQuery I don't know how would I use it? I am not getting it. I have WMI service running. Do I need to call the WMIQuery function from my script? Can u guys help?
Top
#42436 - 2003-07-04 01:56 AM Re: hardware inventory
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Hi Anna, how you doin ? Include the WMIQuery function at the bottom of your script, then call it like in the following script. Assuming your running Kixtart 4 and have WMI running, should return the "make" of your workstation.


Break On

$Make = WMIQuery("Manufacturer","Win32_ComputerSystem")[0]

?"Make=" $Make

Exit 1


FUNCTION WMIQuery($sWhat, $sFrom, Optional $sComputer, Optional $sWhere, Optional $x)
Dim $sQuery, $objEnum, $sValue, $sItem, $lUbound
Dim $aTMP[0]

$sQuery = "Select " + $sWhat + " From "+ $sFrom
If Not $sComputer $sComputer=@WKSTA EndIf
If $sWhere AND $x $sQuery = $sQuery + " Where " + $sWhere + " = '"+$x+"'" EndIf

$SystemSet = GetObject("winmgmts:{impersonationLevel=impersonate}!//"+$sComputer)
If @ERROR Exit VAL("&"+Right(DecToHex(@ERROR),4)) Return EndIf

$objEnum = $SystemSet.ExecQuery($sQuery)
If @ERROR Exit VAL("&"+Right(DecToHex(@ERROR),4)) Return EndIf

For Each $objInstance in $objEnum
If $objInstance
$=Execute("$$sValue = $$objInstance.$sWhat")
Select
Case VarType($sValue) & 8192
For Each $sItem in $sValue
$lUbound = Ubound($aTMP)
If $aTMP[$lUbound] >' '
$lUbound = $lUbound +1
Redim Preserve $aTMP[$lUbound]
EndIf
$aTMP[$lUbound] = Trim($sItem)
Next
Case 1
$lUbound = Ubound($aTMP)
If $aTMP[$lUbound] >' '
$lUbound = $lUbound +1
Redim Preserve $aTMP[$lUbound]
EndIf
$aTMP[$lUbound] = Trim($sValue)
EndSelect
EndIf
Next
$WMIQuery = $aTMP
Exit VAL("&"+Right(DecToHex(@ERROR),4))
ENDFUNCTION


If you need more information regarding "what" is available from "where", just hollar !

-Shawn
-Shawn

Top
#42437 - 2003-07-04 03:41 AM Re: hardware inventory
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Or download the WMI SDK which comes with a WMI Object Browser. Or search for the KiXomatic tool on the KORG BBS. WMI takes a while to get used to, but then you'll love it. And explore the BBS a little bit, there's been a lot posted with regards to inventories, just use the BBS Search extensively.
_________________________
There are two types of vessels, submarines and targets.

Top
#42438 - 2003-07-07 06:51 PM Re: hardware inventory
anna Offline
Getting the hang of it

Registered: 2001-08-21
Posts: 71
Loc: Los Angeles, cA
I think I have kix 3.61 version. To upgrade to 4.0 is it pretty simple and painless?

Anna

Top
#42439 - 2003-07-07 06:55 PM Re: hardware inventory
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Please read the FAQ Forum under Kix upgrade: what are those new features? can upgrade be done without any danger?
_________________________
There are two types of vessels, submarines and targets.

Top
#42440 - 2003-07-07 07:11 PM Re: hardware inventory
anna Offline
Getting the hang of it

Registered: 2001-08-21
Posts: 71
Loc: Los Angeles, cA
Is there another way I can use WMIquery without upgrading it to 4.x? We won't be doing an upgrade anytime soon and I need to get a hardware inventory out this week. I'd appreciate any advise. thanks all
Anna

Top
#42441 - 2003-07-07 07:30 PM Re: hardware inventory
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
WMI requires COM, which requires KiXtart 4.x. you can always run KiXtart 4.x from a central location without rolling it out to all clients. Alternatively, see http://home.wanadoo.nl/scripting/index-kix-scripts.htm
_________________________
There are two types of vessels, submarines and targets.

Top
#42442 - 2003-07-07 08:24 PM Re: hardware inventory
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Unless ... you want to port WMIQuery to use the old OLExxx functions - which will work under 3.x but looks damn ugly.

For the adventurous ...

Whimmy ...

-Shawn

oh and btw, when I said "port" WMIQuery to 3.x, meant to say "turn it into a sub-routine" [Wink]

[ 07. July 2003, 20:31: Message edited by: Shawn ]

Top
#42443 - 2003-07-07 09:53 PM Re: hardware inventory
anna Offline
Getting the hang of it

Registered: 2001-08-21
Posts: 71
Loc: Los Angeles, cA
I was able to get most of the needed information from registry entry, except the RAM. I came across the memory.kix, but haven't figured out how to get the result. Do I call the memory.kix script within my script? How do I get the result? when I run the script where does it write the value? thanks
Anna

Top
#42444 - 2003-07-08 02:51 PM Re: hardware inventory
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
anna,

Provided you have a list of computers, you can do this remotely and all you need is to run KiXtart 4.x from your local workstation, for example.

If you don't have the list of computers, you should be able to generate the list from AD users and computers, Hyena, or I believe that there are a couple of AD Scripts here that can do just that.

Here goes -


$logshare='c:\'
$logfile=$logshare+'Inventory.TXT'
      $oXL=Createobject('Excel.application')
      ;Check to insure that Excel is available
      IF 0<>@error ?@error ' Excel Application is not found' 
            SLEEP 4 
            RETURN 
      ENDIF
      $Rc=$oXL.workbooks.open("C:\Yourexcelfile.xls")
      $Row=1
      WHILE $oXL.cells($Row,1).value<>''
            $Row=$Row+1
            IF $oXL.cells($Row,1).value='' ;Once it gets to a blank row...
                  $oXL.quit ;quit Excel
                  $oXL=0 ;set the object to 0
            ELSE
                  $b=$oXL.cells($Row,1)
                  $b ;Print out results
        for each $stick in WMIQuery("Capacity","Win32_PhysicalMemory",$b)
        $MEMval($stick) / 1048576
        $logdata=$b+','+$MEM+@CRLF
        LOGGER($logshare,$logdata)
        next
            ENDIF
      LOOP


; ref - http://www.kixtart.org/board/ultimatebb.php?ubb=get_topic;f=12;t=000117
FUNCTION WMIQuery($sWhat$sFromOptional $sComputerOptional $sWhereOptional $x)
    Dim $sQuery$objEnum$sValue$sItem$lUbound
    Dim $aTMP[0]

     $sQuery = "Select " + $sWhat + " From "$sFrom
    If Not $sComputer    $sComputer=@WKSTA    EndIf
    If $sWhere AND $x     $sQuery = $sQuery + " Where " + $sWhere + " = '"+$x+"'"    EndIf

     $SystemSet = GetObject("winmgmts:{impersonationLevel=impersonate}!//"+$sComputer)
         If @ERROR     Exit VAL("&"+Right(DecToHex(@ERROR),4))     Return     EndIf

    $objEnum = $SystemSet.ExecQuery($sQuery)
        If @ERROR     Exit VAL("&"+Right(DecToHex(@ERROR),4))     Return     EndIf

      For Each $objInstance in $objEnum
        If $objInstance
            $=Execute("$$sValue = $$objInstance.$sWhat")
            Select
                Case VarType($sValue) & 8192
                    For Each $sItem in $sValue
                        $lUbound = Ubound($aTMP)
                        If $aTMP[$lUbound] >' '
                            $lUbound = $lUbound +1
                            Redim Preserve $aTMP[$lUbound]
                            EndIf
                        $aTMP[$lUbound] = Trim($sItem)
                        Next
                Case 1
                    $lUbound = Ubound($aTMP)
                    If $aTMP[$lUbound] >' '
                        $lUbound = $lUbound +1
                        Redim Preserve $aTMP[$lUbound]
                        EndIf
                    $aTMP[$lUbound] = Trim($sValue)
                EndSelect
            EndIf
        Next
    $WMIQuery = $aTMP
    Exit VAL("&"+Right(DecToHex(@ERROR),4))
ENDFUNCTION

;ref - http://www.kixtart.org/board/ultimatebb.php?ubb=get_topic;f=12;t=000295
FUNCTION LOGGER($logfile,$logdata)
  DIM $n
  WHILE Open(1$logfile5) OR $n=5
   IF $n
    '.'
   ELSE
    ?'Please wait'
   ENDIF
   $n=$n+1
   SLEEP 3
  LOOP
  $n=WriteLine(1$logdata)
  $n=Close(1)
 ENDFUNCTION



HTH,

Kent

[ 08. July 2003, 16:21: Message edited by: kdyer ]
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
Page 1 of 1 1


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

Who's Online
1 registered (Allen) and 1198 anonymous users online.
Newest Members
M_Moore, BeeEm, min_seow, Audio, Hoschi
17883 Registered Users

Generated in 0.073 seconds in which 0.028 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