/build/static/layout/Breadcrumb_cap_w.png

Inventorying & Reporting on User Profile-Specific & Other Non-Inventoried Data

In a nutshell - if you can output data to a text file, this method will allow you to get it into the Inventory - Custom Fields section of your K1000.  On my network I use it to collect network drive & printer info, screen resolution and other things the K1000 doesn't support natively.

I've referenced this post a few times since ITNinja went live, and just today realized that a number of things didn't migrate smoothly (particularly in the example scripts section...).  Therefore, as I feel this info is still relevant, I'm doing a clean-up, update and quasi-repost, which will hopefully make this more usable than the original version.  I've also made a few revisions so that things should work with *both* WinXP and Win7 - when I originally did all of this I didn't have any Win7 machines using all of this and have since changed a few things.

There are a number of good comments in the original post, so for anyone interested, here's the link:

Extending the Computer Inventory to Support User Profile Specific & Other Non-Inventoried Data
http://www.itninja.com/question/extending-the-computer-inventory-to-support-user-profile-specific-other-non-inventoried-data

Also, for anyone planning on reporting on the data collected using this method, you'll probably find this post useful:

Workaround for Line Break Character Bug in Reports Generated on Inventory Custom Fields
http://itninja.com/blog/view/workaround-for-line-break-character-bug-in-reports-generated-on-inventory-custom-fields

As usual, hope this helps somebody!

John
_________________________________________________________________________________

***Notes***

The ShellCommandTextReturn listed in step 5 below works in versions prior to 5.1 and post 5.3.47173.  The other versions (5.2 and earlier 5.3) have a bug that prevent this command from working properly.

I'm not a scripting wizard and most of the scripts have been cobbled together via examples found via Google (along with a lot of trial & error testing). I've tried to ensure that nothing hangs or crashes, but if you see things that can be improved, please share.

There's a bug in the reports where the line breaks are not processed correctly during the text file import and they end up listed in the reports rather than being line breaks.  Tyler Gingrich has fixed this in the Computer Inventory screen so the results are clean, but the reports still exhibit this (by default).  See the link above for a post on how to address this with some tweaking of the report code.
_________________________________________________________________________________
_________________________________________________________________________________

Custom Inventory Items & Reporting for Scripts

1) Create a custom folder on all PCs for holding script output files (i.e. C:\KBOX)
    - this can be done using a vbs script and run from KBOX
    - avoid creating in protected folders in Win7 (i.e. C:\Windows\KBOX) as the scripts may not work

2) Create a vbs script that outputs to a text file to a custom folder (i.e. C:\KBOX)
    - create cleanup routine in script for output file as necessary

3) Create a new item in Scripts - Scripts to deploy (see Scripting Settings for VBS Scripts below line break for ref)

4) Run/deploy script on a test PC and make sure file is output correctly to custom folder

5) Create a new Inventory - Software item

   Example:
   - Display Name           Screen Resolution
   - Custom Inv Rule        ShellCommandTextReturn(cmd /c type c:\WINDOWS\KBOX\screen_resolution.txt)

6) Force inventory update on a the test PC via Inventory - Computers screen

7) Check test PC's Custom Inventory Field to verify it is populated with text from script output file

8) Create a new report using Report Wizard
    
   See this post:
   http://itninja.com/blog/view/workaround-for-line-break-character-bug-in-reports-generated-on-inventory-custom-fields

9) Run new report - should list all computers and have entry for test PC with text from script output file.
_________________________________________________________________________________
_________________________________________________________________________________

Scripting Settings for VBS Scripts
_________________________________________________________________________________

To create a scripting item using a vbs script:

1) Script Type       Offline KScript (or Online KScript if script needs to run as logged in user)
2) Enabled           checkbox has to be checked
3) Deployment        Specify one of these (all, specific PCs, label)
4) Supported OS      Microsoft Windows
5) Run As            Run As User logged in to console (if script needs to run as logged in user)
   * note - needs to have trap in vbs script for when no one logged into PC
