Jump to content
Strawberry Orange Banana Lime Leaf Slate Sky Blueberry Grape Watermelon Chocolate Marble
Strawberry Orange Banana Lime Leaf Slate Sky Blueberry Grape Watermelon Chocolate Marble

MSFN is made available via donations, subscriptions and advertising revenue. The use of ad-blocking software hurts the site. Please disable ad-blocking software or set an exception for MSFN. Alternatively, register and become a site sponsor/subscriber and ads will be disabled automatically. 


Sign in to follow this  
eyeball

can i have a little help with a vbs script please?

Recommended Posts

Hi all,

i have a .vbs script that can audit an ip range and collect data. it collects such things as the operating system, RAM etc.

basically i want to add in another WMI called win32_SoftwareFeature and use the value "ProductName" to tell me what software is installed on the machine

the .vbs script exports what it finds to an excel file i have been trying to do this almost all day and failed miserably lol please i know someone will find this a walk in the park, can anyone help me add this in?

below is a link to the script

http://www.megaworm.com/images/./data/media/4/auditor.zip

many thanks

Share this post


Link to post
Share on other sites

It's going to take me a little while to look over all that code and put it what you're looking for, but FWIW there's some pretty kick a** stuff in that script. It'll certainly teach me a thing or two while trying to solve your problem.

Share this post


Link to post
Share on other sites

cool thanks for looking :) yes its a very very useful script indeed and i have learnt loads from just reading through it and experimenting

unfortunatly im not good with arrays and its what (i assume) i need to implement software audits within this script. so if you could help me roguespear i would be very grateful :)

Share this post


Link to post
Share on other sites

I have been looking at the script and it is pretty messed up here is One example of

what I have found incorrect

You have this Two times and no Close for it.

This is at Line 39 and Line 61 in the script.

set fx = fsox.OpenTextFile(outputFile, ForWriting, True)

Here is what I have made for you to work with

'''' ***** - SCRIPT BY GUNSMOKINGMAN - ***** ''''
'''' ***** - http://gunsmokingman.ath.cx/ - ***** ''''
strComputer = "."
'''' *********************************************************************************
'''' VARIBLES FOR THE SCRIPT
Dim ComputerReport, Comp, CompReport '''' --> colComputer
Dim BDate, BiosReportDate '''' --> Bios
Dim OsName, N1, Ver '''' --> OsInfo

'''' *********************************************************************************
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colComputer = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem",,48)
Set Bios = objWMIService.ExecQuery("SELECT * FROM Win32_BIOS",,48)
Set Os = objWMIService.ExecQuery( "SELECT * FROM Win32_OperatingSystem",,48)
'''' *********************************************************************************
'''' --> colComputer
For Each objComputer in colComputer
Comp = Split(objComputer.UserName,"\")
CompReport = "Computer Name : " & Comp(0) & vbCrLf & "User Name : " & Comp(1)
MB = 1024 * 1024 : Ram = FormatNumber(objComputer.TotalPhysicalMemory / MB,1)
ComputerReport = CompReport & Vbcrlf & "Total Physical Memory : " & Ram & " MB" &_
vbCrLf & "Model : " & objComputer.Model
Next
'''' *********************************************************************************
'''' --> Bios
For Each objBios in Bios
BDate = Left(objBios.ReleaseDate,8) : DateBios
BiosReportDate = BiosReportDate & vbCrLf & "Manufacturer : " & objBios.Manufacturer & vbCrLf &_
"Bios Version : " & objBios.Version
Next
'''' *********************************************************************************
'''' --> OsInfo
Set OsInfo = objWMIService.ExecQuery( "SELECT * FROM Win32_OperatingSystem",,48)
For Each objOs in OsInfo
Ver = "-Build-" & objOs.BuildNumber : N1 = Split(objOs.Name,"|")
OsName = "Operating System Name : " & vbCrLf & N1(0) & Ver
Next
'''' *********************************************************************************
'''' CONVERTS THE BIOS DATE FORMAT
Function DateBios
BDate1 = Left(BDate,4) : BDate2 = Right(BDate,4)
BDate2a = Left(BDate2,2) : BDate3 = Right(BDate2,2)
BiosReportDate = "Bios Release Date : " & BDate1 & "-" & BDate2a & "-" & BDate3
End Function
'''' *********************************************************************************

MsgBox ComputerReport & vbCrLf & BiosReportDate & vbCrLf & OsName, 0 + 32, "Computer Information"

I will repost some more in the next couple of days if you want. I am not a coder but I will try my best

to get it working properly for you.

Share this post


Link to post
Share on other sites

thanks GunSmokingMan thats great start, certainly is more organised but you cut the best part of the script! - the output to a .xls, unless you were going to implement this later?

anyway that definately gives me something to work on, and im confident i could add more WMI's in there, the only thing i would have trouble with would be arrays like i say.

thanks for the help :thumbup

Share this post


Link to post
Share on other sites
basically i want to add in another WMI called win32_SoftwareFeature and use the value "ProductName" to tell me what software is installed on the machine

I think I'll just let GSM handle this one as he seems to be actively working on it now. What I was going to implement was something using Win32_Product instead of Win32_SoftwareFeature. I just wrote this script yesterday for someone in a different forum:

Option Explicit
Dim ws, fs, strComputer, objWMIService, colSoftware, objSoftware
Set ws = WScript.CreateObject("WScript.Shell")
Set fs = CreateObject("Scripting.FileSystemObject")
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSoftware = objWMIService.ExecQuery("Select * from Win32_Product")
For Each objSoftware in colSoftware
If Left(objSoftware.Name, 12) = "Adobe Reader" Then
WScript.Echo objSoftware.Name & " is installed."
WScript.Echo "The installed version is: " & objSoftware.Version
End If
Next

Edited by RogueSpear

Share this post


Link to post
Share on other sites

Hey RoqueSpear any help from you would be appreciated, I used what you posted in this script.

This now produces a text file with all the information in it. I will be adding more of the WMI classes

I just want to make sure this is the information you want to collect.

'''' ***** - SCRIPT BY GUNSMOKINGMAN, ROQUESPEAR - ***** ''''
'''' ***** - http://gunsmokingman.ath.cx/ - ***** ''''
Dim strComputer : strComputer = "."
'''' *********************************************************************************
'''' VARIBLES FOR THE SCRIPT
Dim colComputer, objComputer, ComputerReport, Comp, CompReport '''' --> colComputer
Dim Bios, objBios, BiosDate, BiosReportDate '''' --> Bios
Dim objProc, Processor, Proc, ProcReport, Speed '''' --> Processor
Dim IDate, InstallDate, OsName, N1, Ver '''' --> OsInfo
Dim InstalledSotware, Software, SWName, SWVer '''' --> Software
Dim BDate, BDate1, BDate2, BDate2a, BDate3 '''' Conver Wmi Date Format
Dim Ts , S_3, S_5 '''' --> Text Output
S_3 = Space(3) : S_5 = Space(5) '''' Space Varibles
'''' *********************************************************************************
'''' VARIBLES AND OBJECTS FOR SCRIPT
Dim Act : Set Act = CreateObject("Wscript.Shell")
Dim Fso : Set Fso = CreateObject("Scripting.FileSystemObject")
Dim DTop : DTop = Act.SpecialFolders("Desktop")
'''' *********************************************************************************
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
'''' *********************************************************************************
'''' --> colComputer
Set colComputer = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem",,48)
For Each objComputer in colComputer
Comp = Split(objComputer.UserName,"\")
CompReport = S_3 & "Computer Name : " & Comp(0) & vbCrLf & S_3 & "User Name : " & Comp(1)
MB = 1024 * 1024 : Ram = FormatNumber(objComputer.TotalPhysicalMemory / MB,1)
ComputerReport = CompReport & Vbcrlf & S_3 & "Total Physical Memory : " & Ram & " MB" &_
vbCrLf & S_3 & "Model : " & objComputer.Model
Next
'''' *********************************************************************************
'''' --> Bios
Set Bios = objWMIService.ExecQuery("SELECT * FROM Win32_BIOS",,48)
For Each objBios in Bios
BDate = Left(objBios.ReleaseDate,8)
BDate1 = Left(BDate,4) : BDate2 = Right(BDate,4)
BDate2a = Left(BDate2,2) : BDate3 = Right(BDate2,2)
BiosReportDate = "Bios Release Date : " & BDate1 & "-" & BDate2a & "-" & BDate3
BiosReportDate = S_3 & BiosReportDate & vbCrLf & S_3 &_
"Manufacturer : " & objBios.Manufacturer & vbCrLf & S_3 &_
"Bios Version : " & objBios.Version
Next
'''' *********************************************************************************
'''' --> Processor
Set Processor = objWMIService.ExecQuery( "SELECT * FROM Win32_Processor",,48)
For Each objProc in Processor
Proc = S_3 & "Processor Name : " & objProc.Name : Speed = S_3 & "Processor Speed : " & objProc.MaxClockSpeed & " MHZ"
ProcReport = S_5 & "Cpu Report" & vbCrLf & Proc & vbCrLf & Speed & vbCrLf
Next
'''' *********************************************************************************
'''' --> OsInfo
Set OsInfo = objWMIService.ExecQuery( "SELECT * FROM Win32_OperatingSystem",,48)
For Each objOs in OsInfo
BDate = Left(objOs.InstallDate,8)
BDate1 = Left(BDate,4) : BDate2 = Right(BDate,4)
BDate2a = Left(BDate2,2) : BDate3 = Right(BDate2,2)
InstallDate = "Install Date : " & BDate1 & "-" & BDate2a & "-" & BDate3
Ver = "-Build-" & objOs.BuildNumber : N1 = Split(objOs.Name,"|")
OsName = S_5 & "Operating System Name" & vbCrLf & S_3 & N1(0) & Ver & vbCrLf & S_3 & InstallDate & vbCrLf
Next
'''' *********************************************************************************
'''' --> Software **** MADE BY ROQUESPEAR
Set Software = objWMIService.ExecQuery("Select * from Win32_Product",,48)
For Each objSoftware in Software
SWName = S_3 & "Installed Software : " & objSoftware.Name
SWVer = S_3 & "Version : " & objSoftware.Version
InstalledSotware = InstalledSotware & vbCrLf & SWName & Vbcrlf & SWVer & vbCrLf & S_3 & Chr(171) & " ------------ " & Chr(187)
Next
'''' *********************************************************************************
'''' TEXT FILE OUTPUT
Set Ts = Fso.CreateTextFile(DTop & "\ComputerReport.txt")
Ts.WriteLine S_5 & Chr(171) & " ***** Computer Report " & Now() & " ***** " & Chr(187) & vbCrLf
Ts.WriteLine S_5 & "Computer Information" & vbCrLf & ComputerReport & vbCrLf & BiosReportDate & vbCrLf
Ts.WriteLine ProcReport & vbCrLf & OsName
Ts.WriteLine S_5 & "SoftWare" & InstalledSotware
Ts.Close
Act.Run(Chr(34) & DTop & "\ComputerReport.txt" & Chr(34))

Share this post


Link to post
Share on other sites

thanks for the help RogueSpear :) much appreciated and gunsmokingman im sorry i didnt mean to sound rude when i said you left out the best bit :) im glad you are putting in and glad you are having a look at the script, i hope you find it of some use to you in the future :thumbup

