Hello all!
Here is a script for you that I made to avoid using CMDOW with Windows Post-Install, hope it will help!
Upgrading to WPI 5.0 might allso help, since it eliminates wpi.cmd, but you might still want this :-)
You can use it to start programs (e.g. wpi.cmd from Autorun) like this:
OPEN=WScript.exe wpi\lh.vbs wpi.cmd
Note: To avoid putting a long path in there twice, the cmd file is assumed to be in the same folder as the script. (\WPI in the example)
I know it's not very good when it comes to handling arguments, because you will lose quotes...
Here is it:
CODE
' rh.vbs - Run (a cmd batch) hidden - aquarius 11:58 14.12.2005
' Example: WScript.exe wpi\rh.vbs wpi.cmd
' Assumes wpi.cmd is in same folder as rh.vbs
' quoted arguments not handled well...
Dim objArgs, WshShell
Dim strWindowStyle, DebugWait, strCMD, strShellRun, ProgFolder, Prog, strApp, I
Set objArgs = WScript.Arguments
Set WshShell = WScript.CreateObject("WScript.Shell")
Const nDebug = false ' nDebug=true for Debug mode
strWindowStyle = 0
DebugWait = false
strCMD = "Cmd /c "
If nDebug then
strWindowStyle = 1
DebugWait = True
strCMD = "Cmd /c CLS & "
End If
if WScript.Arguments.Count = 0 then
msgbox "strApplication requires an argument" & VbNewline &_
"Example: WScript.exe wpi\rh.vbs wpi.cmd"
WScript.Quit (-1)
End If
' Find folder and program to launch (arg 0) in the same folder as the script
ProgFolder = Left( WScript.ScriptFullName, InStrRev( WScript.ScriptFullName, "\" ))
Prog = objArgs(0)
strApp = """" & ProgFolder & Prog & """"
' Add all arguments (following arg 0 which is the cmd file)
For I = 1 to objArgs.Count - 1
strApp = strApp & " " & objArgs(I)
Next
strShellRun = strCMD & strApp
If nDebug then
if wshShell.Popup( "Do you want to execute " & strShellRun & " ?", 10, "Confirm", 1 ) <> 1 then
wScript.Quit(1)
End If
End If
WScript.Quit (WshShell.Run( strShellRun, strWindowStyle, DebugWait ))
As you can see, you can set the nDebug to true to verify it's actions.
Allso, instead of using CMDOW @ /VIS for handling error messages, here is another script to display error dialogs etc.
CODE
'dialog.vbs - Aquarius, 23:32 15.06.2006
'WScript.exe dialog.vbs "Message" [/T:"Title"] [/S:type] [/W:SecondsToWait]
'The returned errorcode will be like Windows Script Host Popup Method
' except if no arguments where passed, in which case it returns -2
'Put strings with spaces inside quotes (message and title)
Dim WshShell, DlgTitle, nSeconds, nType
Dim argsNamed, argsUnnamed
nSeconds=0
nType=0
set WshShell = WScript.CreateObject("WScript.Shell")
if WScript.Arguments.Count = 0 then
WshShell.Popup "Syntax: wscript.exe dialog.vbs " + chr(34) + "Message" + chr(34) + " [/T:" + chr(34) + "Title" + chr(34) + "] [/S:type] [/W:SecondsToWait]", 0, "Dialog.vbs", 4112
WScript.Quit (-2)
end if
Set argsNamed = WScript.Arguments.Named
if argsNamed.Exists("t") then DlgTitle=argsNamed.Item("t")
if argsNamed.Exists("s") then nType=argsNamed.Item("s")
if argsNamed.Exists("w") then nSeconds=argsNamed.Item("w")
WScript.Quit (WshShell.Popup( WScript.Arguments.Unnamed(0) , nSeconds, DlgTitle, nType))
Here is an example:
CODE
ifmember.exe administrators && (
WScript.exe %wpipath%dialog.vbs "You are not an administrator. Log in with admin rights to use this program" /T:"WPI"
Exit
)
It does pass on errorcodes from the dialog, so you can use it to do some decision making in the batch.
The full syntax is in the script :-)
I hope these may help you further!
Aquarius