Have 2 message boxes & 1 outputfile, need to merge

Author Message
FelixMc

  • Total Posts : 3
  • Scores: 0
  • Reward points : 0
  • Joined: 5/16/2005
  • Location:
  • Status: offline
Have 2 message boxes & 1 outputfile, need to merge Monday, May 16, 2005 4:00 AM (permalink)
0
' 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


' ****Show current logged on user*******
dim user
set user=createobject("WScript.Network")
msgbox user.UserName
Set user = Nothing

' ****Show IP address*******************
strComputer = "."
Set objWMIService = GetObject( _
"winmgmts:\\" & strComputer & "\root\cimv2")
Set IPConfigSet = objWMIService.ExecQuery _
("Select IPAddress from Win32_NetworkAdapterConfiguration ")

For Each IPConfig in IPConfigSet
If Not IsNull(IPConfig.IPAddress) Then
For i=LBound(IPConfig.IPAddress) _
to UBound(IPConfig.IPAddress)
WScript.Echo IPConfig.IPAddress(i)
Next
End If
Next

'****End - I would like two things ***************
'***1: all info in 1 text file *******************
'***2: save the file the username returned.*******

Dim outFile

' Header line for screen output
strMsg = vbCrLf & "Hardware summary 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", , 48 )
' Display error number and description if applicable
If Err Then ShowError
' Prepare display of results
For Each objItem in colItems
strMsg = strMsg & "Processor(s)" & vbCrLf _
& " Name: " _
& Strip( objItem.Name ) & vbCrLf _
& " Manufacturer: " _
& objItem.Manufacturer & vbCrLf _
& " Description: " _
& objItem.Description & vbCrLf _
& " Current Clock Speed: " _
& objItem.CurrentClockSpeed & " MHz" _
& vbCrLf & vbCrLf
Next

' Query memory properties
Set colItems = objWMIService.ExecQuery( "Select * from Win32_LogicalMemoryConfiguration", , 48 )
' Display error number and description if applicable
If Err Then ShowError
' Prepare display of results
For Each objItem in colItems
strMsg = strMsg & "Memory" & vbCrLf _
& " Total Physical Memory: " _
& Int( ( objItem.TotalPhysicalMemory + 1023 ) / 1024 ) _
& " MB" & vbCrLf & vbCrLf
Next

' Query harddisk properties
Set colItems = objWMIService.ExecQuery( "Select * from Win32_DiskDrive", , 48 )
' Display error number and description if applicable
If Err Then ShowError
' Prepare display of results
For Each objItem in colItems
strMsg = strMsg & "Harddisk(s)" & vbCrLf _
& " Manufacturer: " _
& objItem.Manufacturer & vbCrLf _
& " Model: " _
& objItem.Model & vbCrLf _
& " Size: " _
& Int( ( objItem.Size + 536870912 ) / 1073741824 ) _
& " GB" & vbCrLf & vbCrLf
Next

' Query video adapter properties
Set colItems = objWMIService.ExecQuery( "Select * from Win32_VideoController", , 48 )
' Display error number and description if applicable
If Err Then ShowError
' Prepare display of results
For Each objItem in colItems
strMsg = strMsg & "Video" & vbCrLf _
& " Name: " _
& objItem.Name & vbCrLf _
& " Description: " _
& objItem.Description & vbCrLf _
& " Video Processor: " _
& objItem.VideoProcessor & vbCrLf _
& " Adapter RAM: " _
& Int( ( objItem.AdapterRAM + 524288 ) / 1048576 ) _
& " MB" & vbCrLf _
& " Video Mode Description: " _
& objItem.VideoModeDescription & vbCrLf & vbCrLf
Next


' Display results
WScript.Echo strMsg


dim FSobj
set FSobj=CreateObject("Scripting.FileSystemObject")

set outFile= FSobj.CreateTextFile("C:\test\outFile.txt", 2, True)
outFile.write strMsg
outFile.Close

WScript.Echo "Output stored to C:\test\outFile.txt folder."


'Done
WScript.Quit(0)

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