6) Dependencies      Upload target vbs script here
7) Policy or Job Rules
   Task 1
     Attempts      1
     On Failure    Break
     Verify        
       1) Always Fail
     On Success    
        <nothing>
     Remediation
       1) Launch a program
          Directory     $(KBOX_SYS_DIR)
          File          cscript.exe
          Check box for "Wait for startup" (yes)
          Parameters    "$(KACE_DEPENDENCY_DIR)\screen_resolution.vbs" (for example)

      (optional - if you want to upload files to the kbox - be aware you can't report on these)
       2) Upload a file
          Directory     Wherever vbs script outputs file (i.e. C:\KBOX)
          File          name of output file (i.e. screen_resolution.txt)

     On Remediation Success
       1) Log message
          successfully ran screen_resolution script

     On Remediation Failure
       1) Log message
          failed to run screen_resolution script

8) Save
_________________________________________________________________________________
_________________________________________________________________________________

Example scripts and output
_________________________________________________________________________________

1) local_and_network_drives.vbs

4/13/2012 8:03:51 AM - Logged in user:  jsmith
------------------------------------------------------
C: Local Hard Drive
D: CD/DVD Drive
G: \\siteserver\data
H: \\fileserver\helpdesk
I: \\siteserver\users\sfrazier
L: \\siteserver\public
M: \\fileserver\manufacturing
P: \\fileserver\public
Q: \\fileserver\QA
R: \\fileserver\Research
S: \\fileserver\Sales&Marketing

_________________________________________________________________________________

2) memory_info.vbs

------------------------------------------------------
4/13/2012 8:03:18 AM
------------------------------------------------------
Slots:                2
Maximum Capacity:     4096 MB
------------------------------------------------------
Memory Stick:         DIMM_1
Capacity:             512 MB
Form Factor:          DIMM
Memory Type:          TQFP
Speed:                333 MHz
Data Width:           64
------------------------------------------------------
Memory Stick:         DIMM_2
Capacity:             512 MB
Form Factor:          DIMM
Memory Type:          TQFP
Speed:                333 MHz
Data Width:           64
------------------------------------------------------

_________________________________________________________________________________

3) printer_default.vbs

4/13/2012 4:05:21 AM - Logged in user:  jsmith
------------------------------------------------------
HP LaserJet P2035n (Landscape - NWA)

4/11/2012 12:04:25 PM - Logged in user:  jdoe
------------------------------------------------------
\\srv-ec01\LANIER LD325

_________________________________________________________________________________

4) printers_list.vbs

4/13/2012 8:04:00 AM - Logged in user:  jsmith
------------------------------------------------------
Microsoft Office Document Image Writer
HP LaserJet P2035n (Landscape - NWA)
HP LaserJet P2035n
HP LaserJet 2100 PCL6
\\srv-ec01\ec156

4/11/2012 12:04:47 PM - Logged in user:  jdoe
------------------------------------------------------
Microsoft Office Document Image Writer
HP LaserJet P2035n (Landscape - NWA)
HP LaserJet P2035n
HP LaserJet 2100 PCL6
\\srv-ec01\HP LaserJet 2100 Series PCL 6
\\srv-ec01\LANIER LD325

_________________________________________________________________________________

5) screen_resolution.vbs

1024 * 768

_________________________________________________________________________________
_________________________________________________________________________________

Scripts (compatible with WinXP & Win7)
_________________________________________________________________________________

local_and_network_drives.vbs
_________________________________________________________________________________

Dim objFSO, newfolder
Dim strComputer, objWMIService
Dim fso, fsHandle, objShell,LogFileName, colItems, objItem

set objFSO=CreateObject("Scripting.FileSystemObject")
If Not objFSO.FolderExists("c:\KBOX") Then
   newfolder = objFSO.CreateFolder ("c:\KBOX")
End If

Set objShell = CreateObject("Wscript.Shell")
Set fso = Wscript.CreateObject("Scripting.FilesystemObject")

If objFSO.FileExists("c:\KBOX\local_and_network_drives.txt") Then
fso.DeleteFile "c:\KBOX\local_and_network_drives.txt", True
End If

LogFileName= "C:\KBOX\local_and_network_drives.txt"
set fsHandle = fso.OpenTextFile (LogFileName,8,True)

sUser = ConsoleUser(".") ' use "." for local computer

