Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 906
  • Last Modified:

VB script writes system info.

Hello,

I need a sample VB script file which will write system info.(OS,version,computer name, current user,Physical Memory, IP Addr, MAC Addr,Harddrive space..) into a text file. The text file needs to be located on desktop.

Thanks.
0
mrong
Asked:
mrong
  • 4
  • 3
1 Solution
 
jimbobmcgeeCommented:
Your best bet lies with the WMI.  You can get some details on this at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/wmi_start_page.asp
0
 
thunder_mooseCommented:
Hi there,

As the previous poster mentioned, you can use WMI to do it. Here's a VBScript for WSH that does what you want. To use it, open notepad, paste the code there, save it as a .vbs file and use cscript from the command promt to run it as follows: cscript filename.vbs

It saves the info in a file called info.txt on the desktop. This script assumes you have Windows 2000 or later.

Dim strComputerName, strDesktopPath
Dim objWMIService, objQryOS, objOS
Dim objQryNetwork, objNIC, objQryDisks, objDisk
Dim objQryCompSys, objComp
Dim objWSHShell
Dim objFSO, objTxtInfo

strComputername = "."

Set objWSHShell = CreateObject("WScript.Shell")
strDesktopPath = objWSHShell.SpecialFolders("Desktop")

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTxtInfo = objFSO.CreateTextFile(strDesktopPath & "\Info.txt")
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" _
    & strComputerName & "\root\cimv2")

Set objQryOS = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem")
Set objQryNetwork = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration", , 48)
Set objQryDisks = objWMIService.ExecQuery("SELECT * FROM Win32_LogicalDisk")
Set objQryCompSys = objWMIService.ExecQuery("Select * from Win32_ComputerSystem")

For Each objComp in objQryCompSys
    objTxtInfo.WriteLine "User Name: " & objComp.UserName
    objTxtInfo.WriteLine "Computer Name: " & objComp.Name
    objTxtInfo.WriteLine "Physical Memory: " & objComp.TotalPhysicalMemory & " bytes"
Next

For Each objOS In objQryOS
    objTxtInfo.Writeline "OS Name: " & objOS.Name
    objTxtInfo.WriteLine "OS Version: " & objOS.Version
Next

For Each objNIC in objQryNetwork
    If Not IsNull(objNic.IPAddress) Then
       For I=LBound(objNIC.IPAddress) to UBound(objNIC.IPAddress)
           objTxtInfo.WriteLine "IP Address: " & objNIC.IPAddress(I)
       Next
       objTxtInfo.WriteLine "MAC Address: " & objNIC.MACAddress
    End If
Next

For Each objDisk in objQryDisks
    objTxtInfo.WriteLine "Disk Drive: " & objDisk.DeviceID & _
                         "(" & objDisk.FreeSpace & " bytes free)"
Next

objTxtInfo.Close

Set objTxtInfo = Nothing
Set objFSO = Nothing
Set objWSHShell = Nothing
Set objWMIService = Nothing


Hope that helps you,
Cheers,
thunder_moose
0
 
mrongAuthor Commented:
Hi thunder_moose,

I got OS Name: Microsoft Windows 2000 Professional|C:\WINNT|\Device\Harddisk0\Partition1. Is it possible to get rid of " |C:\WINNT|\Device\Harddisk0\Partition1" ?

Also your VBscript will get free hard drive space, Can you get available space as well? I only need disk space info for drive C and D. How to change the code?

Thanks.
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
mrongAuthor Commented:
Is this code also work for WinXP? what happens if run it on Win98 or 95?

Thanks.
0
 
thunder_mooseCommented:
Hi Mrong,

To answer your last questions first, yes the script will work on Windows XP. It can work on Windows 98, ME and NT4.0 as well but you'll have to install WSH for Windows 9x. You can get that here:

http://www.microsoft.com/downloads/details.aspx?FamilyID=0a8a18f6-249c-4a72-bfcf-fc6af26dc390&displaylang=en

