Jump to content
Strawberry Orange Banana Lime Leaf Slate Sky Blueberry Grape Watermelon Chocolate Marble
Strawberry Orange Banana Lime Leaf Slate Sky Blueberry Grape Watermelon Chocolate Marble

MSFN is made available via donations, subscriptions and advertising revenue. The use of ad-blocking software hurts the site. Please disable ad-blocking software or set an exception for MSFN. Alternatively, register and become a site sponsor/subscriber and ads will be disabled automatically. 


Sign in to follow this  
Kelsenellenelvian

Need a 3 choice cmd file

Recommended Posts

Dim someVarName

someVarName = "the exact same stuf you used to pass to wsh.Run goes here"

MsgBox someVarName

wsh.Run someVarName

Thanks. 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 Explicit

Const bootsect = "bootsect.bin"
Dim fso, wsh, shl, fld, src, locpath, valid, bootable
Dim MkisofsParams, wshExec, stdoutline, objDebugOutFile, LogFileName

Set fso = CreateObject("Scripting.FileSystemObject")
Set wsh = WScript.CreateObject("WScript.Shell")

CheckStartMode

locpath=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 If
valid=false
bootable=false

If WScript.Arguments.Count = 1 Then
src=WScript.Arguments(0)
ValidateSourcePath()
End If

If 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=Nothing
End If

LogFileName = 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 If

MkisofsParams = "-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 & _
" " & MkisofsParams
End If

MkisofsParams = locpath & "mkisofs.exe " & MkisofsParams
objDebugOutFile.WriteLine(locpath & MkisofsParams & vbCrLf)
Wscript.Echo MkisofsParams & vbCrLf
Set 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 time
Loop
objDebugOutFile.Close

If wshExec.ExitCode <> 0 then
'Wscript.Echo vbCrLf & "ErrorCode: " & wshExec.ExitCode
wsh.Run "notepad.exe " & LogFileName
End If

Sub ValidateSourcePath()
If fso.FileExists(src) Then src=fso.GetParentFolderName(src)
If Not fso.FolderExists(src) Then Exit Sub
If 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 If
End If
End Sub

' http://ask.metafilter.com/79481/vbscript-printing-to-command-line
Sub 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 If
End Sub

Share this post


Link to post
Share on other sites

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 & """ " & argsToPass

Otherwise there's no other issues with it.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...