Function ConsoleUser(sHost)
' Returns name of user logged on to console
' If no users are logged on, returns ""
Dim oWMI, colProc, oProcess, sUser, sDomain
Set oWmi = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate,(debug)}!\\" _
& sHost & "\root\cimv2")

Set colProc = oWmi.ExecQuery("Select Name from Win32_Process" _
& " Where Name='explorer.exe' and SessionID=0")

ConsoleUser = ""
For Each oProcess In colProc
lRet = oProcess.GetOwner(sUser, sDomain)
If lRet = 0 Then
ConsoleUser = sUser
End If
Next
End Function

fsHandle.Writeline Now & " - " _
& "Logged in user:  " & suser _

fsHandle.Writeline "------------------------------------------------------"

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
   & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colDrives = objWMIService.ExecQuery _
    ("Select * From Win32_LogicalDisk Where DriveType = 3")
For Each objDrive in colDrives

fsHandle.Writeline objDrive.Name & " " & "Local Hard Drive"

Next

Set colDrives = objWMIService.ExecQuery _
    ("Select * From Win32_LogicalDisk Where DriveType = 5")
For Each objDrive in colDrives

fsHandle.Writeline objDrive.Name & " " & "CD/DVD Drive"

Next


Set colDrives = objWMIService.ExecQuery _
    ("Select * From Win32_LogicalDisk Where DriveType = 4")
For Each objDrive in colDrives

fsHandle.Writeline objDrive.Name & " " & objDrive.ProviderName _

Next

fsHandle.Writeblanklines 1
fsHandle.close

set objShell = Nothing
set fso = Nothing
_________________________________________________________________________________
_________________________________________________________________________________

memory_info.vbs
_________________________________________________________________________________

Dim objFSO, newfolder
Dim strComputer, objWMIService
Dim fso, fsHandle, objShell,LogFileName, colItems, objItem

set objFSO=CreateObject("Scripting.FileSystemObject")
If Not objFSO.FolderExists("c:\KBOX") Then
   newfolder = objFSO.CreateFolder ("c:\KBOX")
End If

Set objShell = CreateObject("Wscript.Shell")
Set fso = Wscript.CreateObject("Scripting.FilesystemObject")

If objFSO.FileExists("c:\KBOX\memory_info.txt") Then
fso.DeleteFile "c:\KBOX\memory_info.txt", True
End If

LogFileName= "C:\KBOX\memory_info.txt"
set fsHandle = fso.OpenTextFile (LogFileName,8,True)

fsHandle.Writeline "------------------------------------------------------"
fsHandle.Writeline Now
fsHandle.Writeline "------------------------------------------------------"

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colItems = objWMIService.ExecQuery _
("Select * from Win32_PhysicalMemoryArray")

For Each objItem in colItems
fsHandle.Writeline "Slots:                " & objItem.MemoryDevices
fsHandle.Writeline "Maximum Capacity:     " & (objItem.MaxCapacity / 1024) & " MB"
fsHandle.Writeline "------------------------------------------------------"

Next

Set col2Items = objWMIService.ExecQuery("Select * from Win32_PhysicalMemory")

For Each objItem in col2Items

Dim ff, mt

If  objItem.FormFactor = 0 THEN
   ff = "Unknown"
ElseIf objItem.FormFactor = 1 THEN
    ff = "Other"
ElseIf objItem.FormFactor = 2 THEN
    ff = "SIP"
ElseIf objItem.FormFactor = 3 THEN
    ff = "DIP"
ElseIf objItem.FormFactor = 4 THEN
    ff = "ZIP"
ElseIf objItem.FormFactor = 5 THEN
    ff = "SOJ"
ElseIf objItem.FormFactor = 6 THEN
    ff = "Proprietary"
ElseIf objItem.FormFactor = 7 THEN
    ff = "SIMM"
ElseIf objItem.FormFactor = 8 THEN
    ff = "DIMM"
ElseIf objItem.FormFactor = 9 THEN
    ff = "TSOP"
ElseIf objItem.FormFactor = 10 THEN
    ff = "PGA"
ElseIf objItem.FormFactor = 11 THEN
    ff = "RIMM"
ElseIf objItem.FormFactor = 12 THEN
    ff = "SODIMM"
ElseIf objItem.FormFactor = 13 THEN
    ff = "SRIMM"
ElseIf objItem.FormFactor = 14 THEN
    ff = "SMD"
ElseIf objItem.FormFactor = 15 THEN
    ff = "SSMP"
ElseIf objItem.FormFactor = 16 THEN
    ff = "QFP"
ElseIf objItem.FormFactor = 17 THEN
    ff = "TQFP"
ElseIf objItem.FormFactor = 18 THEN
    ff = "SOIC"
ElseIf objItem.FormFactor = 19 THEN
    ff = "LCC"
ElseIf objItem.FormFactor = 20 THEN
    ff = "PLCC"
ElseIf objItem.FormFactor = 21 THEN
    ff = "BGA"
ElseIf objItem.FormFactor = 22 THEN
    ff = "FPBGA"
ElseIf objItem.FormFactor = 23 THEN
    ff = "LGA"
End If

If objItem.MemoryType = 0 THEN
    mt = "Unknown"
ElseIf objItem.MemoryType = 1 THEN
    mt = "Other"
ElseIf objItem.MemoryType = 2 THEN
    mt = "SIP"
ElseIf objItem.MemoryType = 3 THEN
    mt = "DIP"
ElseIf objItem.MemoryType = 4 THEN
    mt = "ZIP"
ElseIf objItem.MemoryType = 5 THEN
    mt = "SOJ"
ElseIf objItem.MemoryType = 6 THEN
    mt = "Proprietary"
ElseIf objItem.MemoryType = 7 THEN
    mt = "SIMM"
ElseIf objItem.MemoryType = 8 THEN
    mt = "DIMM"
ElseIf objItem.MemoryType = 9 THEN
    mt = "TSOP"
ElseIf objItem.MemoryType = 10 THEN
    mt = "PGA"
ElseIf objItem.MemoryType = 11 THEN
    mt = "RIMM"
ElseIf objItem.MemoryType = 12 THEN
    mt = "SODIMM"
ElseIf objItem.MemoryType = 13 THEN
    mt = "SRIMM"
ElseIf objItem.MemoryType = 14 THEN
    mt = "SMD"
ElseIf objItem.MemoryType = 15 THEN
    mt = "SSMP"
ElseIf objItem.MemoryType = 16 THEN
    mt = "QFP"
ElseIf objItem.MemoryType = 17 THEN
    mt = "TQFP"
ElseIf objItem.MemoryType = 18 THEN
    mt = "SOIC"
ElseIf objItem.MemoryType = 19 THEN
    mt = "LCC"
ElseIf objItem.MemoryType = 20 THEN
    mt = "PLCC"
ElseIf objItem.MemoryType = 21 THEN
    mt = "BGA"
ElseIf objItem.MemoryType = 22 THEN
    mt = "FPBGA"
ElseIf objItem.MemoryType = 23 THEN
    mt = "LGA"
End If

fsHandle.Writeline "Memory Stick:         " & objItem.DeviceLocator
fsHandle.Writeline "Capacity:             " & (objItem.Capacity / 1024 / 1024) & " MB"
fsHandle.Writeline "Form Factor:          " & ff
fsHandle.Writeline "Memory Type:          " & mt
fsHandle.Writeline "Speed:                " & objItem.Speed & " MHz"
fsHandle.Writeline "Data Width:           " & objItem.DataWidth
fsHandle.Writeline "------------------------------------------------------"

Next

fsHandle.Writeblanklines 1
fsHandle.close

set objShell = Nothing
set fso = Nothing
_________________________________________________________________________________
_________________________________________________________________________________