I'm not sure if it'll work on 95, but can't think of a real reason why it shouldn't.

As for your other queries. The first is simple text manipulation. Replace the line

   objTxtInfo.Writeline "OS Name: " & objOS.Name

with

   strOSName = objOS.Name
   intEnd = instr(strOSName, "|") - 2
   strOSName = Mid(strOSName, 1, intEnd)
   objTxtInfo.Writeline "OS Name: " & strOSName

To show the capacity of the drive, just add this line:

    objTxtInfo.WriteLine "Total Disk Space: " & objDisk.Size

In the section dealing with the hard disk size (under For Each objDisk...)

If you want to convert it to MegaBytes instead, use: objDisk.Size / (1024*1024)

Once again, I hope this helps
thunder_moose
0
 
thunder_mooseCommented:
Oh yes, almost missed your other question:

To only display drives C & D's sizes you have to change the diskdrive code to:

If objDisk.DeviceID = "c:" OR objDisk.DeviceID = "d:" Then
.....
End if

But I realise that all this might be pretty confusing, so here's the entirety of the code again, with the modifications that you requested.

Dim strComputerName, strDesktopPath
Dim objWMIService, objQryOS, objOS
Dim objQryNetwork, objNIC, objQryDisks, objDisk
Dim objQryCompSys, objComp
Dim objWSHShell
Dim objFSO, objTxtInfo

strComputername = "."

Set objWSHShell = CreateObject("WScript.Shell")
strDesktopPath = objWSHShell.SpecialFolders("Desktop")

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTxtInfo = objFSO.CreateTextFile(strDesktopPath & "\Info.txt")
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" _
    & strComputerName & "\root\cimv2")

Set objQryOS = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem")
Set objQryNetwork = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration", , 48)
Set objQryDisks = objWMIService.ExecQuery("SELECT * FROM Win32_LogicalDisk")
Set objQryCompSys = objWMIService.ExecQuery("Select * from Win32_ComputerSystem")

For Each objComp in objQryCompSys
    objTxtInfo.WriteLine "User Name: " & objComp.UserName
    objTxtInfo.WriteLine "Computer Name: " & objComp.Name
    objTxtInfo.WriteLine "Physical Memory: " & objComp.TotalPhysicalMemory & " bytes"
Next

For Each objOS In objQryOS
   strOSName = objOS.Name
   intEnd = instr(strOSName, "|") - 2
   strOSName = Mid(strOSName, 1, intEnd)
   objTxtInfo.Writeline "OS Name: " & strOSName
   objTxtInfo.WriteLine "OS Version: " & objOS.Version
Next

For Each objNIC in objQryNetwork
    If Not IsNull(objNic.IPAddress) Then
       For I=LBound(objNIC.IPAddress) to UBound(objNIC.IPAddress)
           objTxtInfo.WriteLine "IP Address: " & objNIC.IPAddress(I)
       Next
       objTxtInfo.WriteLine "MAC Address: " & objNIC.MACAddress
    End If
Next

For Each objDisk in objQryDisks
     If (objDisk.DeviceID = "C:") OR (objDisk.DeviceID = "D:") Then
        objTxtInfo.WriteLine "Disk Drive: " & objDisk.DeviceID & _
                         "(" & objDisk.FreeSpace & "of " & objDisk.Size & " bytes free)"
     End If
Next

objTxtInfo.Close

Set objTxtInfo = Nothing
Set objFSO = Nothing
Set objWSHShell = Nothing
Set objWMIService = Nothing



There you go. That should take care of everything you wanted.

0
 
mrongAuthor Commented:
What about manufacturer and model? How to convert bytes to MB for disk drive and memory.
Thanks.


0
 
thunder_mooseCommented:
Well no offense, but for 80 points, I'm done with this question. Follow up on the link posted by the other poster for more info on WMI.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now