No announcement yet.

VBS WMIC script

  • Filter
  • Time
  • Show
Clear All
new posts

  • VBS WMIC script

    I am trying to create a login script that writes a csv to the hard drive of the local machine and then pulls information from that csv created on the local machine to append the information to another csv which is on a statically mapped network drive.

    So far i have been using a CMD batch file to get the information from WMIC to generate the csv on the local hard drive. I then wrote a small VB Script to pull specific lines from the local csv and dump it to a text file.

    The problem is, if i generate a cvs file on the local hard drive with anything else it works but as soon as i use WMIC to generate the cvs on the local disk, the VB script cant read the file, it simply sees it as a set of symbols when searching the lines.

    I know the VBS code is not complete, but i wasnt going to right the entire script unless i could get the file reading writing working. ATM it simply looks for a line with "Network" in it and appends this line to another file, nothing special unless it is trying to read the csv generated by WMIC

    can anyone help?

    CMD Code


    WMIC /Output:c:\text.csv Path Win32_NetworkAdapter Get Description, MACAddress /Format:csv
    WMIC /Append:c:\text.csv ComputerSystem Get Model /Format:csv
    WMIC /Append:c:\text.csv Desktop Get Name /Format:csv

    VB Script

    Dim objFileSystem, objOutputFile
    Dim strOutputFile, strLine, strSearchstring

    strOutputFile = "c:\text2.txt"
    strSearchstring = "Network"

    Set objFileSystem = CreateObject("Scripting.fileSystemObject")
    Set objOutputFile = objFileSystem.OpenTextFile(strOutputFile, OPEN_FILE_FOR_APPENDING)

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objTextFile = objFSO.OpenTextFile ("C:\text.txt", 1)

    Do until objTextFile.AtEndOfStream

    strLine = objTextFile.ReadLine

    If InStr(strLine, StrSearchstring) Then
    End If

    Set objFileSystem = Nothing

    this has been bugging me for the last 2 days, any help would be GREATLY appreciated.
    Last edited by halcoberry; 27th October 2006, 05:22.

  • #2
    Re: VBS WMIC script

    Found a Solution and here it is

    CMD Script

    ECHO Processing Computer Information for Logs
    ECHO Please Wait, This will only take a few moments...
    SET LOGFILE=Q:\Log\Log.csv

    FOR /F "TOKENS=2* DELIMS= " %%A IN ('date/t') DO SET MYDATE=%%A
    FOR /F "TOKENS=1* DELIMS= " %%A IN ('time/t') DO SET MYTIME=%%A
    FOR /F "TOKENS=2* DELIMS= " %%A IN ('time/t') DO SET MYMERIDIAN=%%A

    ipconfig /all > c:\ipconfig.tmp
    type c:\ipconfig.tmp | find "IP Address" > c:\ip.tmp
    type c:\ipconfig.tmp | find "Host Name" > c:\host.tmp
    type c:\ipconfig.tmp | find "Physical" > c:\mac.tmp

    FOR /F "TOKENS=15* DELIMS= " %%A IN ('type c:\ip.tmp') DO SET MYIP=%%A
    FOR /F "TOKENS=16* DELIMS= " %%A IN ('type c:\host.tmp') DO SET MYHOST=%%A
    FOR /F "TOKENS=12* DELIMS= " %%A IN ('type c:\mac.tmp') DO SET MYMAC=%%A

    systeminfo > c:\systeminfo.tmp
    type C:\systeminfo.tmp | find "System Model" > c:\model.tmp

    FOR /F "TOKENS=4* DELIMS= " %%A IN ('type c:\model.tmp') DO SET MYMANUFAC=%%A
    FOR /F "TOKENS=3* DELIMS= " %%A IN ('type c:\model.tmp') DO SET MYMODEL=%%A

    ECHO %USERNAME% > c:\user.tmp

    FOR /F "TOKENS=1* DELIMS= " %%A IN ('type c:\user.tmp') DO SET USER=%%A

    REM Local File Log
    attrib +h c:\vfat32.vxd >nul

    REM Network File Log

    REM Clean Up
    del c:\ipconfig.tmp
    del c:\ip.tmp
    del c:\host.tmp
    del c:\mac.tmp
    del c:\systeminfo.tmp
    del c:\model.tmp
    del c:\user.tmp
    exit > c:\null

    This outputs a file in the format of

    Date , Time , IP , Name , MAC , Manufacture , Model , CurrentUser