printer_default.vbs (note - this is my reworking of billprew's script so that it captures the default printer)
_________________________________________________________________________________

' Script reads a current log file of users and printers, elliminates dupes,
' adds in the current user and their printers, and then rewrites the log file.
'
' This script uses a dictionary object to store the printers for each user.
' There will be one dictionary item per user, and then the "data" of that
' user's dictionary item will have the format:
'
' date-string|printer 1|printer 2|printer 3|...|

' Require variables to be defined before usage
Option Explicit

' Define constants
Const ForReading = 1
Const ForWriting = 2

' Define variable used in mainline of script
Dim strBaseDir, strListFile, objFSO, dicUsers, objShell

' Define base folder and log file name
strBaseDir = "C:\KBOX\"
strListFile = strBaseDir & "printer_default.txt"

' Create needed objects
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject( "WScript.Shell" )
Set dicUsers = CreateObject("Scripting.Dictionary")

' Create the base folder if it doesn't exist
If Not objFSO.FolderExists(strBaseDir) Then
objFSO.CreateFolder(strBaseDir)
End If

' If we have a prior log file, load the users and printers from it first
If objFSO.FileExists(strListFile) Then
    GetHistory(strListFile)
End If

' Add printers for the current user to the dictionary
GetPrinters(GetUser("."))

' Dump the contents of the dictionary to the log file
WriteLog(strListFile)


' Subroutnie to load prior history, elliminate any duplicates
Sub GetHistory(strFile)
    Dim objFile, strUser, strLine, arrTemp

    ' Open the log file for reading
    Set objFile = objFSO.OpenTextFile(strFile, ForReading)

    strUser = ""

    ' Read each line, looking for user or printer lines, skip blank and dash lines
    Do Until objFile.AtEndOfStream
        strLine = objFile.ReadLine
        If strLine <> "" And Mid(strLine, 1, 10) <> "----------" Then
            If Instr(strLine, "Logged in user:") Then
                arrTemp = Split(Replace(strLine, "  ", " "), " ")
                strUser = LCase(arrTemp(7))
                ' Try to add this user to the dictionary
                AddUser strUser, arrTemp(0) & " " & arrTemp(1) & " " & arrTemp(2)
            Else
                If strUser <> "" Then
                    ' Try to add this printer to the dictionary
                    AddPrinter strUser, strLine
                End If
            End If
        End If
    Loop

    objFile.Close
    Set objFile = Nothing
End Sub

' Subroutine to get default printer for this user and add to dictionary
Sub GetPrinters(strUser)
    Dim strComputer, objWMI, colPrinters, objPrinter

    ' Make sure we have a user
    If strUser <> "" Then
        ' Add this user to the dictionary if needed
        AddUser strUser, FormatDateTime(Now)

        ' Identify all printers for this user
        strComputer = "."
        Set objWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
        Set colPrinters =  objWMI.ExecQuery("Select * from Win32_Printer where Default = 'True'")
        For Each objPrinter in colPrinters
            ' Try to add each printer to dictionary
            AddPrinter strUser, objPrinter.Name
        Next

        Set colPrinters = Nothing
        Set objWMI = Nothing
    End If
End Sub

' Subroutine to dump the accumulated data from the dictionary to the log file
Sub WriteLog(strFile)
    Dim objFile, strUser, arrData, i
 
    ' Open the log file for writing
    Set objFile = objFSO.OpenTextFile (strFile, ForWriting, True)
 
    ' Process each user in the dictionary
    For Each strUser in dicUsers
        arrData = Split(dicUsers.Item(strUser), "|")
 
        ' Header lines for a user
        objFile.Writeline arrData(0) & " - " & "Logged in user:  " & strUser
        objFile.Writeline "------------------------------------------------------"
 
        ' Loop through all printers for this user and write to log file
        If UBound(arrData) > 0 Then
            For i = 1 to UBound(arrData)-1
                objFile.Writeline arrData(i)
            Next
        End If
        objFile.WriteBlankLines 1
    Next
 
    objFile.Close
    Set objFile = Nothing
End Sub

' Function to get the current user id
Function GetUser(strHost)
    GetUser = LCase(objShell.ExpandEnvironmentStrings("%UserName%"))
End Function

' Subroutine to add a user to the dictionary (if it doesn't already exist)
Sub AddUser(strUser, strDate)
    If dicUsers.Exists(strUser) Then
        dicUsers.Item(strUser) = strDate & "|"
    Else
        dicUsers.Add strUser, strDate & "|"
    End If
End Sub

