![]() | ![]() |
|
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! |
| |||||||
| Software and web development Databases, graphics, programming, scripting and web development. |
![]() |
| | LinkBack | Thread Tools |
| | #5 (permalink) |
| Pixel Abuser 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 (permalink) |
| Member Join Date: Oct 2003
Posts: 93
Thanks: 0
Thanked 0 Times in 0 Posts
| Originally Posted by Spunkey 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 (permalink) |
| bored out of my tiny mind Join Date: Jul 2003 Location: Berkshire
Posts: 3,023
Thanks: 51
Thanked 55 Times in 48 Posts
| 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 (permalink) |
| Member Join Date: Oct 2003
Posts: 93
Thanks: 0
Thanked 0 Times in 0 Posts
| Originally Posted by malfunction 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 (permalink) |
| bored out of my tiny mind Join Date: Jul 2003 Location: Berkshire
Posts: 3,023
Thanks: 51
Thanked 55 Times in 48 Posts
| 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 |
| | |
| | #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
Thanks |
| | |
| | #13 (permalink) |
| bored out of my tiny mind Join Date: Jul 2003 Location: Berkshire
Posts: 3,023
Thanks: 51
Thanked 55 Times in 48 Posts
| 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 (permalink) |
| Member Join Date: Oct 2003
Posts: 93
Thanks: 0
Thanked 0 Times in 0 Posts
| Originally Posted by malfunction 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 (permalink) |
| bored out of my tiny mind Join Date: Jul 2003 Location: Berkshire
Posts: 3,023
Thanks: 51
Thanked 55 Times in 48 Posts
| Originally Posted by clipse 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 (permalink) |
| Member Join Date: Oct 2003
Posts: 93
Thanks: 0
Thanked 0 Times in 0 Posts
| Originally Posted by malfunction 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 |
| | |
![]() |
| Breadcrumb | ||||||
| ||||||
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| hijackthis help | carrcn | Help - technical & advisory | 15 | 30-08-2004 05:52 PM |