cdob Posted August 9, 2010 Share Posted August 9, 2010 Dim someVarNamesomeVarName = "the exact same stuf you used to pass to wsh.Run goes here" MsgBox someVarNamewsh.Run someVarNameThanks. Actual idea was a option to provide debug informations.Imagine ISO build failed at end user. Log some informations. If a error occour, open notepad.Ask the end user to post the log file. Hopefully the error source can be detected that way.This stuff has been around for a decade That's pretty young Still a "Tales of Mystery and Imagination".Corrections happily appreciated.Option ExplicitConst bootsect = "bootsect.bin"Dim fso, wsh, shl, fld, src, locpath, valid, bootableDim MkisofsParams, wshExec, stdoutline, objDebugOutFile, LogFileNameSet fso = CreateObject("Scripting.FileSystemObject")Set wsh = WScript.CreateObject("WScript.Shell")CheckStartModelocpath=Left(WScript.ScriptFullName,(Len(WScript.ScriptFullName)-Len(Wscript.ScriptName)))If Not fso.FileExists(locpath & "mkisofs.exe") Then MsgBox "mkiofs.exe missing", 16, "Error" 'vbOKOnly=0 vbCritical=16 WScript.Quit(1)End Ifvalid=falsebootable=falseIf WScript.Arguments.Count = 1 Then src=WScript.Arguments(0) ValidateSourcePath()End IfIf Not valid Then Set shl=CreateObject("Shell.Application") While Not valid Set fld=shl.BrowseForFolder(0, "Select source",16,17) '16=BIF_EDITBOX; 17=ssfDRIVES If fld Is Nothing Then WScript.Quit(1) src=fld.Self.Path Set fld=Nothing ValidateSourcePath() Wend Set shl=NothingEnd IfLogFileName = locpath & "mkisofs.log"Set objDebugOutFile = fso.CreateTextFile(LogFileName,True) objDebugOutFile.WriteLine("script " & WScript.ScriptFullName)objDebugOutFile.WriteLine("locpath: " & locpath)objDebugOutFile.WriteLine("source: " & src & vbCrLf)If bootable And Not fso.FileExists(locpath & "bootsect\" & bootsect) Then MsgBox "Boot sector missing (" & bootsect & ")", 16, "Error" WScript.Quit(1)End IfMkisofsParams = "-iso-level 4 -joliet-long -duplicates-once -force-uppercase" & _ " -sysid ""Win32"" -V ""Windows"" -m thumbs.db" & _ " -o """ & src & ".iso""" & " """ & src & """ """ & locpath & "bootsect"""If bootable Then MkisofsParams = "-no-emul-boot -b " & bootsect & _ " -hide boot.catalog -hide " & bootsect & _ " -hide-joliet boot.catalog -hide-joliet " & bootsect & _ " " & MkisofsParamsEnd IfMkisofsParams = locpath & "mkisofs.exe " & MkisofsParamsobjDebugOutFile.WriteLine(locpath & MkisofsParams & vbCrLf)Wscript.Echo MkisofsParams & vbCrLfSet wshExec = wsh.Exec(MkisofsParams)Do While wshExec.Status = 0 stdoutline=wshExec.StdErr.Readline 'Wscript.StdOut.WriteLine stdoutline 'write to standard output Wscript.Echo stdoutline objDebugOutFile.WriteLine(stdoutline) 'write to file at the same timeLoopobjDebugOutFile.CloseIf wshExec.ExitCode <> 0 then 'Wscript.Echo vbCrLf & "ErrorCode: " & wshExec.ExitCode wsh.Run "notepad.exe " & LogFileNameEnd IfSub ValidateSourcePath()If fso.FileExists(src) Then src=fso.GetParentFolderName(src)If Not fso.FolderExists(src) Then Exit SubIf fso.FolderExists(src & "\i386") Then valid=true bootable=true Else If MsgBox("The specified folder doesn't contain Windows XP" & chr(13) & chr(10) & "Create a data CD instead?", 36, "Warning") = 6 Then 'vbYesNo=4 vbQuestion=32 valid=true bootable=false End IfEnd IfEnd Sub' http://ask.metafilter.com/79481/vbscript-printing-to-command-lineSub CheckStartMode Dim strStartExe ' Returns the running executable as upper case from the last \ symbol strStartExe = UCase( Mid( wscript.fullname, instrRev(wscript.fullname, "\") + 1 ) ) If Not strStartExe = "CSCRIPT.EXE" Then ' This wasn't launched with cscript.exe, so relaunch using cscript.exe explicitly! ' wscript.scriptfullname is the full path to the actual script wsh.Run "cscript.exe """ & wscript.scriptfullname & """" wscript.quit End IfEnd Sub Link to comment Share on other sites More sharing options...
CoffeeFiend Posted August 10, 2010 Share Posted August 10, 2010 The main issue I see is if someone who has wscript as a default instead of cscript, the check you added will re-start it using cscript, but without the original cmd line args.You could change: wsh.Run "cscript.exe """ & wscript.scriptfullname & """"for wsh.Run "cscript.exe """ & wscript.scriptfullname & """" & " " & WScript.Arguments(0)but then that will fail if someone started the script without any parameters (and it wouldn't pass potential "extra" parameters either). So the ideal way around this is building another string, containing all cmd line args (if any), then passing those on, like such: Dim argsToPass, arg For Each arg In WScript.Arguments argsToPass = argsToPass & arg & " " Next If Len(argsToPass) > 1 Then argsToPass = Left(argsToPass, Len(argsToPass)-1) 'trim unecessary trailing space wsh.Run "cscript.exe """ & wscript.scriptfullname & """ " & argsToPassOtherwise there's no other issues with it. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now