' Subroutine to add a printer to the dictionary for a user (if it doesn't already exist)
Sub AddPrinter(strUser, strPrinter)
    Dim strTemp
    strTemp = dicUsers.Item(strUser)
    If Instr(strTemp, "|" & strPrinter & "|") = 0 Then
        dicUsers.Item(strUser) = strTemp & strPrinter & "|"
    End If
End Sub
_________________________________________________________________________________
_________________________________________________________________________________

printers_list.vbs (note - my original script was revised by billprew from ExpertsExchange so that it updates users' printers lists while scrubbing old entries)
_________________________________________________________________________________

' Script reads a current log file of users and printers, elliminates dupes,
' adds in the current user and their printers, and then rewrites the log file.
'
' This script uses a dictionary object to store the printers for each user.
' There will be one dictionary item per user, and then the "data" of that
' user's dictionary item will have the format:
'
' date-string|printer 1|printer 2|printer 3|...|

' Require variables to be defined before usage
Option Explicit

' Define constants
Const ForReading = 1
Const ForWriting = 2

' Define variable used in mainline of script
Dim strBaseDir, strListFile, objFSO, dicUsers, objShell

' Define base folder and log file name
strBaseDir = "C:\KBOX\"
strListFile = strBaseDir & "printers_list.txt"

' Create needed objects
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject( "WScript.Shell" )
Set dicUsers = CreateObject("Scripting.Dictionary")

' Create the base folder if it doesn't exist
If Not objFSO.FolderExists(strBaseDir) Then
objFSO.CreateFolder(strBaseDir)
End If

' If we have a prior log file, load the users and printers from it first
If objFSO.FileExists(strListFile) Then
    GetHistory(strListFile)
End If

' Add printers for the current user to the dictionary
GetPrinters(GetUser("."))

' Dump the contents of the dictionary to the log file
WriteLog(strListFile)


' Subroutnie to load prior history, elliminate any duplicates
Sub GetHistory(strFile)
    Dim objFile, strUser, strLine, arrTemp

    ' Open the log file for reading
    Set objFile = objFSO.OpenTextFile(strFile, ForReading)

    strUser = ""

    ' Read each line, looking for user or printer lines, skip blank and dash lines
    Do Until objFile.AtEndOfStream
        strLine = objFile.ReadLine
        If strLine <> "" And Mid(strLine, 1, 10) <> "----------" Then
            If Instr(strLine, "Logged in user:") Then
                arrTemp = Split(Replace(strLine, "  ", " "), " ")
                strUser = LCase(arrTemp(7))
                ' Try to add this user to the dictionary
                AddUser strUser, arrTemp(0) & " " & arrTemp(1) & " " & arrTemp(2)
            Else
                If strUser <> "" Then
                    ' Try to add this printer to the dictionary
                    AddPrinter strUser, strLine
                End If
            End If
        End If
    Loop

    objFile.Close
    Set objFile = Nothing
End Sub

' Subroutine to get all pronters for this user and add to dictionary
Sub GetPrinters(strUser)
    Dim strComputer, objWMI, colPrinters, objPrinter

    ' Make sure we have a user
    If strUser <> "" Then
        ' Add this user to the dictionary if needed
        AddUser strUser, FormatDateTime(Now)

        ' Identify all printers for this user
        strComputer = "."
        Set objWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
        Set colPrinters =  objWMI.ExecQuery("Select * from Win32_Printer")
        For Each objPrinter in colPrinters
            ' Try to add each printer to dictionary
            AddPrinter strUser, objPrinter.Name
        Next

        Set colPrinters = Nothing
        Set objWMI = Nothing
    End If
End Sub

' Subroutine to dump the accumulated data from the dictionary to the log file
Sub WriteLog(strFile)
    Dim objFile, strUser, arrData, i
 
    ' Open the log file for writing
    Set objFile = objFSO.OpenTextFile (strFile, ForWriting, True)
 
    ' Process each user in the dictionary
    For Each strUser in dicUsers
        arrData = Split(dicUsers.Item(strUser), "|")
 
        ' Header lines for a user
        objFile.Writeline arrData(0) & " - " & "Logged in user:  " & strUser
        objFile.Writeline "------------------------------------------------------"
 
        ' Loop through all printers for this user and write to log file
        If UBound(arrData) > 0 Then
            For i = 1 to UBound(arrData)-1
                objFile.Writeline arrData(i)
            Next
        End If
        objFile.WriteBlankLines 1
    Next
 
    objFile.Close
    Set objFile = Nothing
End Sub

' Function to get the current user id
Function GetUser(strHost)
    GetUser = LCase(objShell.ExpandEnvironmentStrings("%UserName%"))
End Function

' Subroutine to add a user to the dictionary (if it doesn't already exist)
Sub AddUser(strUser, strDate)
    If dicUsers.Exists(strUser) Then
        dicUsers.Item(strUser) = strDate & "|"
    Else
        dicUsers.Add strUser, strDate & "|"
    End If