Sub Syntax()
strMsg = strMsg & vbCrLf _
& "Hardware.vbs, Version 1.11" & vbCrLf _
& "Display basic hardware summary for " _
& "any computer on the network" & vbCrLf & vbCrLf _
& "Usage: CSCRIPT //NOLOGO HARDWARE.VBS " _
& "[ computer_name ]" & vbCrLf & vbCrLf _
& "Where: " & Chr(34) & "computer_name" & Chr(34) _
& " is the optional name of a remote" & vbCrLf _
& " computer (default is local computer " _
& "name)" & vbCrLf & vbCrLf _
& "Written by Rob van der Woude" & vbCrLf _
& "http://www.robvanderwoude.com" & vbCrLf & vbCrLf _
& "Created with Microsoft's Scriptomatic tool" & vbCrLf _
& "http://www.microsoft.com/technet/treeview/default.asp" _
& "?url=/technet/scriptcenter/WMImatic.asp" & vbCrLf
WScript.Echo strMsg
WScript.Quit(1)
End Sub


Private Function Strip( strInput )
Do While Left( strInput, 1 ) = " "
strInput = Mid( strInput, 2 )
Loop
Strip = strInput
End Function
 
#1
    token

    • Total Posts : 1917
    • Scores: 0
    • Reward points : 0
    • Joined: 1/14/2005
    • Location:
    • Status: offline
    Re: Have 2 message boxes & 1 outputfile, need to merge Monday, May 16, 2005 7:34 AM (permalink)
    0
    I only see one msgbox in the entire script. You have to give more to receive more.

     
    #2
      FelixMc

      • Total Posts : 3
      • Scores: 0
      • Reward points : 0
      • Joined: 5/16/2005
      • Location:
      • Status: offline
      Re: Have 2 message boxes & 1 outputfile, need to merge Monday, May 16, 2005 10:19 PM (permalink)
      0
      [?][?]
      If you run the script 2 boxes appear.

      Anyway, I've edited the script - what I'm posting here is a plea for help, a much shorter version that if someone could explain where I'm going wrong I'll sort the larger script out myself. PLEASE someone!

      I want to save the following IP address into the created textfile - what's wrong with this code? Second thing, perhaps not so eay - how would I save the file as the given IP address?

      '[CODE]

      Dim outFile

      ' Header line for screen output
      strMsg = IPconfig

      strComputer = "."
      Set objWMIService = GetObject( _
      "winmgmts:\\" & strComputer & "\root\cimv2")
      Set IPConfigSet = objWMIService.ExecQuery _
      ("Select IPAddress from Win32_NetworkAdapterConfiguration ")

      For Each IPConfig in IPConfigSet
      If Not IsNull(IPConfig.IPAddress) Then
      For i=LBound(IPConfig.IPAddress) _
      to UBound(IPConfig.IPAddress)
      WScript.Echo IPConfig.IPAddress(i)
      Next
      End If
      Next

      dim FSobj
      set FSobj=CreateObject("Scripting.FileSystemObject")

      set outFile= FSobj.CreateTextFile("outFile.txt", 2, True)
      outFile.write strMsg
      outFile.Close

      WScript.Echo "Output stored to outFile.txt in same directory as script."
       
      #3
        FelixMc

        • Total Posts : 3
        • Scores: 0
        • Reward points : 0
        • Joined: 5/16/2005
        • Location:
        • Status: offline
        Re: Have 2 message boxes & 1 outputfile, need to merge Monday, May 16, 2005 11:52 PM (permalink)
        0
        Have fixed the difficult (for me!) naming the file, will post full file so you can see the 2nd part - appending the IP address to the already created text file. This should be easy, am working on now, if someone could post a solution before then though I'd be chuffed!

        '[code]

        ' 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 IPConfigSet = objWMIService.ExecQuery _
        ("Select IPAddress from Win32_NetworkAdapterConfiguration ")
        For Each IPConfig in IPConfigSet
        If Not IsNull(IPConfig.IPAddress) Then
        For i=LBound(IPConfig.IPAddress) _
        to UBound(IPConfig.IPAddress)
        WScript.Echo IPConfig.IPAddress(i)
        Next
        End If
        Next

        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

        Dim outFile


        ' Header line for screen output
        strMsg = vbCrLf & "Hardware summary 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", , 48 )
        ' Display error number and description if applicable
        If Err Then ShowError
        ' Prepare display of results
        For Each objItem in colItems
        strMsg = strMsg & "Processor(s)" & vbCrLf _
        & " Name: " _
        & Strip( objItem.Name ) & vbCrLf _
        & " Manufacturer: " _
        & objItem.Manufacturer & vbCrLf _
        & " Description: " _
        & objItem.Description & vbCrLf _
        & " Current Clock Speed: " _
        & objItem.CurrentClockSpeed & " MHz" _
        & vbCrLf & vbCrLf
        Next

        ' Query memory properties
        Set colItems = objWMIService.ExecQuery( "Select * from Win32_LogicalMemoryConfiguration", , 48 )
        ' Display error number and description if applicable
        If Err Then ShowError
        ' Prepare display of results
        For Each objItem in colItems
        strMsg = strMsg & "Memory" & vbCrLf _
        & " Total Physical Memory: " _
        & Int( ( objItem.TotalPhysicalMemory + 1023 ) / 1024 ) _
        & " MB" & vbCrLf & vbCrLf
        Next

        ' Query harddisk properties
        Set colItems = objWMIService.ExecQuery( "Select * from Win32_DiskDrive", , 48 )
        ' Display error number and description if applicable
        If Err Then ShowError
        ' Prepare display of results
        For Each objItem in colItems
        strMsg = strMsg & "Harddisk(s)" & vbCrLf _
        & " Manufacturer: " _
        & objItem.Manufacturer & vbCrLf _
        & " Model: " _
        & objItem.Model & vbCrLf _
        & " Size: " _
        & Int( ( objItem.Size + 536870912 ) / 1073741824 ) _
        & " GB" & vbCrLf & vbCrLf
        Next

        ' Query video adapter properties
        Set colItems = objWMIService.ExecQuery( "Select * from Win32_VideoController", , 48 )
        ' Display error number and description if applicable
        If Err Then ShowError
        ' Prepare display of results
        For Each objItem in colItems
        strMsg = strMsg & "Video" & vbCrLf _
        & " Name: " _
        & objItem.Name & vbCrLf _
        & " Description: " _
        & objItem.Description & vbCrLf _
        & " Video Processor: " _
        & objItem.VideoProcessor & vbCrLf _
        & " Adapter RAM: " _
        & Int( ( objItem.AdapterRAM + 524288 ) / 1048576 ) _
        & " MB" & vbCrLf _
        & " Video Mode Description: " _
        & objItem.VideoModeDescription & vbCrLf & vbCrLf
        Next

        ' Display results
        WScript.Echo strMsg

        dim FSobj
        set FSobj=CreateObject("Scripting.FileSystemObject")

        set outFile= FSobj.CreateTextFile(strComputer &".txt", 2, True)
        outFile.write strMsg
        outFile.Close

        WScript.Echo "Output stored to in text file on K:\General\IT\Assets"


        'Done
        WScript.Quit(0)


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


        Sub Syntax()
        strMsg = strMsg & vbCrLf _
        & "Hardware.vbs, Version 1.11" & vbCrLf _
        & "Display basic hardware summary for " _
        & "any computer on the network" & vbCrLf & vbCrLf _
        & "Usage: CSCRIPT //NOLOGO HARDWARE.VBS " _
        & "[ computer_name ]" & vbCrLf & vbCrLf _
        & "Where: " & Chr(34) & "computer_name" & Chr(34) _
        & " is the optional name of a remote" & vbCrLf _
        & " computer (default is local computer " _
        & "name)" & vbCrLf & vbCrLf _
        & "Written by Rob van der Woude" & vbCrLf _
        & "http://www.robvanderwoude.com" & vbCrLf & vbCrLf _
        & "Created with Microsoft's Scriptomatic tool" & vbCrLf _
        & "http://www.microsoft.com/technet/treeview/default.asp" _
        & "?url=/technet/scriptcenter/WMImatic.asp" & vbCrLf
        WScript.Echo strMsg
        WScript.Quit(1)
        End Sub


        Private Function Strip( strInput )
        Do While Left( strInput, 1 ) = " "
        strInput = Mid( strInput, 2 )
        Loop
        Strip = strInput
        End Function

        '[code/]
         
        #4

          Online Bookmarks Sharing: Share/Bookmark

          Jump to:

          Current active users

          There are 0 members and 1 guests.

          Icon Legend and Permission

          • 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
          • Read Message
          • Post New Thread
          • Reply to message
          • Post New Poll
          • Submit Vote
          • Post reward post
          • Delete my own posts
          • Delete my own threads
          • Rate post

          2000-2012 ASPPlayground.NET Forum Version 3.9