Page 2 of 2 FirstFirst 12
Results 17 to 21 of 21

Thread: How do I make a VBscript (WSH based) run in VB6?

  1. #17
    bored out of my tiny mind malfunction's Avatar
    Join Date
    Jul 2003
    Location
    Lurking
    Posts
    3,923
    Thanks
    191
    Thanked
    187 times in 163 posts
    • malfunction's system
      • Motherboard:
      • Gigabyte G1.Sniper (with daft heatsinks and annoying Killer NIC)
      • CPU:
      • Xeon X5670 (6 core LGA 1366) @ 4.4GHz
      • Memory:
      • 48GB DDR3 1600 (6 * 8GB)
      • Storage:
      • 1TB 840 Evo + 1TB 850 Evo
      • Graphics card(s):
      • 290X
      • PSU:
      • Antec True Power New 750W
      • Case:
      • Cooltek W2
      • Operating System:
      • Windows 10
      • Monitor(s):
      • Dell U2715H
    Well there's no reason why you couldn't just use vbscript to do the whole thing anyway... Or even just a simple batch file to pipe the output of ipconfig/all to a file - e.g

    ipconfig /all >c:\ipconfig.txt

    Though if you use something like WMI you could also collect other info (OS version for example)... It would be more work but a better way might be to produce an ISP style dial up / access CD (or just a program) that you can hand out to students that basically requires them to only:

    1) Get the program on the PC (e.g. insert CD)
    2) Program autoruns if possible
    3) Program asks for validated user id / password (printed separately)
    4) These are submitted to some kind of 'public' / DMZ part of the uni's infrastructure and if they are accepted the program then uploads the MAC address, etc and configures the client PC as appropriate

    Just a thought anyway

  2. #18
    Member
    Join Date
    Oct 2003
    Posts
    93
    Thanks
    0
    Thanked
    0 times in 0 posts
    Quote Originally Posted by malfunction
    Well there's no reason why you couldn't just use vbscript to do the whole thing anyway... Or even just a simple batch file to pipe the output of ipconfig/all to a file - e.g

    ipconfig /all >c:\ipconfig.txt

    Though if you use something like WMI you could also collect other info (OS version for example)... It would be more work but a better way might be to produce an ISP style dial up / access CD (or just a program) that you can hand out to students that basically requires them to only:

    1) Get the program on the PC (e.g. insert CD)
    2) Program autoruns if possible
    3) Program asks for validated user id / password (printed separately)
    4) These are submitted to some kind of 'public' / DMZ part of the uni's infrastructure and if they are accepted the program then uploads the MAC address, etc and configures the client PC as appropriate

    Just a thought anyway
    Yes that's why I was looking at using WSH & WMI in the first place- to collect this information on user's machines. I don't mind using WSH to dump the output of IPconfig into a file and then using VB to go through and extract the info I want (as this seems to work with all versions of Windows). I just dont know how to actually make that happen in VB...

  3. #19
    Member
    Join Date
    Oct 2003
    Posts
    93
    Thanks
    0
    Thanked
    0 times in 0 posts
    Ok I give up trying to make this damn thing work in VB6. Could a Java applet return the local mac address, IP address etc? as I have an idea for a nice clean implementation if it does.

    Thanks

  4. #20
    Registered User
    Join Date
    May 2004
    Location
    Newcastle
    Posts
    42
    Thanks
    0
    Thanked
    1 time in 1 post
    • Brodieman's system
      • Motherboard:
      • ASUS P5N32-E SLI
      • CPU:
      • Intel Core2Duo 6600
      • Memory:
      • 4GB
      • Storage:
      • 2x320GB
      • Graphics card(s):
      • 640Mb XFX nVidia 8800 GTS
      • Monitor(s):
      • 22" Wide Screen LG
      • Internet:
      • 20mb Cable
    Okay you have an issue with your code...

    You'll kick yourself tbh...

    why are you using
    Wscript.Echo "Index: " & objItem.Index?

    Wscript is an object of WSH and echo is one of it's methods....

    repleace wscript.echo with well
    msgbox or something along the lines of

    dim strNetworkInfo

    strNetworkInfo = ""
    strNetworkInfo = "Index: " & objItem.Index & vbcr + vblf
    strNetworkInfo = strNetworkInfo & "Manufacturer: " & objItem.Manufacturer

    msgbox strNetworkInfo

    etc etc etc.... let me know if this works for you.. if not i'll have a play...

    As regarding it not displaying Windows ME info.... well what do you expect...
    You are getting information from the machines WMI and the version is slightly different... you should however beable to get most of the information..

    Hope this helps...

    That is if your still working on it...

    BTW if you want a good book on this you may want to get hold of the Microsoft Press Scripting book... would give you the exact name but i lent it to a sysadmin mate about 3 months back....

    Good luck

    If it don't work.. let me know and i'll see if I can put an app toegther for you with comments etc etc so you can see what I did.
    Last edited by Brodieman; 08-03-2005 at 02:43 PM.

  5. #21
    Registered User
    Join Date
    May 2004
    Location
    Newcastle
    Posts
    42
    Thanks
    0
    Thanked
    1 time in 1 post
    • Brodieman's system
      • Motherboard:
      • ASUS P5N32-E SLI
      • CPU:
      • Intel Core2Duo 6600
      • Memory:
      • 4GB
      • Storage:
      • 2x320GB
      • Graphics card(s):
      • 640Mb XFX nVidia 8800 GTS
      • Monitor(s):
      • 22" Wide Screen LG
      • Internet:
      • 20mb Cable
    Okay I've developed a little app....

    I got it fully work.. any issues let me know.

    Cheers

    Stu

    **************************8

    Open notepad
    Save the below text in a file called frmMain.frm

    Code:
    VERSION 5.00
    Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
    Begin VB.Form frmMain 
       Caption         =   "Nexus Demo: Network Adaptor Test"
       ClientHeight    =   3495
       ClientLeft      =   60
       ClientTop       =   450
       ClientWidth     =   5880
       LinkTopic       =   "Form1"
       ScaleHeight     =   3495
       ScaleWidth      =   5880
       StartUpPosition =   3  'Windows Default
       Begin VB.Frame fraDetails 
          Caption         =   "Results"
          Height          =   2415
          Left            =   120
          TabIndex        =   1
          Top             =   960
          Width           =   5655
          Begin MSComctlLib.ListView lstvResults 
             Height          =   2055
             Left            =   120
             TabIndex        =   5
             Top             =   240
             Width           =   5415
             _ExtentX        =   9551
             _ExtentY        =   3625
             View            =   3
             LabelWrap       =   -1  'True
             HideSelection   =   -1  'True
             AllowReorder    =   -1  'True
             FullRowSelect   =   -1  'True
             GridLines       =   -1  'True
             _Version        =   393217
             ForeColor       =   -2147483640
             BackColor       =   -2147483643
             BorderStyle     =   1
             Appearance      =   1
             NumItems        =   0
          End
       End
       Begin VB.Frame fraComputer 
          Height          =   735
          Left            =   120
          TabIndex        =   0
          Top             =   120
          Width           =   5655
          Begin VB.CommandButton cmdRun 
             Caption         =   "&Run"
             Height          =   255
             Left            =   4920
             TabIndex        =   4
             Top             =   240
             Width           =   615
          End
          Begin VB.TextBox txtComputerName 
             Height          =   285
             Left            =   1560
             TabIndex        =   3
             Text            =   "."
             Top             =   240
             Width           =   3135
          End
          Begin VB.Label lblComputerName 
             Caption         =   "Computer Name:"
             Height          =   255
             Left            =   120
             TabIndex        =   2
             Top             =   240
             Width           =   1335
          End
       End
    End
    Attribute VB_Name = "frmMain"
    Attribute VB_GlobalNameSpace = False
    Attribute VB_Creatable = False
    Attribute VB_PredeclaredId = True
    Attribute VB_Exposed = False
    Private Sub cmdRun_Click()
    
    On Error GoTo Errorhandler
    
        Screen.MousePointer = vbHourglass
        
        Dim strAdaptertype As String
        
        ClearData
        
        strComputer = txtComputerName.Text      ' name of the computer we are going to query the WMI of..
                                                ' You could if you have network Admin permissions of the machine
                                                ' enter a remote computer name...
                                                ' WMI can actually be used for a lot of things
                                                
        Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
                                                ' Creating the object to connect to the WMI
                                                ' repository, including where in the WMI you are connecting to
    
        Set colItems = objWMIService.ExecQuery("Select * from Win32_NetworkAdapter")
                                                ' Querying the WMI repository, table being the Win32_NetworkAdaptor
    
        
        For Each objitem In colItems
        
            With objitem
        
                If Not IsNull(.MACAddress) Then
    
                Select Case .AdapterTypeID
                    Case Is = 0
                        strAdaptertype = "Ethernet 802.3"
                    Case Is = 1
                        strAdaptertype = "Token Ring 802.5"
                    Case Is = 2
                        strAdaptertype = "Fiber Distributed Data Interface (FDDI)"
                    Case Is = 3
                        strAdaptertype = "Wide Area Network (WAN)"
                    Case Is = 4
                        strAdaptertype = "LocalTalk"
                    Case Is = 5
                        strAdaptertype = "Ethernet using DIX header format"
                    Case Is = 6
                        strAdaptertype = "ARCNET"
                    Case Is = 7
                        strAdaptertype = "ARCNET (878.2)"
                    Case Is = 8
                        strAdaptertype = "ATM"
                    Case Is = 9
                        strAdaptertype = "Wireless"
                    Case Is = 10
                        strAdaptertype = "Infrared Wireless"
                    Case Is = 11
                        strAdaptertype = "Bpc"
                    Case Is = 12
                        strAdaptertype = "CoWan"
                    Case Is = 13
                        strAdaptertype = "1394"
                    Case Else
                        strAdaptertype = "Unknown"
                End Select
     
                Set itmX = frmMain.lstvResults.ListItems.Add(, , strAdaptertype) ' Add the Adapter Type a first element
                itmX.SubItems(1) = .AdapterTypeID       ' Add the Adapter Type ID as the second element
                itmX.SubItems(2) = .AutoSense           ' Add more details... list goes on
                itmX.SubItems(3) = .Description         ' Not all of the information
                itmX.SubItems(4) = .DeviceID            ' will be added as it's not
                itmX.SubItems(5) = .Index               ' neccessarily been implemented
                itmX.SubItems(6) = .MACAddress          ' by microsoft or manufacturers yet....
                itmX.SubItems(7) = .Manufacturer        ' but over time it probably will be
                itmX.SubItems(8) = .MaxNumberControlled ' Information relating to this query can be found at
                itmX.SubItems(9) = .MaxSpeed            ' http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_networkadapter.asp
                itmX.SubItems(10) = .Name               ' Regardless of what overs thing MSDN is your friend
                itmX.SubItems(11) = .NetConnectionID    ' As is google
                itmX.SubItems(12) = .NetConnectionStatus
                itmX.SubItems(13) = .NetworkAddresses
                itmX.SubItems(14) = .PermanentAddress
                itmX.SubItems(15) = .PNPDeviceID
                itmX.SubItems(16) = .ProductName
                itmX.SubItems(17) = .ServiceName
                itmX.SubItems(18) = .Speed
                    
                End If
                
            End With
        Next
     
     
        With lstvResults
            .SortKey = 0                                ' Just sorting the data in the list view, by the Adapter Type
            .Sorted = True                              ' This should put just the 803.2 devices at the top of the list.
            .SortOrder = lvwAscending
       End With
    
        Screen.MousePointer = 0
    Exit Sub
    
    Errorhandler:
    
        If Err.Number = 0 Then
            'no error..
            Exit Sub
        
        ElseIf Err.Number = 13 Then
            Resume Next
        
        ElseIf Err.Number = 92 Then
            Resume Next
        
        Else
            ' unknown error or error that's not handled atm
            MsgBox "An unknown error or an unhandled error has been detected! " & vbCr + vbLf & _
            "Contact your Systems Administrator" & vbCr + vbLf & _
             vbCr + vbLf & _
            "Error Number: " & Err.Number & vbCr + vbLf & _
            "Error Source: " & Err.Source & vbCr + vbLf & _
            "Error Description " & Err.Description _
            , vbExclamation + vbOKOnly, "Error"
            Screen.MousePointer = 0
            Exit Sub
        
        End If
    End Sub
    Private Sub LoadListView()
            
        ' Adding colums to the listview
        With lstvResults
            ClearData
            .ColumnHeaders.Clear
            
            .ColumnHeaders.Add , , "Adapter Type"
            .ColumnHeaders.Add , , "Adapter Type ID"
            .ColumnHeaders.Add , , "Auto Sense"
            .ColumnHeaders.Add , , "Description"
            .ColumnHeaders.Add , , "Device ID"
            .ColumnHeaders.Add , , "Index"
            .ColumnHeaders.Add , , "MAC Address"
            .ColumnHeaders.Add , , "Manufacturer"
            .ColumnHeaders.Add , , "Max Number Controlled"
            .ColumnHeaders.Add , , "Max Speed"
            .ColumnHeaders.Add , , "Name"
            .ColumnHeaders.Add , , "Net Connection ID"
            .ColumnHeaders.Add , , "Net Connection Status"
            .ColumnHeaders.Add , , "Network Addresses"
            .ColumnHeaders.Add , , "Permanent Address"
            .ColumnHeaders.Add , , "PNP Device ID"
            .ColumnHeaders.Add , , "Product Name"
            .ColumnHeaders.Add , , "Service Name"
            .ColumnHeaders.Add , , "Speed"
            .View = lvwReport
            .Sorted = False
            
        End With
    End Sub
    
    Private Sub ClearData()
    
        lstvResults.ListItems.Clear
    End Sub
    
    Private Sub Form_Load()
    
        LoadListView
        
    End Sub
    
    Private Sub lstvResults_ColumnClick(ByVal ColumnHeader As MSComctlLib.ColumnHeader)
    
        With lstvResults
            .SortKey = ColumnHeader.Index - 1
            .Sorted = True
            If .SortOrder = lvwAscending Then
                .SortOrder = lvwDescending
            Else
                .SortOrder = lvwAscending
            End If
        End With
        
    
    End Sub
    Make sure you have the "Microsoft Windows Common Control 6.0 SP4" or above added for the list view to work properly

Page 2 of 2 FirstFirst 12

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. hijackthis help
    By carrcn in forum Help! Quick Relief From Tech Headaches
    Replies: 15
    Last Post: 30-08-2004, 06:52 PM

Posting Permissions

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