Hi
As title please
Thanks
Hi
As title please
Thanks
Well... Though they're similar they aren't the same. You can use the same objects and methods though - have a look at MSDN...
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
What does the script do? Any chance of posting it / non sensitive sections of it? And why convert it?
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:Originally Posted by rubbishrubbishrubbishrubbishrubbishey
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 ----
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
HiOriginally Posted by malfunction
I still cannot work out how to get the WMI to run as part of a VB application, and google is no help
Thanks
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
I have worked it out now- I was referencing the wrong library Thanks for all the help.
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.
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:
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?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
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.Originally Posted by malfunction
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" ?Originally Posted by clipse
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)
HiOriginally Posted by malfunction
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
There are currently 1 users browsing this thread. (0 members and 1 guests)