Consulting

Results 1 to 8 of 8

Thread: Solved: Newbie question

  1. #1

    Solved: Newbie question

    How can I get a result from the below script to append to a spread sheet or txt file
    [VBA]
    ' Check command line parameters
    Select Case WScript.Arguments.Count
    Case 0
    ' Default if none specified is local computer (".")
    Set objWMIService = GetObject( "winmgmts://./root/cimv2" )
    Set colItems = objWMIService.ExecQuery( "Select * from Win32_ComputerSystem", , 48 )
    For Each objItem in colItems
    strComputer = objItem.Name
    Next
    Case 1
    ' Command line parameter can either be a computer
    ' name or "/?" to request online help
    strComputer = UCase( Wscript.Arguments(0) )
    if InStr( strComputer, "?" ) > 0 Then Syntax
    Case Else
    ' Maximum is 1 command line parameter
    Syntax
    End Select
    ' Define constants
    Const wbemFlagReturnImmediately = &h10
    Const wbemFlagForwardOnly = &h20
    ' Header line for screen output
    strMsg = vbCrLf & "CPU load percentage for " & strComputer & ":" & vbCrLf & vbCrLf
    ' Enable error handling
    On Error Resume Next
    ' Connect to specified computer
    Set objWMIService = GetObject( "winmgmts://" & strComputer & "/root/cimv2" )
    ' Display error number and description if applicable
    If Err Then ShowError
    ' Query processor properties
    Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Processor", "WQL", _
    wbemFlagReturnImmediately + wbemFlagForwardOnly)
    ' Display error number and description if applicable
    If Err Then ShowError
    ' Prepare display of results
    For Each objItem In colItems
    strMsg = strMsg _
    & "Device ID : " & objItem.DeviceID & vbCrLf _
    & "Load Percentage : " & objItem.LoadPercentage & vbCrLf & vbCrLf
    Next
    ' Display results
    WScript.Echo strMsg
    'Done
    WScript.Quit(0)

    Sub ShowError()
    strMsg = vbCrLf & "Error # " & Err.Number & vbCrLf & _
    Err.Description & vbCrLf & vbCrLf
    Syntax
    End Sub
    [/VBA]

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Master
    Joined
    Jan 2005
    Location
    Porto Alegre - RS - Brasil
    Posts
    1,219
    Location
    Hi EricM,

    what do you want to have stored at your spreadsheet? Is your script from a .vbs file or you have added it to a spredsheet yet?

    If it enclosed in a spredsheet you may simply type:
    [VBA]Range("A" & Range("A65536").End(xlUp).Row + 1) = strMsg[/VBA]
    Best Regards,

    Carlos Paleo.

    To every problem there is a solution, even if I dont know it, so this posting is provided "AS IS" with no warranties.

    If Debugging is harder than writing a program and your code is as good as you can possibly make
    it, then by definition you're not smart enough to debug it.




    http://www.mugrs.org

  3. #3
    Paleo you are great at this. I appreciate all the help you give.
    here is what I am doing.
    I use host monitor to monitor my Network assets. Well lately it has been detecting a high CPU on some of my Citrix server. By the time I get there the CPU usage is down (Naturally) But my boss seems to think HM is giving false messages. So I am going to add this VB script to HM so when the CPU is above the 85% the action from host monitor will be to Run the VBS script. This way I can compare the time HM says it was high to the entry from the VBS script to see if it really was above 85%.

    Quote Originally Posted by Paleo
    Hi EricM,

    what do you want to have stored at your spreadsheet? Is your script from a .vbs file or you have added it to a spredsheet yet?

    If it enclosed in a spredsheet you may simply type:
    [VBA]Range("A" & Range("A65536").End(xlUp).Row + 1) = strMsg[/VBA]

  4. #4
    Administrator
    VP-Knowledge Base VBAX Master
    Joined
    Jan 2005
    Location
    Porto Alegre - RS - Brasil
    Posts
    1,219
    Location
    Hi Eric,

    well sounds like my script wont help you too much as you dont want to enclose it in excel, so give me give me some more info and I will try to adapt the script for you. Which one is your operating system and which version is your HM?

    Anyway, you may use this script to write to a text file:

    [VBA]
    Const ForAppending = 8
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objTextFile = objFSO.OpenTextFile _
    ("c:\scripts\service_status.txt", ForAppending, True)
    Set colServices = GetObject("winmgmts:").ExecQuery _
    ("Select * from Win32_Service")
    For Each objService in colServices
    objTextFile.WriteLine(objService.DisplayName & vbTab & _
    objService.State)
    Next
    objTextFile.Close
    [/VBA]
    This example script demonstrates how to retrieve the status for all the services installed on a computer, and then saves the service name and status to a text file.
    Best Regards,

    Carlos Paleo.

    To every problem there is a solution, even if I dont know it, so this posting is provided "AS IS" with no warranties.

    If Debugging is harder than writing a program and your code is as good as you can possibly make
    it, then by definition you're not smart enough to debug it.




    http://www.mugrs.org

  5. #5
    IT is on a W2K server and Host Monitor is the latest version. I am not at work to check right now but I know I just updated it. It can also goto a spread sheet. I just thought it be easier to goto a txt file thats all.

  6. #6
    Administrator
    VP-Knowledge Base VBAX Master
    Joined
    Jan 2005
    Location
    Porto Alegre - RS - Brasil
    Posts
    1,219
    Location
    Hi Eric,

    so did my script has done the trick for you?
    Best Regards,

    Carlos Paleo.

    To every problem there is a solution, even if I dont know it, so this posting is provided "AS IS" with no warranties.

    If Debugging is harder than writing a program and your code is as good as you can possibly make
    it, then by definition you're not smart enough to debug it.




    http://www.mugrs.org

  7. #7
    Yes
    Sorry busy week

  8. #8
    Administrator
    VP-Knowledge Base VBAX Master
    Joined
    Jan 2005
    Location
    Porto Alegre - RS - Brasil
    Posts
    1,219
    Location
    Great, I am glad I could help you out!
    Best Regards,

    Carlos Paleo.

    To every problem there is a solution, even if I dont know it, so this posting is provided "AS IS" with no warranties.

    If Debugging is harder than writing a program and your code is as good as you can possibly make
    it, then by definition you're not smart enough to debug it.




    http://www.mugrs.org

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •