Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
Keywords: NT service 95 wntSvcCreate error 531: Invalid Parameter
http://www.microsoft.com/msj/0398/service2.aspx
It is possible to create a compiled WinBatch program that will run as a native service under Windows NT or Windows 2000. To do this, compile the WinBatch script as usual using the 'Small EXE for Networked PC's' option in the WinBatch Compiler, but make sure to specify an output file with an extension of ".EXS" instead of ".EXE". Alternatively, you can simply rename an existing WinBatch program (version 2001 and higher) by changing its extension from ".EXE" to ".EXS".You can install a WinBatch service (or any service) using the wntSvcCreate function in the WIL Windows NT extender (see the Win32 Network Extender help file).
A WinBatch service can be configured in the Service Manager (in Control Panel) to run automatically on system startup, or manually on demand. In either case, when the WinBatch service starts up it processes the script just like a normal WinBatch program.
If you want the WinBatch service to wait for a particular time or event to occur, you can use any of the normal WIL methods (TimeDelay, TimeWait, WinWaitExist, etc.).
You can also use any of the following service functions: SvcSetAccept, SvcSetState, SvcWaitForCmd.
You can also use loops or branching (For, While, Goto, etc.) to cause the WinBatch service to continue running for an indefinite period of time. When processing reaches the end of the script (or a Return or Exit command, or a Cancel event), the WinBatch service will automatically stop. You can force a WinBatch service to stop prematurely by using the "Stop" function in the Service Manager (in Control Panel), or using another service control program (such as the wntSvcControl function in the WIL Windows NT extender). A WinBatch service will exit automatically on Windows shutdown.
It is unnecessary to use IntControl(1001) with a WinBatch service, but doing so will not hurt. WinBatch services do not exit when a user logs out.
If you are making a WinBatch service that will not be installed as an interactive service, you should use IntControl(38) at the beginning of the script to prevent WIL from displaying any unexpected error message boxes. If a non-interactive service attempts to interact with the desktop, it can cause the script to hang.
Notes:
Example:
AddExtender("WWWNT34i.DLL") ServiceName="At Your Service" DisplayName="AYS" BinaryPathName="c:\temp\AtYourService.exs" LoadOrderGroup="" ServiceStartName="LocalSystem" ;<== Password="" createstring=Strcat(ServiceName,"|",DisplayName,"|",BinaryPathName,"|",LoadOrderGroup,"|",ServiceStartName,"|",Password) ServiceType=256|16 StartType=3 ErrorControl=0 createflags=strcat(ServiceType,"|",StartType,"|",ErrorControl) wntSvcCreate("", createstring, createflags, "","") Message("Done","Added a service to the service control manager database.")
See WinBatch Help, for details.
The errors received are not typical of the shutdown and may appear during the service life and must not stop the service.
Intcontrol (1005, 0, 0, 0, 0) never returns @true.
Starting in WinBatch 2001J (and updated in 2001K) you can write better services that can be notified of relevent system events. See Winbatch.hlp. Lots of new service documentation in that help file.
***You must use INSTSRV.EXE to install a service that runs SRVANY.EXE. You then go into the registry subkey used by that service and add some named registry values that tell that particular instance of SRVANY.EXE what particular non-service .EXE program should be run in the context of a service.***
Configuring winbatch to run as a service:
These notes describe installing a service which will run a winbatch script at service startup.
* Items you must have on hand before starting:
Following these notes are two samples of wbt scripts which can be run under a service.
* Instructions:
instsrv winbsrv c:\temp\srvany.exeShould get msg: "the service was successfully added" note: to uninstall the service:
instsrv winbsrv remove
regedt32go to:
HKLM\system\CCS\services\winbsrv
Note: on the way to debugging this process several errors were encountered, and each one of them had entries describing the error and how to handle it in technet.
Here's a little background information on Windows services:
A service is something that runs whether a person is logged into the workstation or not. This is so that if a person logs out, the program continues to run. This has a variety of uses, such as to have a scheduling script that will run at preset times no matter whether a person is logged in or not, as long as the computer is running.
Another use is virus scanning software, which you don't want to not be running just because you don't have a person logged in.
Finally, you may want to have an admin service logging the users who log in or out of a multi-user machine, or may prefer to have some program running in the background continuously, and prefer to have it load once on a boot, rather than with each login.
If you have such a need, consider running as a service. With NT, you need to use a utility, because of the security on the NT. With Win95, since there is no security of that sort, you simply have to add an item to the registry to create a service once you tell your Winbatch to run as a service.
There is *a little bit* of built in support for running WinBatch as a service, via IntControl(1001 ....
IntControl(1001,1,0,0,0)at the top of your script and don't trust any environment assumptions.
For NT, you need both the IntControl 1001 AND the SRVRANY.EXE utility from the NT resource kit. IntControl 1001 works alone for 95 but with NT needs the SvrAny.Exe utility.
The reason you need to use the external utility SVRANY in NT and not in 95 is because of the fact that you cannot boot NT without logging in as somebody. You need to be logged in to have any access rights at all. Therefore, by that logic, you cannot send keys to NT services, you cannot assume any specific access rights, etc.
The srvany utility with NT resourcekit allows you to run any application as a service. To use this, you have to install Srvany as a service (you can do this with another resource kit utility - srvinstw.exe). You then change the parameters registry setting for this service and add your application.
A better solution for all the above is to use the Rservice utility which allows you to install the service local or remotely (works very nice). This utility ships with SMS 1.2 SP 3 -(Rservice.exe is provided in the latest Systems Management Server 1.2 Service Pack). I have used the above method in a large scale environment and I am very impressed.
Basically the IntControl(1001,...) simply tells the script to ignore user shutdown messages. For example there is a USER_IS_LOGGING_OFF command that is sent to all applications, and they dutifully quit. This tells WinBatch to ignore such messages and continue to run.
The limitations we've found out so far with running Winbatch as a service this way are:
I recommend disk files as the communications interface. The logged on user can make a file to do something. The service can:
while 1 TimeDelay(5) if FileExist("flag.file") while FileSize("flag.file")==0 TimeDelay(1) endwhile ;DO SOMETHING endif endwhileThere is no way currently to run winbatch code with Admin rights from a normal users account. There are a couple of schemes where you can log the user off and auto-log in as admin to do the dirty work...but the security holes are atrocious.
I'm using SmartBatch32, an NT-based job scheduler, to launch a number of WinBatch jobs. I just hit my first snag.
This job attempts a DDE initiate to cc:Mail. If zero is returned, it attempts to start cc:Mail as follows:
Run(ccMailExe, ccMailLogin)If I double-click on the WBT file to launch it, the job runs to completion. If SmartBatch launches it I get the 1932: WinExec: Undefined Error dialog box. I hope you might have some ideas because I've pretty much exhausted the SmartBatch people.
I've tried RunShell instead, but it didn't help. I note from the WIL manual that 32-bit WinBatch uses the CreateProcess API, but the message appears to come from WinExec? Also, and for what it's worth, SmartBatch is running as an NT Service.
You can try FileExist(ccmailexe) and see if the script can see it.
You might also try adding DirChange to the desired directory just before doing the RUN statement.
I have a "daemon" script that runs on a remote-control host computer. The script's job is to make sure that the host logs off gracefully when someone disconnects. The script never terminates. It runs in the background and waits for a connection, then monitors the connection. When the user disconnects, the script cleans up and logs the user out (basically a "Close all programs and log on as a different user"). The script then waits for the next caller.
I have this jerry-rigged right now - when the caller disconnects, the script WinActivates Program manager and sends an Alt-F4, Alt-C, Alt-Y. All this does is activate the "Shut Down Windows" box and selects the "Close all programs..." button. This works as it should. I had expected IntControl 66 to behave identically, but it has the undesired side effect of terminating the script. BTW, I am not currently using the WinBatch "Shutdown Mode".
If it is in the shutdown script...then that is expected behavior. But you are already in shutdown code so it should not be necessary.
Yes, that will terminate the script. I never did quite realize that before, but the original intent of the IntControl(66 was to shut down the computer...its been modifies since....
However I suggest a completely different method. I suggest letting the script shut down as it wished, and then when the "autologon" occurs, simple launch a new copy of the script by placing it in the RUN- line of win.ini or perhaps in the registry under the RUN key.
IntControl 66 doesn't seem to bother other "services" that I have running (e.g. McAfee Vshield, Eversys Monitor Agent, etc...). Any chance of an updated Intcontrol 66 (or a newer number if compatibility is an issue) that won't terminate the invoking script - provided that that script is running as a service (IntControl 1001)?
Don't really want to modify the IntControl 66 functionality as it is in widespread use.
So....being clever. Lets say your service is called MYSERVE.EXE and you launch it via the RunServices section of the registry. And now it comes time to log the user out via the IntControl 66.
-----snip----- ;Add this code to the TIPTOP of your script if param0==1 if param1=="LOGOFF" IntControl(66,0,0,0,0) endif endif ; END OF TIPTOP SECTION ;much of the old script here. ;Here is where you do the IntControl66 ;ASSUMING COMPILED EXE MyExe=IntControl(1004,0,0,0,0) Run(MyExe,"LOGOFF") ; Maybe RunWait ??? ;and continue with your service code here.
If you cannot modify services (which is a shame), and you don't have an existing service you can post the command to (such as WinInstall, or your own winbatch service), then you can still do it as follows.
hmm.
Use winbatch COMPILER (don't recommend uncompiled version in this instance due to security considerations.)
This compiled program you email to use user, and ask them to run it. The program will:-
This batch file will contain a line running another winbatch script. which will add the icons, remove the autoadminlogin line, remove the runonce line, and then force a logout again.
While you're there, you'd do yourself a good favour to add an admin service on the machine.
Bit messy, but its the only way I can think of anyway.
My goal is to perform certain tasks either in a forced mode or in an interactive mode. I just need to know which one to kick off.
Thanks in advance for your help!
I was able to start and stop the foreground service as needed. In your case, you could pass status information via registry changes within HKLM, which will be available to background and foreground users and services. In fact, I would just pop a couple extra value fields in those created by SRVANY (assuming that is what you used to define your WB app as a service) for your service and have the foreground task fill the fields as necessary.
Good luck.
My environment is:
You should be able to find them on support.microsoft.com under the following Q numbers.
Q142676: Overcoming User32.dll Initialization Failure Errors The information in this article applies to: Microsoft Windows NT Workstation version 4.0 Microsoft Windows NT Server version 4.0 SYMPTOMS When you try to start a service a pop-up dialog box appears with the following message:- DLL initialization failure Initialization of the dynamic link library c:\windows\system32\user32.dll failed. The process is terminating abnormally. CAUSE The system has run out of memory to create a new desktop heap for the service being started. (see article for more details)
Q175875: Dr. Watson Causing Fault in USER32 The information in this article applies to: Microsoft Windows NT Server version 4.0 SYMPTOMS When an application is running on a computer running Windows NT Server, it may at times raise an exception for any of a number of reasons. Ordinarily,an exception like this calls the Dr. Watson system utility which then captures the exception, writing out a log and a memory dump. Under some circumstances, Dr. Watson will fail to start and will cause an exception in User32.dll. CAUSE This can occur if the application causing the exception is running as a service, but the service account does not have the right to log on locally. (see article for more details)
Any help would be greatly appreciated.
The error message you are seeing is a classic example of trying to start a .EXE as a service when the .EXE is not capable of detecting and responding to service control manager messages that are being sent to it.
Article ID: W17209
File Created: 2007:07:03:14:28:48
Last Updated: 2007:07:03:14:28:48