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

#1
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
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
 


Last edited:
#3
(duplicate reply removed)
 


This website is not affiliated, owned, or endorsed by Microsoft Corporation. It is a member of the Microsoft Partner Program.
Top