Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

retrieve memory size without using WMI

Status
Not open for further replies.

toeter

Technical User
Apr 29, 2003
33
DE
Does anyone know how to retrieve
a client's physical memory size
without using WMI, so only using
Windows Scripting Host

somethiong like this:

Set Wshell = CreateObject("WScript.Shell")
Set OS = Wshell.Environment("Process")
Wscript.Echo OS("OS")

But then for retrieving memory
 
Is there a reason you can't use WMI? It is certainly more appropriate for this need.

Anyway, this will do what you have asked:

'==========================================================================
'
' NAME: GetMemWithoutWMI.vbs
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL: ' DATE : 1/29/2004
'
' COMMENT: retrieve system memory without using WMI
'
'==========================================================================

On Error Resume Next

'open the file system object
Set oFSO = CreateObject("Scripting.FileSystemObject")
set WSHShell = wscript.createObject("wscript.shell")

Call WSHShell.Run("cmd.exe /C mem >C:\Memory.txt")
'open the data file
Set oTextStream = oFSO.OpenTextFile("C:\Memory.txt")

'make an array from the data file
MemText = Split(oTextStream.ReadAll, vbNewLine)
'close the data file
oTextStream.Close

Report = ""

For Each line In MemText
Report = Report & line & vbCrLf
Next

MsgBox Report
 
Yeah there is,

it isn't supported on Win98..
(or is it?)

thx
 
