I have developed a service on a 64 bit system using Visual Studio 2010. The service is just a skeleton that accesses the Start and Stop methods in a secondary library. The library accesses a 64 bit COM object, and must be built as x64. The COM object is a dll that was built separately as x64 and tested in a 64-bit environment. I have an installer that sets up the project and installs the service through a custom action.
If I set the service to build as Any CPU, the installation works, and the service can access the library, but the COM object cannot be found. The installation will also work if I remove the custom action that installs the service. If I then try to install the service manually using installutil, I get the same error message as above.
If you add a 64-bit managed custom action to a Setup project, the Visual Studio build process embeds a 32-bit version of InstallUtilLib.dll into the MSI as InstallUtil. In turn, the 32-bit .NET Framework is loaded to run the 64-bit managed custom action and causes a BadImageFormatException exception.
I have a windows service. In the Properties I have the platform target set as X64. In my csproj file I have changed all instances of prefer32bit to false. I am installing the service with installutil.exe when I install and run my service it runs as 32 bit. I am currently building in debug mode. What am I missing here?
Just to add to this old answer, yes use Process Explorer. You can right click on the columns and select Image Type to show which processes are 32 bit and which are 64 bit. Run Process as Administrator to see some services.
If you're developing a Windows service with .NET Framework, you can quickly install your service app by using the InstallUtil.exe command-line utility or PowerShell. Developers who want to release a Windows service that users can install and uninstall can use the free WiX Toolset or commercial tools like Advanced Installer, InstallShield, and others. For more information, see Create an installer package (Windows desktop).
If you want to uninstall a service from your computer, don't follow the steps in this article. Instead, find out which program or software package installed the service, and then choose Apps in Settings to uninstall that program. Many services are integral parts of Windows; if you remove them, you might cause system instability.
Key issue is I'm using the third-party PmsService utility to run the server as a service. Someone has already commented on the Plex Forums that I'd need a 64-bit compatible version of this but one doesn't seem to exist yet?
Hi,
I need to run the jboss server as a windows service. To achieve that i used Native JBoss. I am able to run it as a windows service using that but i can access jboss only on localhost. I need to run jboss on a specific ipadress. It can be done by few changes in the service.bat file.
This is the snippet of service.bat file:
:cmdStart
REM Executed on service start
call run.bat >run.log
goto cmdEnd
ipaddress has to be added in the service.bat file in the above code in the line: call run.bat >run.log
Similarly should i have to add the ipaddress even during shutdown in the code:
:cmdStop
REM Executed on service stop
call shutdown -S >shutdown.log
goto cmdEnd
I dont exactly remember how to add that ip address.
waiting for reply from someone.....!
Thanks in advance...
Regards,
Raghav.
Mladen told me it should work on both 32 and 64 bit windows platforms.
You can try it, too, on x64 and tell me if there is any problem :-)
I thought it would be very useful to bundle this by default to avoid all the hassle of reverting to service wrappers and the like.
If someone wants the full jboss native distro to get the apr connectors and stuff you can simply unzip it over.
I just now downloaded trunk and tried using the included jbosssvc.exe on my Vista 64-bit box and got a C0000005 access violation error. This error does not appear if I use the jbosssvc.exe from the 64-bit Windows JBoss Native download.
Perhaps provide both jbosssvc.exe and jbosssvc64.exe, and update the service.bat script to detect which is required and use the right one. You can key off of the PROCESSOR_ARCHITECTURE env var, it is set to "x86" when running 32-bit Windows and "AMD64" for 64-bit Windows. (Note that I have an Intel Core 2 Quad processor - thus "AMD64" does not really identify the exact processor type, but rather simply means "running a 64-bit OS".)
I got it working by downgrading to version 10.1 sp1 and loading the same project. As soon as I tried to open the programmer, it immediately threw up a modal dialog box saying it could not start the jtag server service, with "Error opening SCM" as the reason.
Recently, I needed to adjust a Java application to be able to run as a Windows service which is the Windows equivalent to a Unix daemon. There are several libraries available for this kind of task and after some reading, I chose Apache procrun which turned out to be a good choice. The configuration was less painful than expected and the tool seems quite powerful, due to a large set of configuration options. Also, building a Windows service or a Unix daemon should not make much of a difference. I used a 64bit Windows 7 and 32bit Java 7 JVM for this tutorial.
Now, you need procrun to turn that into a Windows service. Download it from the procrun download page and unpack whatever you chose to download. In my case, this was version 1.0.10 of the Windows binaries and the essential part in the archive is prunsrv.exe, the procrun service application which is responsible for installing and removing the service. prunmgr.exe is also an extremly useful application that provides a GUI to set everything you can configure via batch scripts.
The difficult part now is to install the service. This can be done by a call of prunsrv.exe with appropriate options. There are quite some options you can / have to use, so this is best packaged as a batch script which I called installService.bat:
Open the command prompt and move to the directory where the script is located. The script modifies the registry, so it needs to have administrator privileges to execute successfully. The first line sets the service name which determines its registry key. Next, you need to set the path to prunsrv.exe. On that note, here is a lesson that took me some time to learn: If you use (correct) relative paths to files in the installation script, the service will install correctly and it will run fine in debugging mode. It will however fail when run normally with any administrative tooling you have. Be it the usual Windows management console (Computer -> Manage -> Services and Applications -> TestService) or prunmgr.exe. Generally, you should use absolute paths with procrun. Interestingly, there is one exception to this rule: the jar file you use as classpath. Here, the relative path worked out fine for me. Another lesson, I found on stackoverflow, is that you must not use white spaces in the service name.
Hello Jorg, this has been really helpful. I have been able to install as a service but on starting the service, an error is thrown that it cant find the class.
Can you help me decide how to properly reference the pr_startclass properly from the batch file.
Maybe give an example with complete file paths.
Hi Jorg,
Yes this was the error and its running perfectly.
But i need this service to start in background as well as foreground.
Apart from using java -jar xyz.jar is there any other better way?
The error message says that procrun cannot locate the class file of the service. You could check that the jar file is properly build and that the class file is really in there. Alternatively, the most common issue is some misconfiguration in the file paths.
Hi Jorg , My service runs under SYSTEM account before any user logged on .I want to run the service under Logged in user account ,but do not want to change in installation batch file for user specific details.
How Can I do this.
that is the normal behavior of installService.bat. It installs the service into the system, which is why you see that the service exists, but it does not start the service, and hence you see it as stopped.
as far as I understand, procrun only hooks the java program into the service api of the operating system. It does not interfere into the programs regular execution or influence threading. Threading is determined by the JVM which you declare in the procrun configuration.
I have a program that I started as a network service. It starts and stops fine. I can send it a command from cmd to check the status and that returns fine, but when I send it a command to spawn a new thread it starts the process, then it sits there hung up until i terminate the process.
this should bring up the GUI to edit the properties of the service. In my case I found all the values that I set via the batch script missing. So I entered them via the GUI. Next I applied the values , then restarted the service once via the GUI, everything worked as advertized and now I am a happy camper.
Hi,
the method signature seems correct. Are you really sure you try to execute the jar with the most recent version of the class? Could it be that you accidently installed a previous version that did not have the stop method? I would try to uninstall the service, rebuild the jar, install the rebuilt jar, and try to run again.
Hope this helps,
Jörg
Hi,
Myself was struggling to create a Windows service from Java application., until I found your article. Read it and tried to run the sample code. But it throws the following exception in Error Log, Any idea why?
Again me When i create service on Window 7 same error is show for me The ZTimeService
service terminated with service-specific error Incorrect function. When i choose prunsrv.exe is in the wrong package ? or something else ? How can i create a ZTimeService Help and Guide me thnaks