• HEXUS
  • HEXUS.tv
  • channel
  • gaming
  • lifestyle
  • trust
  • community
  • ESReality
  • HEXUS.community discussion forumsVisit Corsair.com

    Welcome to the HEXUS.community discussion forums forums.

    You are currently viewing our boards as a guest which gives you limited access to view most discussions and other features. By joining our free community you will have access to post topics, respond to polls and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

    Go Back   HEXUS.community discussion forums > HEXUS.help - buying advice & technical queries > Operating systems & applications > Software and web development

    Software and web development Databases, graphics, programming, scripting and web development.

    Reply
     
    LinkBack Thread Tools
    Old 23-02-2005, 10:52 PM   #1 (permalink)
    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
    clipse is offline   Reply With Quote
    Old 23-02-2005, 10:53 PM   #2 (permalink)
    bored out of my tiny mind
     
    malfunction's Avatar
     
    Join Date: Jul 2003
    Location: Berkshire
    Posts: 3,023
    Thanks: 51
    Thanked 55 Times in 48 Posts
    malfunction's system
    Well... Though they're similar they aren't the same. You can use the same objects and methods though - have a look at MSDN...
    malfunction is offline   Reply With Quote
    Old 23-02-2005, 11:20 PM   #3 (permalink)
    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
    clipse is offline   Reply With Quote
    Old 23-02-2005, 11:54 PM   #4 (permalink)
    bored out of my tiny mind
     
    malfunction's Avatar
     
    Join Date: Jul 2003
    Location: Berkshire
    Posts: 3,023
    Thanks: 51
    Thanked 55 Times in 48 Posts
    malfunction's system
    What does the script do? Any chance of posting it / non sensitive sections of it? And why convert it?
    malfunction is offline   Reply With Quote
    Old 24-02-2005, 09:33 AM   #5 (permalink)
    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

    Spunkey is offline   Reply With Quote
    Old 24-02-2005, 10:19 AM   #6 (permalink)
    Member
     
    Join Date: Oct 2003
    Posts: 93
    Thanks: 0
    Thanked 0 Times in 0 Posts
    Originally Posted by Spunkey
    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 ----
    
    clipse is offline   Reply With Quote
    Old 24-02-2005, 10:50 AM   #7 (permalink)
    bored out of my tiny mind
     
    malfunction's Avatar
     
    Join Date: Jul 2003
    Location: Berkshire
    Posts: 3,023
    Thanks: 51
    Thanked 55 Times in 48 Posts
    malfunction's system
    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
    malfunction is offline   Reply With Quote
    Old 24-02-2005, 04:12 PM   #8 (permalink)
    Member
     
    Join Date: Oct 2003
    Posts: 93
    Thanks: 0
    Thanked 0 Times in 0 Posts
    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
    clipse is offline   Reply With Quote
    Old 24-02-2005, 04:14 PM   #9 (permalink)
    bored out of my tiny mind
     
    malfunction's Avatar
     
    Join Date: Jul 2003
    Location: Berkshire
    Posts: 3,023
    Thanks: 51
    Thanked 55 Times in 48 Posts
    malfunction's system
    How about this:

    http://www.freevbcode.com/ShowCode.asp?ID=6719

    #1 result for this search:

    http://www.google.co.uk/search?q=wmi...en-GB:official
    malfunction is offline   Reply With Quote
    Old 24-02-2005, 04:17 PM   #10 (permalink)
    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.
    clipse is offline   Reply With Quote
    Old 24-02-2005, 04:26 PM   #11 (permalink)
    bored out of my tiny mind
     
    malfunction's Avatar
     
    Join Date: Jul 2003
    Location: Berkshire
    Posts: 3,023
    Thanks: 51
    Thanked 55 Times in 48 Posts
    malfunction's system
    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.
    malfunction is offline   Reply With Quote
    Old 24-02-2005, 10:53 PM   #12 (permalink)
    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
    clipse is offline   Reply With Quote
    Old 24-02-2005, 11:29 PM   #13 (permalink)
    bored out of my tiny mind
     
    malfunction's Avatar
     
    Join Date: Jul 2003
    Location: Berkshire
    Posts: 3,023
    Thanks: 51
    Thanked 55 Times in 48 Posts
    malfunction's system
    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)
    malfunction is offline   Reply With Quote
    Old 24-02-2005, 11:48 PM   #14 (permalink)
    Member
     
    Join Date: Oct 2003
    Posts: 93
    Thanks: 0
    Thanked 0 Times in 0 Posts
    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.
    clipse is offline   Reply With Quote
    Old 24-02-2005, 11:54 PM   #15 (permalink)
    bored out of my tiny mind
     
    malfunction's Avatar
     
    Join Date: Jul 2003
    Location: Berkshire
    Posts: 3,023
    Thanks: 51
    Thanked 55 Times in 48 Posts
    malfunction's system
    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)
    malfunction is offline   Reply With Quote
    Old 25-02-2005, 12:04 AM   #16 (permalink)
    Member
     
    Join Date: Oct 2003
    Posts: 93
    Thanks: 0
    Thanked 0 Times in 0 Posts
    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
    clipse is offline   Reply With Quote
    Reply

    Breadcrumb
    Go Back   HEXUS.community discussion forums > HEXUS.help - buying advice & technical queries > Operating systems & applications > Software and web development


    Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
     
    Thread Tools

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off
    Trackbacks are On
    Pingbacks are On
    Refbacks are On


    Similar Threads
    Thread Thread Starter Forum Replies Last Post
    hijackthis help carrcn Help - technical & advisory 15 30-08-2004 05:52 PM



    All times are GMT. The time now is 08:47 AM.

    Any representations/statements made on the HEXUS.community discussion forums are the representations/statements of the author i.e. the person/organisation making them. If any such representations/statements are disputed they are a matter between the parties concerned. HEXUS Limited accepts no responsibility for any misrepresentations, inaccurate or false statements made by any person/organisation other than HEXUS Limited employees.

    Hosted Exchange

    Powered by vBulletin® Version 3.8.4
    Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
    Content Relevant URLs by vBSEO 3.3.2
    © Copyright 2009 HEXUS® Limited. All rights reserved. Unauthorised reproduction strictly prohibited.