Page 1 of 2 12 LastLast
Results 1 to 16 of 21

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

  1. #1
    Member
    Join Date
    Oct 2003
    Posts
    93
    Thanks
    0
    Thanked
    0 times in 0 posts

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

    Hi

    As title please

    Thanks

  2. #2
    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... Though they're similar they aren't the same. You can use the same objects and methods though - have a look at MSDN...

  3. #3
    Member
    Join Date
    Oct 2003
    Posts
    93
    Thanks
    0
    Thanked
    0 times in 0 posts
    I have searched MSDN but can't really find anything to answer my questions, perhaps I'm just being stupid. Anyone willing to help a bit more?

    Thanks

  4. #4
    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
    What does the script do? Any chance of posting it / non sensitive sections of it? And why convert it?

  5. #5
    Pixel Abuser Spunkey's Avatar
    Join Date
    Nov 2003
    Location
    Milton Keynes
    Posts
    1,523
    Thanks
    0
    Thanked
    0 times in 0 posts
    vbscript should run in vb6
    admittedly they are different languages, but VBS has the same process flow and syntax, just that it is missing several components.

    As malfunction says, if you can post the code we'll cast a beady over it for you

  6. #6
    Member
    Join Date
    Oct 2003
    Posts
    93
    Thanks
    0
    Thanked
    0 times in 0 posts
    Quote Originally Posted by rubbishrubbishrubbishrubbishrubbishey
    vbscript should run in vb6
    admittedly they are different languages, but VBS has the same process flow and syntax, just that it is missing several components.

    As malfunction says, if you can post the code we'll cast a beady over it for you
    It's still in the early stages but this is the WSH file:

    Code:
    option explicit
    ' ---- BEGIN Callout 1 ----
    Dim objFileSystem, objOutputFile
    Dim strOutputFile
    
    ' generate a filename base on the script name
    strOutputFile = "./" & Split(WScript.ScriptName, ".")(0) & ".out"
    
    Set objFileSystem = CreateObject("Scripting.fileSystemObject")
    Set objOutputFile = objFileSystem.CreateTextFile(strOutputFile, TRUE)
    
    dim console
    set console = new cliwrapper
    
    objOutputFile.WriteLine console.exec("ipconfig /all | find ""Description""")
    objOutputFile.WriteLine console.exec("ipconfig /all | find ""IP Address""")
    objOutputFile.WriteLine console.exec("ipconfig /all | find ""Physical Address""")
    objOutputFile.WriteLine console.exec("ipconfig /all | find ""DHCP Enabled""")
    objOutputFile.WriteLine console.exec("ipconfig /all | find ""Subnet Mask""")
    objOutputFile.WriteLine console.exec("ipconfig /all | find ""Default Gateway""")
    objOutputFile.WriteLine console.exec("ipconfig /all | find ""DNS Servers""")
    objOutputFile.Close
    
    Set objFileSystem = Nothing
    
    ' ---- END Callout 1 ----
    
    
    ' ---- BEGIN Callout 2 ----
    Class CliWrapper
    
    	public stdout, stderr, command
    	private sh, fso, syncmode, outfile, errfile
    	private ForReading, TristateUseDefault, DoNotCreateFile
    	
    	public function Exec(sCmd)
    		' clean out old stdout and stderr
    		stdout = vbNullString: stderr = vbNullString
    		' keep the sCmd value for troubleshooting
    		' we expand it the way the Windows shell will
    		command = sh.ExpandEnvironmentStrings(sCmd)
    		sh.Run "%COMSPEC% /c " & sCmd & " 2>" & errfile _
    			& " 1>" & outfile, 0, syncmode
    		stderr = ProcessFile(errfile)
    		stdout = ProcessFile(outfile)
    		Exec = stdout
    	end function
    	
    	private sub class_initialize
    		' for speed of use over time
    		Set sh = createobject("WScript.Shell")
    		Set fso = createobject("Scripting.FileSystemObject")
    		ForReading = 1:	TristateUseDefault = -2
    		DoNotCreateFile = false
    		outfile = fso.GetTempName
    		errfile = fso.GetTempName
    		syncmode = true
    	end sub
    
    	private function ProcessFile(filepath)
    		' given the path to a file, will return entire contents
    		if fso.FileExists(filepath) then
    			with fso.OpenTextFile(filepath, ForReading, _
    				false, TristateUseDefault)
    				if .AtEndOfStream <> true then
    					ProcessFile = .ReadAll
    				end if
    				.Close
    				fso.DeleteFile(filepath)
    			end with
    		end if	
    	end function
    
    end class
    ' ---- END Callout 2 ----

  7. #7
    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
    That all looks fairly sensible - one big obvious problem is that I doubt you'll have access to "WScript.Shell" in VB6 though there will be a way to call external processes. On a different note have you heard about "WMI":

    http://www.microsoft.com/technet/scr...t/default.mspx

    The root of the script "repository" is here:

    http://www.microsoft.com/technet/scr...s/default.mspx

  8. #8
    Member
    Join Date
    Oct 2003
    Posts
    93
    Thanks
    0
    Thanked
    0 times in 0 posts
    Quote Originally Posted by malfunction
    That all looks fairly sensible - one big obvious problem is that I doubt you'll have access to "WScript.Shell" in VB6 though there will be a way to call external processes. On a different note have you heard about "WMI":

    http://www.microsoft.com/technet/scr...t/default.mspx

    The root of the script "repository" is here:

    http://www.microsoft.com/technet/scr...s/default.mspx
    Hi

    I still cannot work out how to get the WMI to run as part of a VB application, and google is no help

    Thanks

  9. #9
    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

  10. #10
    Member
    Join Date
    Oct 2003
    Posts
    93
    Thanks
    0
    Thanked
    0 times in 0 posts
    I have worked it out now- I was referencing the wrong library Thanks for all the help.

  11. #11
    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
    No probs. If you want or need specific VBS / WSH help post back but I don't do VB6 / have it installed so can only do guesswork for you.

  12. #12
    Member
    Join Date
    Oct 2003
    Posts
    93
    Thanks
    0
    Thanked
    0 times in 0 posts
    Hi

    I have the following little program so far. I have got it to output the network name, description, and MAC into a little form. (I havent formatted the output or anything yet, mainly cause I don't know how to yet!)

    However, I can't get a MAC to appear in Windows ME. It's fine in XP and 2000. Here is the code:

    Code:
    Private Sub Command1_Click()
    
    On Error Resume Next
    
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    
    Set colItems = objWMIService.ExecQuery("Select * from Win32_NetworkAdapter")
    For Each objItem In colItems
    
        If objItem.MACAddress <> "" Then
        ListView1.ListItems.Add = (objItem.AdapterType) 'Adapter Type
        'Listview1.Width= ADJUST WIDTH!
     
       ' Select Case objItem.AdapterTypeID
         '   Case 0 strAdapterType = "Ethernet 802.3"
          '  Case 1 strAdapterType = "Token Ring 802.5"
           ' Case 2 strAdapterType = "Fiber Distributed Data Interface (FDDI)"
           ' Case 3 strAdapterType = "Wide Area Network (WAN)"
           ' Case 4 strAdapterType = "LocalTalk"
           ' Case 5 strAdapterType = "Ethernet using DIX header format"
           ' Case 6 strAdapterType = "ARCNET"
           ' Case 7 strAdapterType = "ARCNET (878.2)"
          '  Case 8 strAdapterType = "ATM"
          '  Case 9 strAdapterType = "Wireless"
          '  Case 10 strAdapterType = "Infrared Wireless"
          '  Case 11 strAdapterType = "Bpc"
          '  Case 12 strAdapterType = "CoWan"
           ' Case 13 strAdapterType = "1394"
      '  End Select
     
        'MsgBox ("Adapter Type Id: " & strAdapterType)
        'MsgBox ("AutoSense: " & objItem.AutoSense)
        ListView1.ListItems.Add = ("Description: " & objItem.Description)
        'MsgBox ("Device ID: " & objItem.DeviceID)
        Wscript.Echo "Index: " & objItem.Index
        ListView1.ListItems.Add = ("MAC: " & objItem.MACAddress) 'MAC Address
        Wscript.Echo "Manufacturer: " & objItem.Manufacturer
        Wscript.Echo "Maximum Number Controlled: " & objItem.MaxNumberControlled
        Wscript.Echo "Maximum Speed: " & objItem.MaxSpeed
        Wscript.Echo "Name: " & objItem.Name
        Wscript.Echo "Net Connection ID: " & objItem.NetConnectionID
        Wscript.Echo "Net Connection Status: " & objItem.NetConnectionStatus
        For Each strNetworkAddress In objItem.NetworkAddresses
            Label1.Caption = "NetworkAddress: " & strNetworkAddress
        Next
        'ListView1.ListItems.Add = ("Permanent Address: " & objItem.PermanentAddress)
        'ListView1.ListItems.Add = ("PNP Device ID: " & objItem.PNPDeviceID)
        'ListView1.ListItems.Add = (objItem.ProductName) 'Product Name
        'ListView1.ListItems.Add = ("Service Name: " & objItem.ServiceName)
        'ListView1.ListItems.Add = ("Speed: " & objItem.Speed)
        ListView1.ListItems.Add = ("END OF ITEM")
        
        End If
    Next
    
    End Sub
    
    Private Sub Form_Load()
    With ListView1
          .ListItems.Clear
          .ColumnHeaders.Clear
          .ColumnHeaders.Add , , "Adapter Type"
          .ColumnHeaders.Add , , "MAC Address"
          .ColumnHeaders.Add , , "Type"
          .ColumnHeaders.Add , , "Manufacturer"
          .ColumnHeaders.Add , , "Description"
          .View = lvwReport
          .Sorted = False
       End With
    End Sub
    Is there something wrong with my code or is it impossible to make it appear? Google and MSDN suggests it cannot be done though, as I can't find anything really on it. Would it work if the user installed WSH 5.x or whatever?

    Thanks

  13. #13
    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
    It may well be that the version of the object / class in windows ME doesn't support the method / field to get the mac address... In that respect the older method you were using (calling ipconfig and parsing the output) would give you more info on more platforms but is obviously a bit of a kludge (still if it works)... What are you actually trying to do anyway (MAC addresses aren't usually used for much for example)

  14. #14
    Member
    Join Date
    Oct 2003
    Posts
    93
    Thanks
    0
    Thanked
    0 times in 0 posts
    Quote Originally Posted by malfunction
    It may well be that the version of the object / class in windows ME doesn't support the method / field to get the mac address... In that respect the older method you were using (calling ipconfig and parsing the output) would give you more info on more platforms but is obviously a bit of a kludge (still if it works)... What are you actually trying to do anyway (MAC addresses aren't usually used for much for example)
    I am basically trying to build a system that can be use to troubleshoot faults for students connecting their own PCs to the JANET network through their halls of residence.

    Each network port in each room is locked to a certain MAC. I need to extract that MAC so if all else fails it can be sent to the help desk to see if a bad MAC (i.e user reported the wrong MAC) is causing the problem.

  15. #15
    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
    Quote Originally Posted by clipse
    I am basically trying to build a system that can be use to troubleshoot faults for students connecting their own PCs to the JANET network through their halls of residence.

    Each network port in each room is locked to a certain MAC. I need to extract that MAC so if all else fails it can be sent to the help desk to see if a bad MAC (i.e user reported the wrong MAC) is causing the problem.
    Sounds interesting. If their only network connection is to JANET though (and that connection isn't working) how are you going to get the info off the student's PC? Will there be some kind of DMZ / public server the PC will still be able to post to? If the 'report' / output from the program is going to someone in the know though why don't you just send them the entire unedited output from "ipconfig /all" ?

    If you're planning on emailing the data out it's nice and easy through CDO (I have some example VBScript code I can dig out for you if you like)

  16. #16
    Member
    Join Date
    Oct 2003
    Posts
    93
    Thanks
    0
    Thanked
    0 times in 0 posts
    Quote Originally Posted by malfunction
    Sounds interesting. If their only network connection is to JANET though (and that connection isn't working) how are you going to get the info off the student's PC? Will there be some kind of DMZ / public server the PC will still be able to post to? If the 'report' / output from the program is going to someone in the know though why don't you just send them the entire unedited output from "ipconfig /all" ?

    If you're planning on emailing the data out it's nice and easy through CDO (I have some example VBScript code I can dig out for you if you like)
    Hi

    No there is no such setup in place. The idea is that the student runs the troubleshooting utility to try and solve the problem. If it fails to work, the program snaphots their NIC's MAC, their obtained IP address, link speed/ duplex settings, and other bits as well as the results of the troubleshooting walkthrough and dumps it into a file which the student then gets from their PC to a PC with an Internet connection using a USB drive/ floppy disc or whatever and e-mails it to the help desk. It's a tad primitive I know, but there is no other way of getting the file from their PC at present

    As you have probably guessed, I am new to VB and WMI, WSH etc, but looking through VB's References menu, there is a WSH controller library, which I assume allows me to adapt WSH- based files to run in the VB window? If that is the case, I could have the script I originally posted dump the result into a .out file along with some other info to be sent to the help desk? Only problem is VB doesn't seem to let me adapt it to work Ah well presuming that is what this library is designed to do, I will have another crack at it tomorrow.

    Thanks

Page 1 of 2 12 LastLast

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
  •