Windows 7 VB script will not display results in a window.

Discussion in 'Programming and Scripting' started by tom5674, Oct 1, 2010.

  1. tom5674

    tom5674 New Member

    Joined:
    Oct 1, 2010
    Messages:
    2
    Likes Received:
    0
    When running the following script it will not display the results in a pop up window. This is only happening in Windows 7 Ent. The scrip does work fine from the cmd prompt. Some lines are commented out on purpose. Just want for the user to run this from the desktop and then tell me what the computer name is so I can connect to it remotely.

    On Error Resume Next
    Const wbemFlagReturnImmediately = &h10
    Const wbemFlagForwardOnly = &h20
    arrComputers = Array(".")
    For Each strComputer In arrComputers

    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
    Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem", "WQL", _
    wbemFlagReturnImmediately + wbemFlagForwardOnly)

    For Each objItem In colItems

    ' WScript.Echo "Domain: " & objItem.Domain
    ' WScript.Echo "Manufacturer: " & objItem.Manufacturer
    ' WScript.Echo "Model: " & objItem.Model
    ' strBIOS=Join(objitem.Win_32Bios,".")
    ' WScript.Echo "SerialNumber: " & objItem.SerialNumber
    WScript.Echo "Name: " & objItem.Name
    ' WScript.Echo "PrimaryOwnerName: " & objItem.PrimaryOwnerName
    Next
    Next
    arrComputers = Array(".")
    For Each strComputer In arrComputers

    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
    Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration", "WQL", _
    wbemFlagReturnImmediately + wbemFlagForwardOnly)
    strIPAddress = Join(objItem.IPAddress, ",")
    WScript.Echo "IPAddress: " & strIPAddress
    Next
    Function WMIDateStringToDate(dtmDate)
    WScript.Echo dtm:
    WMIDateStringToDate = CDate(Mid(dtmDate, 5, 2) & "/" & _
    Mid(dtmDate, 7, 2) & "/" & Left(dtmDate, 4) _
    & " " & Mid (dtmDate, 9, 2) & ":" & Mid(dtmDate, 11, 2) & ":" & Mid(dtmDate,13, 2))
    End Function


    Thanks in advance.
    Tom
     
  2. Toulousaing

    Toulousaing New Member

    Joined:
    Oct 26, 2010
    Messages:
    24
    Likes Received:
    0
    No, script did NOT run from command line.
    Try this one:

    Code:
    'On Error Resume Next
    Const wbemFlagReturnImmediately = &h10
    Const wbemFlagForwardOnly = &h20
    arrComputers = Array(".")
    
    For Each strComputer In arrComputers
      Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
      Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem", "WQL", _
          wbemFlagReturnImmediately + wbemFlagForwardOnly)
      For Each objItem In colItems
    
    '   WScript.Echo "Domain: " & objItem.Domain
    '   WScript.Echo "Manufacturer: " & objItem.Manufacturer
    '   WScript.Echo "Model: " & objItem.Model
    '   strBIOS=Join(objitem.Win_32Bios,".")
    '   WScript.Echo "SerialNumber: " & objItem.SerialNumber
        WScript.Echo "Name: " & objItem.Name
    '   WScript.Echo "PrimaryOwnerName: " & objItem.PrimaryOwnerName
      Next
    Next
    
    arrComputers = Array(".")
    
    For Each strComputer In arrComputers
      Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
      Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration", "WQL", _
          wbemFlagReturnImmediately + wbemFlagForwardOnly)
      For Each objItem In colItems
        If isNull(objItem.IPAddress) Then
            Wscript.Echo "IPAddress: "
        Else
            Wscript.Echo "IPAddress: " & Join(objItem.IPAddress, ",")
        End If
      Next
    Next
    wscript.Quit
    
    
    'Function WMIDateStringToDate(dtmDate)
    
    '  WScript.Echo dtm:
    '  WMIDateStringToDate = CDate(Mid(dtmDate, 5, 2) & "/" & _
    '  Mid(dtmDate, 7, 2) & "/" & Left(dtmDate, 4) _
    '  & " " & Mid (dtmDate, 9, 2) & ":" & Mid(dtmDate, 11, 2) & ":" & Mid(dtmDate,13, 2))
    
    'End Function
    
    My 2 € :

    comment out the OERN during debug
    there was a For.. missing
    there was a Next missing
    there was a test for IsNull missing
    the WMIDateStringToDate function was not accepted

    Best,
    DTL
     
    #2 Toulousaing, Nov 14, 2010
    Last edited: Nov 14, 2010
  3. Toulousaing

    Toulousaing New Member

    Joined:
    Oct 26, 2010
    Messages:
    24
    Likes Received:
    0
    (duplicate reply removed)
     

Share This Page

Loading...