View Single Post
Old 24-02-2005, 10:19 AM   #6 (permalink)
clipse
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