Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Adding results to Excel

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,58872
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Adding results to Excel
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Adding results to Excel - 4/7/2008 10:09:32 AM   
  ploosie

 

Posts: 43
Score: 0
Joined: 3/2/2008
Status: offline
How can I output my results to Excel instead of using a message box?  Your help would be greatly appreciated.


Option Explicit
dim wshShell
Set wshShell = WScript.CreateObject("WScript.Shell")

Dim strSubKey
Dim arrSubKeys()
Dim strDisplayName, strDisplayVersion, strInstallLocation
Const HKEY_LOCAL_MACHINE = &H80000002
Const strKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
Dim objWMIService, colitems, Item, objItem, strDescription, strPatch
Dim strComputer, message
Dim MCount, MBoxes

MCount = 0
MBoxes = 0
Dim MArray
MArray = Array()

If WScript.Arguments.Count =1 Then
   strComputer = WScript.Arguments(0)
Else
   strComputer = wshShell.ExpandEnvironmentStrings("%COMPUTERNAME%")
   strComputer = Inputbox("Enter Computer name","WMI Patch Check",strComputer)
End If
If strcomputer = "" Then WScript.Quit

strcomputer = UCase(strComputer)

GetPatches()
AddALine "(Done!)" 'Don't change. Forces last bit to be written to Array

Dim i
For i = 0 To UBound(MArray)
   MsgBox MArray(i),vbokonly + vbinformation,"Patches on " & strComputer & " (Page " & i +1 & ")"
Next

'Functions and Subs
Function GetPatches()
On Error Resume Next
   AddALine "From QuickFixEngineering" & vbcrlf & vbcrlf
   WMIConnect "\root\cimv2"
       
   Set colItems = objWMIService.ExecQuery("Select * from Win32_QuickFixEngineering",,48)

   For Each objItem in colitems
       If Err <> 0 Then
           'probably an old NT 4 box without current WMI, or security problem
           MsgBox "No patches found, or WMI Error enumerating data from " & strComputer, vbcritical & vbokonly,"Error"
           WScript.Quit
       End If
   
       If (objItem.Description) = "" Then
           strDescription = "(No Description Available)"
       Else
           strDescription = objItem.Description
       End If
       
       If InStr(objItem.HotFixID,"File")= 0 Then
               strPatch = objItem.HotFixID & " - " & strDescription
                AddALine strPatch & vbcrlf
       End If
   Next

'Add Remove    
   WMIConnect "\root\default"
   Dim objRegistry
   set objRegistry = objWMIService.Get("StdRegProv")
   objRegistry.EnumKey HKEY_LOCAL_MACHINE, strKey, arrSubKeys
   AddALine vbcrlf & "From Add or Remove Programs:" & vbcrlf & vbcrlf

   For Each strSubKey In arrSubKeys
   if instr(lcase(strSubkey),"update") > 0 then
       objRegistry.GetStringValue HKEY_LOCAL_MACHINE, _
           strKey & "\" & strSubKey, "DisplayName", strDisplayName
       AddALine strSubKey & " - " & strDisplayName & vbcrlf
       strDisplayName = vbEmpty
   End If
   Next
End Function


Function MYOSVer()
   Const SPKey = "HKLM\Software\Microsoft\Windows NT\CurrentVersion\CurrentVersion"
   MyOSVER = WshShell.RegRead (SPkey)
End Function

Function AddALine(NewItem)
   If NewItem = "(Done!)" Then
       Redim Preserve MArray(Ubound(Marray) + 1)
       message = message & vbcrlf & "(Done!)"
       MArray(MBoxes) = message
       Exit Function
   End If
   
   If MCount = 15 Then
    Redim Preserve MArray(Ubound(Marray) + 1)
    message = message & vbcrlf & "(Message Box Full. More follows.)"
    MArray(MBoxes) = message
       message = NewItem
       MBoxes = MBoxes +1            'Increment counter for Array
       MCount = 0                    'Reset
   Else
       message = message & NewItem
       MCount = MCount +1
   End If
End Function

Function WMIConnect(root)    
On Error Resume Next
   If MYOSVer < 5.1 Then ' too bad. Must risk hanging WMI calls
       Set objWMIService = GetObject("winmgmts:\\" & strComputer & root)
   Else
       Const wbemConnectFlagUseMaxWait = 128
       Dim objLocator
       Set objLocator = CreateObject("WbemScripting.SWbemLocator")
       Set objWMIService = objLocator.ConnectServer(strComputer,root,,,,, wbemConnectFlagUseMaxWait)
   End If
   
   If Err.Number <> 0 Then
       MsgBox "WMI Error Reaching or connecting to " & strComputer, vbcritical & vbokonly,"Error"
       WScript.Quit
   End If
On Error goto 0
End function
 
 
Post #: 1
 
 RE: Adding results to Excel - 4/7/2008 11:06:57 AM   
  dm_4ever


Posts: 2641
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
Do a search for Excel.Application....you should be able to find plenty of examples....throw something together and post back.

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to ploosie)
 
 
Post #: 2
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Adding results to Excel Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts