WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Samples from Users
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Zen-Works Sample Script

Keywords: 	   command line Zen Works remote control

A couple days ago, I had sent an email requesting information/documentation about the command-line parameters for ZEN-Works remote control.

While writing a wrapper utility program, I want to be able to launch ZEN Works remote control. I found that the program was WVIEWNT.EXE, but when I tried to run the program by itself, I'd receive the error message:

Cannot execute because the command line is invalid

This is what prompted my email earlier.

Then I had an idea...how about if I wrote a program to "intercept" the program call and show the command line parameters being passed!

Enter WinBatch!

I wrote INTERCEPT.EXE that would replace itself with the selected program, show the parameters being passed, then continue on to the original executable. Running INTERCEPT.EXE while holding down the CTRL key, allows you "control" of the INTERCEPT.EXE program. You are prompted whether to INTERCEPT a specified program or RESTORE a previously intercepted program.

INTERCEPTing
When you choose to intercept a program, your prompted to browse to the program to be intercepted. Once selected, it MOVES the executable to C:\INTERCEPT, makes and entry in C:\INTERCEPT\INTERCEPT.INI (to remember the original location), and then copies the running INTERCEPT.EXE to the same location and name of the originally selected file. ie: for my use, it copied INTERCEPT.EXE to F:\PUBLIC\WIN32\WVIEWNT.EXE Then, when NWADMIN32.EXE would access the remote control function, it calls WVIEWNT.EXE, the interceptor, shows the command line parameters, and prompts as to whether you want to continue with the passed parameters. You'll notice the parameters are in an editable box (for modification or cut-n-pasting). INTERCEPT.EXE isn't perfect. In the case of WVIEWNT.EXE, the parameters being passed showed to be:

-wBKDLS_DP556_.Workstations.CC.VOP -nVOP_TREE -cRemote Control

but I still received the "invalid command line" error message. I played around with the command line and found that '-cRemote Control' needed to be '-c"Remote Control" '. Viola!, I had the information I need to continue my utility program.

RESTOREing
By selecting RESTORE, your given a list of previously selected intercepted programs. Select fom the list the program to restore, and it will MOVE the program from C:\INTERCEPT back to it's original location, overwriting the renamed INTERCEPT.EXE. You're back in business!

Obviously, this is a kind of crude remedy, but is a handy utility for techie-types like me that need more information about programs' use of command-line options that are sometimes unavailable or difficult to find information for.

For those of you interested in investigating WinBatch "language", also attached is the source-code.

Caveats:
- This is only tested (and intended) for NT workstation. Though, it should work on any 32-bit platform. 16-bit application is possible, by request.

Enjoy!

(By attaching the program, it comes with the usual disclaimers about my not being responsible for any ill effects.)

Here is the script Intercept.wbt:

;Intercept.wbt  Intercepts program command-line parameters

	CR=strcat(num2char(13),num2char(10))            ;Carriage Return
        tabchr=Num2Char(9)                              ;Tab
        ExeName=WinName()
        WinHide("%ExeName%")
        ExeName=StrUpper(StrSub(ExeName,7,-1))
	Vdot=FileVerInfo(ExeName, "", "FileVersion")
        ExeRoot=StrUpper(FileRoot(ExeName))
        Path2Exe=FileLocate("%ExeName%")         ;Go find where default.wbt lives
        Path2Exe=StrUpper(FilePath(Path2Exe))
        err=0

;DEBUG(@ON)
if IsKeyDown(@SHIFT)==@YES then Debug(@ON)
if IsKeyDown(@CTRL)==@YES then goto MANAGE
Parameters=""

:REDIRECTED
	x=param0
	if x=="0" then goto NOPARAMETERS
	for y=1 to x
		Parameters=StrCat(Parameters," ",param%y%)
	Next
	AskLine("Parameters","%Path2Exe%\%ExeName% has the following passed parameters%CR%",Parameters)
	Run("C:\INTERCEPT\%ExeName%","%Parameters%")
	Exit

:NOPARAMETERS
	if AskYesNo("No Parameters","%Path2Exe%\%ExeName% has no parameters%CR%%CR%Continue without parameters?")==@NO then Exit
	Run("C:\INTERCEPT\%ExeName%","")
	Exit


:MANAGE
	InterceptFormat=`WWWDLGED,5.0`
	
	InterceptCaption=`Program Interceptor (v. %vdot%)`
	InterceptX=90
	InterceptY=109
	InterceptWidth=115
	InterceptHeight=106
	InterceptNumControls=8
	
	Intercept01=`18,84,36,DEFAULT,PUSHBUTTON,DEFAULT,"&OK",1`
	Intercept02=`58,84,36,DEFAULT,PUSHBUTTON,DEFAULT,"&Cancel",0`
	Intercept03=`20,24,64,DEFAULT,RADIOBUTTON,Option,"&Intercept",1`
	Intercept04=`20,64,64,DEFAULT,RADIOBUTTON,Option,"&Restore",2`
	Intercept05=`10,4,90,DEFAULT,STATICTEXT,DEFAULT,"Select to INTERCEPT a program-call"`
	Intercept06=`10,44,90,DEFAULT,STATICTEXT,DEFAULT,"Select to RESTORE a previously"`
	Intercept07=`10,12,102,DEFAULT,STATICTEXT,DEFAULT,"and identify the command line parameters"`
	Intercept08=`10,52,64,DEFAULT,STATICTEXT,DEFAULT,"'Intercepted' program"`
	
	ButtonPushed=Dialog("Intercept")
	
	if Option=="1" then goto INTERCEPT
	if Option=="2" then goto RESTORE
	
	:INTERCEPT
	FileTypes="EXE Files|*.EXE|All Files|*.*"
	Program=AskFileName("Select Program", Path2Exe,filetypes, "", 1)
	if Program=="" then goto NOSELECTION
	if DirExist("C:\INTERCEPT")==@FALSE then DirMake("C:\INTERCEPT")
	FileMove(Program,"C:\INTERCEPT",@TRUE)
	FileCopy("%Path2Exe%\%ExeName%",Program,@TRUE)
	ProgramRoot=FileRoot(Program)
	IniWritePvt("PROGRAMS",ProgramRoot,Program,"C:\INTERCEPT\INTERCEPT.INI")
	Message("%ProgramRoot% Intercepted","%Program% has been intercepted, and moved to C:\INTERCEPT.%CR%%CR%To restore, run this program again while holding down the CTRL key.")
	Exit
	
:RESTORE
	if FileExist("C:\INTERCEPT\INTERCEPT.INI")==@FALSE then goto NONEYET
	Programs=IniItemizePvt("PROGRAMS","C:\INTERCEPT\INTERCEPT.INI")
	if Programs=="" then goto NONELEFT
	;FileTypes="EXE Files|*.EXE|All Files|*.*"
	;Program=AskFileName("Select Program","C:\INTERCEPT",filetypes, "", 1)
	Program=AskItemList("Restore Program",Programs,@TAB,@sorted,@single)
	if Program=="" then goto NOSELECTION
	;ProgramRoot=FileRoot(Program)
	Destination=IniReadPvt("PROGRAMS",Program,"","C:\INTERCEPT\INTERCEPT.INI")
	if FileMove("C:\INTERCEPT\%Program%.EXE",Destination,@TRUE)==@FALSE then goto ABORTED
	IniDeletePvt("PROGRAMS",Program,"C:\INTERCEPT\INTERCEPT.INI")
	Message("Restored","%Program% has been moved back to %Destination%")
	Exit

:NONELEFT
	Message("None to Restore","No Programs are left to be restored from having been intercepted")
	Exit

:NONEYET
	Message("First Time Run","No Programs have yet been intercepted")
	Exit

:NOSELECTION
	Message("DUH!","Nothing selected, nothing to do!")
	Exit

:ABORTED
	Message("ABORT","The restore of %Program% to %Destination% was aborted.")
	Exit


Article ID:   W13811
Filename:   Zen-Works sample.txt
File Created: 1999:04:15:16:56:32
Last Updated: 1999:04:15:16:56:32