Yes, WMI is supported on Win98. You need to install the WMI Core which is a free download from the MS site. You also then need to set some registry settings if you want to use WMI remotely. If you can go that route let me know and I will write a script for the registry settings. (I've been meaning to do that for a while now anyway).
 
This is the problem:

I need to retrieve system information from a clients PC
(OS, MEM, HARDDISKS-size, CPU) on 98/2000/ME/XP

This VBS script is run on someones PC, with 98/2000/ME/XP and normelary this gives back the users CPU clock speed,
at least in XP and 2000 but not in 98 or ME.

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Processor")
For Each objItem in colItems
SysCPU = "Current Clock Speed: " & objItem.CurrentClockSpeed&"Mhz"
Next

So you say there is a way to use remote WMI?

Or do you know another way to retrieve this information (OS, MEM, HARDDISKS-size, CPU) without using WMI?

=> I know you can find CPU type in registry
=> And Disksizes via the 'CreateObject "Scripting.FileSystemObject")- method and then retrieve its properties'
=> But I dont know how to retrieve Memory size (512MB orso) and the Operating System (WInXP or 98)





 
You can do it all with WMI remotely. I'll put a script together for you with instructions. Give me a day or two due to my work schedule.
 
OK, here you go.

I'll do a few posts here for you to make this easier to follow.

You first need to install the WMICore from Microsoft.com/Scripting/.

Next run this script on a 9x box. (I don't have a 9x machine so it is untested, please provide feedback)

Reboot the 9x machine and WMI is enabled on your 9x machines.




'==========================================================================
'
' NAME: enableWMI9x.vbs
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL: ' DATE : 1/29/2004
'
' COMMENT: Sets registry keys to enable WMI on Win9x computers.
'
'==========================================================================

on error resume next

Dim path

Set WSHShell = Wscript.CreateObject("WScript.Shell")
SET oFSO = Wscript.CreateObject("Scripting.FileSystemObject")
'set the key path here. IF you don't end with a '\' then WSH assumes you are pathing to a value.
path = "HKLM\Software\Microsoft\"

WSHShell.RegWrite path & "OLE\EnableDCOM","Y","REG_SZ"
WSHShell.RegWrite path & "OLE\EnableRemoteConnect","Y","REG_SZ"
WSHShell.RegWrite path & "WBEM\cimom\EnableAnonConnections","1","REG_SZ"
WSHShell.RegWrite path & "WBEM\cimom\AutostartWin9x","1","REG_SZ"

strSup = WshShell.SpecialFolders("Startup")
strshortcut = strSup & "\WindowsManagement.lnk"
If Not oFSO.FileExists(strshortcut) Then
SET oUrlLink = WshShell.CreateShortcut(strshortcut)
oUrlLink.TargetPath = "C:\WINDOWS\SYSTEM\WBEM\WINMGMT.EXE"
oUrlLink.Save
End If
 
Part 2: Scripting WMI for Remote Access

Log into your workstation with ADMIN priviledges.

Create an Excel Spreadsheet with the following headings in Row 1:

Computername,Verified Name,Memory,CPU,Disk Size,Free Space,OS Name,Build Number

In column 1 put the names of all the workstations you want to inventory.

Leave Excel OPEN

Next run this script which will inventory the computers and put the info into Excel. Note that I verify the computer name, this helps identify bad entries in DNS:

'==========================================================================
'
' NAME: <MemProcDiskInventory.vbs>
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL: ' DATE : 2/5/2003
'
' COMMENT: <Inventories computer configurations from a list of computers>
' REVISIONS: 4/18/2003 added support for disk size and free disk space
' 1/30/2004 added support for os name and build number
'==========================================================================
on error resume next

set x = getobject(,&quot;excel.application&quot;)
r = 2
do until len(x.cells(r, 1).value) = 0
strComputer = x.cells(r, 1).Value

Set objWMIService = GetObject(&quot;winmgmts:&quot; _
& &quot;{impersonationLevel=impersonate}!\\&quot; & strComputer & &quot;\root\cimv2&quot;)
Set colSettings = objWMIService.ExecQuery _
(&quot;Select * from Win32_OperatingSystem&quot;)
For Each OS In colSettings
x.cells(2, 7).value = OS.Caption
x.cells(2, 8).value = OS.Version
Next
Set colSettings = objWMIService.ExecQuery _
(&quot;Select * from Win32_ComputerSystem&quot;)
For Each objComputer in colSettings
x.cells(r, 2).value = objComputer.Name
x.cells(r, 3).value = objComputer.TotalPhysicalMemory /1024\1024+1 & &quot;MB&quot;
Next
Set colSettings = objWMIService.ExecQuery _
(&quot;Select * from Win32_Processor&quot;)
For Each objProcessor in colSettings
x.cells(r, 4).value = objProcessor.Description
Next


Set objWMIService = GetObject(&quot;winmgmts:&quot;)
Set objLogicalDisk = objWMIService.Get(&quot;Win32_LogicalDisk.DeviceID='c:'&quot;)
x.cells(r, 5).value = objLogicalDisk.Size /1024\1024+1 & &quot;MB&quot;
x.cells(r, 6).value = objLogicalDisk.FreeSpace /1024\1024+1 & &quot;MB&quot;

r = r + 1
loop
 
Hey Mark, thx
Going to test everything, I'll give feedback if it works

But another a question:

&quot;&quot;You first need to install the WMICore from Microsoft.com/Scripting/&quot;&quot;

Can I take this (WMICore) with me on a &quot;Floppydisk&quot;
And when I execute the VBS-Script (to retrieve System-information)it checks wether WMI is installed or not and if not otherwise it will install WMIcore (from the floppydisk)...

Toeter
 
Damn it's 6-7 MB

Not very Floppy Friendly, but anyways, Could burn it on a CD-Rom

Just need to be able to install via the script
 
I agree with PHV, while visiting those boxes I would also install IE6 OR just install the WSH 5.6 update directly.
 
Say, Is there really no other way to retrieve Running Operating System and Memory installed?

maybe in registry?

Toeter...

 
Hello Toeter,

For the memory, under your imposed restriction, I would use a little/tiny freeware utility, memlog.exe by J Fitzgibbon (or any other similar utility out there, I am sure plenty) apt for cmdline interactive. You can download it from:

The reason I need this is just because the good old mem.exe just won't interact well with WshShell.Exec. In fact, WshShell.Exec cannot capture the stdout from it (and hang!)---this is a common feature of some commandline legacy utility. The utility, memlog, is stand-alone, no installation is needed.

From its output of a comma-delimited line, isolate the 5th data (0-base) for physical memory size. (In fact, you can do more with it. It's all up to you.) Here is a possible coding to get you started.
Code:
'Edit your path here
const memlog_path=&quot;d:\net_download\memlog&quot;

set wshshell=createobject(&quot;wscript.shell&quot;)
set oExec=wshshell.exec(memlog_path & &quot;\memlog 0&quot;)
do while oExec.status=0
	wscript.sleep 100
loop
sOut=oExec.StdOut.Readall
set oExec=nothing
set wshshell=nothing

wscript.echo &quot;Physical Memory size (byte) : &quot; & split(sOut,&quot;,&quot;)(5)
'wscript.echo sOut
regards - tsuji
 
Hi Toeter,

You have a lot that you can work with here. I just want to toss in my 2 cents worth and say that it seems to me like you are putting unnecessary restrictions on yourself. You don't need to carry WMICore around on a CD, just install it from a network share. Since your talking about 98 boxes which don't have security, why not ask your users to launch it? Or have it launched by a login script?

It just seems to me that you are looking to avoid a small bit of work for what would save you lots of time by opening up remote management of these antiquated systems.

Regards,

Mark
 
Thx All,

but the reason for the floppy disk or CD is that the Client's PC is not on a network or internet.

It 'can' be but it has to work n all occasions

grtz

Toeter
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top