Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
Is there any way to pass parameters to the .exs service or do I need to use a .ini file or registry entries?
How are you capturing the command line parameters in the service script? The DebugTrace function and IntControl 1006 (returns the un-parsed WinBatch command line), should be very helpful in debugging your problem.
Add both functions to your script. Recompile as a .EXS file. Install the service. Then start it. Post the resulting trace file here.
C:\PS\css\cssTux.exs -PS_HOME=d:\ps84 -Appservers=CIS -Schedulers= -delay=2Here is part of the trace for the .exs file:
************************************************************ *** Debug Initialized *** ============================== Tue 4/20/2004 9:37:02 AM WinBatch 32 2004A WIL DLL 4.4add C:\PS\css\cssTux.exs Windows platform: NT, version: 5.0, build: 2195 (Service Pack 4) ============================== rc=IntControl(1006, 0, 0, 0, 0) (0) VALUE=> "" logIt(logDir,strcat("Command line: ",rc)) (0) CALLING UDF (logit)I created another service using sc that uses a .exe version of the program. Here's it's service properties "Path to executable":
C:\PS\css\cssTux.exe -PS_HOME=d:\ps84 -Appservers=CIS -Schedulers= -delay=2Here is the trace for the .exe file:
************************************************************ *** Debug Initialized *** ============================== Tue 4/20/2004 9:43:38 AM WinBatch 32 2004A WIL DLL 4.4add C:\PS\css\cssTux.exe Windows platform: NT, version: 5.0, build: 2195 (Service Pack 4) ============================== rc=IntControl(1006, 0, 0, 0, 0) (0) VALUE=> "-PS_HOME=d:\ps84 -Appservers=CIS -Schedulers= -delay=2" logIt(logDir,strcat("Command line: ",rc)) (0) CALLING UDF (logit)
I don't know if I've ever tried to have a service-mode compiled script accept command line parameters, but there is an option in the service configuration to enter "Start parameters". Are you entering the parameters through this field in the service properties?
I did some digging around and found something that might be of use to you. This comes from a service-mode script that I wrote last year, and the script needed to be able to accept command line parameters when the service was automatically started.
; Get our command line. We are dealing with a native service program here, and the ; only way that we get command line parameters passed in to us when we get automatically ; started up at system boot time is if they are included as part of the binary file ; specification that is part of the service definition. We must call GetCommandLineA() ; in KERNEL32.DLL in order to obtain the full command line since a WinBatch script in ; native service mode only receives [in Param1 through Param9] the parameters that are ; manually supplied when a service is manually started. Another key thing to remember ; here is that the binary file specification must be a short 8.3 name since we cannot ; tolerate any long file names that include whitespace in them. We will parse the ; command line and find the instance # assigned to the current service. CmdLine = '' TempStrAddr = DllCall('KERNEL32.DLL',long:'GetCommandLineA') TempByte = IntControl(32,TempStrAddr,'BYTE',0,0) while(TempByte != 0) CmdLine = StrCat(CmdLine,Num2Char(TempByte)) TempStrAddr = TempStrAddr + 1 TempByte = IntControl(32,TempStrAddr,'BYTE',0,0) endwhile TempPos = StrIndexNc(CmdLine,'/#=',0,@FWDSCAN) if (TempPos == 0) TempMsg = StrCat('Error! Run Mode = "',RunMode,'", should be "5". Aborting...') Message(Title01,TempMsg) IntControl(1000,ERR_INSTANCE_UNDEFINED,0,0,0) exit endif SvcInstanceNum = Int(StrSub(CmdLine,TempPos+3,2)) SvcInstanceStr = StrFixLeft(SvcInstanceNum,'0',2)This code was used before IntControl(1009,...) was available. In effect, the binary/executable file for the service was specified with some command line parameters following it. A Win32 API function call is made to retrieve the full command line that was used to start the service, and then the command line parameters were parsed out and used to figure out which service instance this was. The IntControl(1009,....) call now makes this code unnecessary as you can directly get the service's registry key name and from that you can directly interrogate the registry for configuration parameters that are specific to this particular instance of the service.
Article ID: W16675
File Created: 2005:02:18:12:21:50
Last Updated: 2005:02:18:12:21:50