Share this post


Link to post
Share on other sites

@GSM, very nice work there :thumbup If you run into something you want me to take a look at, please let me know. I'm pretty beyond busy right now with too many things going on.

Share this post


Link to post
Share on other sites

Eyeball could you list what you need for the Computer Info, I want to collect all information then we can try and get the Xls stuff to work. Could you give the newest posted script a try and tell me if it suitable for you.

RoqueSpear if you need any help for your projects I may be able to help.

Share this post


Link to post
Share on other sites

hi Gsm ok that sounds like a good idea, this list will just be a basic one, if you can think of any more WMI's to add in that would be useful then please add them :). ok heres the list with the value and the WMI class it comes from:

pc hostname - win32_NetworkAdapterConfiguration

domain + role- win32_computerSystemProduct

Make, Model + Serial Number - win32_computerSystemProduct

Total Ram - from Win32_logicalMemoryConfiguration

****also would be nice to know how many memory slots the board has and which ones are used and which ones are empty cpu-z can do this and i dont know how

OS + ServicePacks - from win32_OperatingSystem

Bios Revision - from win32_Bios or win32_systembios

Processor Type - Win32_Processor

***dual core show up as 2 cpu's, and i cant find a way around this****

logged in user - win32_computersystem

NIC Model (1-4) - win32_NetworkAdapter

sn mask, d g/w, IP, MAC address - win32_NetworkAdapterConfiguration

Hdd space + names + number - win32_DiskDrive

also win32_DiskDrivePhysicalMedia tells you the number of physical disks in a system

Partition Info for each disk drive - win32_DiskPartition (shows partitions and their sizes! - v useful)

page file location+ size could be useful - win32_pagefile

scsi controller make model - win32_scsiController - v useful for servers

show tapedrive make + model - again useful for servers found from win32_tapedrive

thats all Gsm hope this isnt too much, and if theres anything i can try to help with i will

thank you so much :) hopefully almost everyone on the board will find a use for the final script and not just us two :)

Edited by eyeball

Share this post


Link to post
Share on other sites

Programs like CPU-Z, Motherboard Monitor, etc are not using WMI for the reporting. I'm not sure exactly what it is that they're doing, but you'll probably notice that programs like that need to be continually updated as new chipset and motherboards are released.

Share this post


Link to post
Share on other sites

yeah i did try that new one Gsm and its great :) i cant wait for the full one!

also rougespear i noticed that too as i had a win 2000 server that cpu z couldnt detect the motherboard as it was too old but through WMI i could get it, so im not exactly sure what it uses

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...