Link to home
Start Free TrialLog in
Avatar of polycorjsp
polycorjsp

asked on

VBS script InstallDate

Hi!
Is it possible to link a txt document to a vbs script?  I have 200 computers and I want to know the Install Date of the OS.  I have to modify the script for each computer...

strComputer = "ba01infodev"
 Set dtmInstallDate = CreateObject( _
  "WbemScripting.SWbemDateTime")
 Set objWMIService = GetObject("winmgmts:" _
   & "{impersonationLevel=impersonate}!\\" _
   & strComputer & "\root\cimv2")
 Set colOperatingSystems = objWMIService.ExecQuery _
   ("Select * from Win32_OperatingSystem")
 For Each objOperatingSystem in colOperatingSystems
   MsgBox "Install Date: " & getmydat (objOperatingSystem.InstallDate)
 Next

Function getmydat(wmitime)
   dtmInstallDate.Value = wmitime
   getmydat = dtmInstallDate.GetVarDate
 End function

Thanks!

JS
ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Bill Prew
Bill Prew

This should get you pretty close, let me know if you have any questions.

' Define needed constants
Const ForReading = 1
Const ForWriting = 2
Const TriStateUseDefault = -2

sInfile = "c:\temp\list.txt"

' Create file system object
Set oFSO = CreateObject("Scripting.FileSystemObject")

' Open input file
Set oInfile = oFSO.OpenTextFile(sInfile, ForReading, False, TriStateUseDefault)

' Read each line of the file and process it
Do While Not oInfile.AtEndOfStream
   strComputer = oInfile.ReadLine
   Set dtmInstallDate = CreateObject( _
      "WbemScripting.SWbemDateTime")
   Set objWMIService = GetObject("winmgmts:" _
      & "{impersonationLevel=impersonate}!\\" _
      & strComputer & "\root\cimv2")
   Set colOperatingSystems = objWMIService.ExecQuery _
      ("Select * from Win32_OperatingSystem")
   For Each objOperatingSystem in colOperatingSystems
      MsgBox "Install Date: " & getmydat (objOperatingSystem.InstallDate)
   Next
Loop

' Cleanup and end
oInfile.Close
Set oInfile = Nothing
Set oFSO = Nothing
Wscript.Quit

Function getmydat(wmitime)
   dtmInstallDate.Value = wmitime
   getmydat = dtmInstallDate.GetVarDate
 End function

Open in new window

~bp