End Sub

' Subroutine to add a printer to the dictionary for a user (if it doesn't already exist)
Sub AddPrinter(strUser, strPrinter)
    Dim strTemp
    strTemp = dicUsers.Item(strUser)
    If Instr(strTemp, "|" & strPrinter & "|") = 0 Then
        dicUsers.Item(strUser) = strTemp & strPrinter & "|"
    End If
End Sub
_________________________________________________________________________________
_________________________________________________________________________________

screen_resolution.vbs
_________________________________________________________________________________

Dim objFSO, newfolder
Dim strComputer, objWMIService
Dim fso, fsHandle, objShell, LogFileName, colItems, objItem

set objFSO=CreateObject("Scripting.FileSystemObject")
If Not objFSO.FolderExists("c:\KBOX") Then
   newfolder = objFSO.CreateFolder ("c:\KBOX")
End If

Set objShell = CreateObject("Wscript.Shell")
Set fso = Wscript.CreateObject("Scripting.FilesystemObject")

If objFSO.FileExists("c:\KBOX\screen_resolution.txt") Then
fso.DeleteFile "c:\KBOX\screen_resolution.txt", True
End If

LogFileName= "C:\KBOX\screen_resolution.txt"
set fsHandle = fso.OpenTextFile (LogFileName,8,True)

Set objWMIService = GetObject("Winmgmts:\\.\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * From Win32_DesktopMonitor where DeviceID = 'DesktopMonitor1'",,0)
For Each objItem in colItems
intHorizontal = objItem.ScreenWidth
intVertical = objItem.ScreenHeight

fsHandle.Writeline intHorizontal & " * " & intVertical _

fsHandle.Writeblanklines 1
fsHandle.close
set objShell = Nothing
set fso = Nothing

 
Next
_________________________________________________________________________________


Comments

  • This is a great blog!

    Some of these I can see running on a daily/weekly basis such as printer lists. When we use scripting, the user sees a command prompt flash on their screen as the script runs for the split second. Is there a way to prevent that? I don't want users to think there is something wrong with their system when in fact we are gathering more information to make their system run better. - aweinbergjjk 11 years ago
  • You could try running the scripts as executables (AutoIT or Batch-to-Exe Converter might work).

    John - jverbosk 10 years ago
  • It was brought to my attention that the local_and_network_drives script doesn't return a user name on some versions of Windows (7, probably 8). This can be fixed by replacing one of the lines.

    Replace this line:

    sUser = ConsoleUser(".") ' use "." for local computer

    ...with this line:

    sUser = LCase(objShell.ExpandEnvironmentStrings("%UserName%"))

    ...and it should work. Just for reference, this is the same call that the printer scripts use (which work on every version of Windows that I've been able to test against).

    John - jverbosk 10 years ago
  • Can you modify this script to search user's desktop or C drive for a selected file like .mdb - Kdebiasse 9 years ago
  • This is great!!! I found your page when I was looking for a way to show the networked printers on a computer, but now I've implemented a couple of these scripts.
    The only thing I would add to this (if I knew anything about VBS myself) is to display the printer port for the local printers. We have both local and networked printers in our environment, and it would be so helpful to know the IP address of the local printers for troubleshooting purposes. I keep a spreadsheet with the info, but it's such a pain to keep up to date. Do you think adding this option be something fairly simple to do?? - nicolebeth 8 years ago
This post is locked
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