PC Review


Reply
Thread Tools Rate Thread

C# Windows Service problem on Windows 7 64 Bit?

 
 
Lothar Behrens
Guest
Posts: n/a
 
      22nd Nov 2010
Hi,

I have written a Windows Service (for the test - a dummy to divide and
conquer) and the service cannot be intalled on the Windows 7
Enterprise (64Bit version) box.

On that box there was installed the .NET 4.0 Client profile and as I
have seen, all earlier versions are installed in the C:\Windows
\Microsoft.Net directory. For a try I have removed that version but no
success.

The service is a .NET 3.5 version service and I have tried building
Any CPU, x86 and x64. All has failed with the following error, that
the application is not a valid Win32 Application.

As other sources state that Windows 7 installs .Net, I did not see any
reason why such a simple test service fails to load whereas a GUI
application will run (compiled in 64Bit).

I am using Visual Studio 2008 9.0.21022.8 RTM with .NET 3.5 SP1.

The installer does start the service after it has installed it and
then it fails. If I do not have any custom installer
steps, the service will fail to start from services.msc either.

Any help please !!!!

Thanks,

Lothar
 
Reply With Quote
 
 
 
 
r norman
Guest
Posts: n/a
 
      22nd Nov 2010
On Mon, 22 Nov 2010 09:17:07 -0800 (PST), Lothar Behrens
<(E-Mail Removed)> wrote:

>Hi,
>
>I have written a Windows Service (for the test - a dummy to divide and
>conquer) and the service cannot be intalled on the Windows 7
>Enterprise (64Bit version) box.
>
>On that box there was installed the .NET 4.0 Client profile and as I
>have seen, all earlier versions are installed in the C:\Windows
>\Microsoft.Net directory. For a try I have removed that version but no
>success.
>
>The service is a .NET 3.5 version service and I have tried building
>Any CPU, x86 and x64. All has failed with the following error, that
>the application is not a valid Win32 Application.
>
>As other sources state that Windows 7 installs .Net, I did not see any
>reason why such a simple test service fails to load whereas a GUI
>application will run (compiled in 64Bit).
>
>I am using Visual Studio 2008 9.0.21022.8 RTM with .NET 3.5 SP1.
>
>The installer does start the service after it has installed it and
>then it fails. If I do not have any custom installer
>steps, the service will fail to start from services.msc either.
>
>Any help please !!!!
>

Service startup problems can be a real headache.

I have a "debug log" system that writes all sorts of information
relating to startup including passing through key steps and catching
and logging all exceptions. It is invaluable.

More invaluable is writing the service to be dual startup: if you
have a command line saying "-debug" (or something similar) it will run
as a console based application program and write all debug log
information to the screen.

 
Reply With Quote
 
Lothar Behrens
Guest
Posts: n/a
 
      22nd Nov 2010
On 22 Nov., 20:23, r norman <r_s_nor...@comcast.net> wrote:
> On Mon, 22 Nov 2010 09:17:07 -0800 (PST), Lothar Behrens
>
>
>
>
>
> <lothar.behr...@lollisoft.de> wrote:
> >Hi,

>
> >I have written a Windows Service (for the test - a dummy to divide and
> >conquer) and the service cannot be intalled on the Windows 7
> >Enterprise (64Bit version) box.

>
> >On that box there was installed the .NET 4.0 Client profile and as I
> >have seen, all earlier versions are installed in the C:\Windows
> >\Microsoft.Net directory. For a try I have removed that version but no
> >success.

>
> >The service is a .NET 3.5 version service and I have tried building
> >Any CPU, x86 and x64. All has failed with the following error, that
> >the application is not a valid Win32 Application.

>
> >As other sources state that Windows 7 installs .Net, I did not see any
> >reason why such a simple test service fails to load whereas a GUI
> >application will run (compiled in 64Bit).

>
> >I am using Visual Studio 2008 9.0.21022.8 RTM with .NET 3.5 SP1.

>
> >The installer does start the service after it has installed it and
> >then it fails. If I do not have any custom installer
> >steps, the service will fail to start from services.msc either.

>
> >Any help please !!!!

>
> Service startup problems can be a real headache. *
>
> I have a "debug log" system that writes all sorts of information
> relating to startup including passing through key steps and catching
> and logging all exceptions. *It is invaluable.
>
> More invaluable is writing the service to be dual startup: *if you
> have a command line saying "-debug" (or something similar) it will run
> as a console based application program and write all debug log
> information to the screen.


I have a debug GUI application, as I have abstracted the internal
functionality off of the service. The GUI has not been tested on
64Bit. But it is crazy that a simple dummy service can't get started
on 64Bit. The service is simply that what visual studio template
generates.

So this in my view - simply - should work.
 
Reply With Quote
 
r norman
Guest
Posts: n/a
 
      22nd Nov 2010
On Mon, 22 Nov 2010 14:39:16 -0800 (PST), Lothar Behrens
<(E-Mail Removed)> wrote:

>On 22 Nov., 20:23, r norman <r_s_nor...@comcast.net> wrote:
>> On Mon, 22 Nov 2010 09:17:07 -0800 (PST), Lothar Behrens
>>
>>
>>
>>
>>
>> <lothar.behr...@lollisoft.de> wrote:
>> >Hi,

>>
>> >I have written a Windows Service (for the test - a dummy to divide and
>> >conquer) and the service cannot be intalled on the Windows 7
>> >Enterprise (64Bit version) box.

>>
>> >On that box there was installed the .NET 4.0 Client profile and as I
>> >have seen, all earlier versions are installed in the C:\Windows
>> >\Microsoft.Net directory. For a try I have removed that version but no
>> >success.

>>
>> >The service is a .NET 3.5 version service and I have tried building
>> >Any CPU, x86 and x64. All has failed with the following error, that
>> >the application is not a valid Win32 Application.

>>
>> >As other sources state that Windows 7 installs .Net, I did not see any
>> >reason why such a simple test service fails to load whereas a GUI
>> >application will run (compiled in 64Bit).

>>
>> >I am using Visual Studio 2008 9.0.21022.8 RTM with .NET 3.5 SP1.

>>
>> >The installer does start the service after it has installed it and
>> >then it fails. If I do not have any custom installer
>> >steps, the service will fail to start from services.msc either.

>>
>> >Any help please !!!!

>>
>> Service startup problems can be a real headache. *
>>
>> I have a "debug log" system that writes all sorts of information
>> relating to startup including passing through key steps and catching
>> and logging all exceptions. *It is invaluable.
>>
>> More invaluable is writing the service to be dual startup: *if you
>> have a command line saying "-debug" (or something similar) it will run
>> as a console based application program and write all debug log
>> information to the screen.

>
>I have a debug GUI application, as I have abstracted the internal
>functionality off of the service. The GUI has not been tested on
>64Bit. But it is crazy that a simple dummy service can't get started
>on 64Bit. The service is simply that what visual studio template
>generates.
>
>So this in my view - simply - should work.


Should does not mean does. Welcome to services programming. That is
why I suggested the debug log. My console app isn't the innards of
the services but the identical code that runs as a service (if started
by the service controller) or as a console app (if started with a
specific command line). Another enormous advantage of this is that
you can then run it from the debugger as an application program and
see exactly what is happening in the first steps of startup.

An alternative is to make the service sleep for, say, ten seconds
before doing anything at all giving you time to connect a debugger to
it.

One thing you must realize is that the service runs, depending on how
you set it up, under different credentials than an application program
and, if it tries to access any system resources, you have to make sure
it has rights to do so.

 
Reply With Quote
 
Lothar Behrens
Guest
Posts: n/a
 
      23rd Nov 2010
On 22 Nov., 23:55, r norman <r_s_nor...@comcast.net> wrote:
> On Mon, 22 Nov 2010 14:39:16 -0800 (PST), Lothar Behrens
>
>
>
> <lothar.behr...@lollisoft.de> wrote:
> >On 22 Nov., 20:23, r norman <r_s_nor...@comcast.net> wrote:
> >> On Mon, 22 Nov 2010 09:17:07 -0800 (PST), Lothar Behrens

>
> >> <lothar.behr...@lollisoft.de> wrote:
> >> >Hi,

>
> >> >I have written a Windows Service (for the test - a dummy to divide and
> >> >conquer) and the service cannot be intalled on the Windows 7
> >> >Enterprise (64Bit version) box.

>
> >> >On that box there was installed the .NET 4.0 Client profile and as I
> >> >have seen, all earlier versions are installed in the C:\Windows
> >> >\Microsoft.Net directory. For a try I have removed that version but no
> >> >success.

>
> >> >The service is a .NET 3.5 version service and I have tried building
> >> >Any CPU, x86 and x64. All has failed with the following error, that
> >> >the application is not a valid Win32 Application.

>
> >> >As other sources state that Windows 7 installs .Net, I did not see any
> >> >reason why such a simple test service fails to load whereas a GUI
> >> >application will run (compiled in 64Bit).

>
> >> >I am using Visual Studio 2008 9.0.21022.8 RTM with .NET 3.5 SP1.

>
> >> >The installer does start the service after it has installed it and
> >> >then it fails. If I do not have any custom installer
> >> >steps, the service will fail to start from services.msc either.

>
> >> >Any help please !!!!

>
> >> Service startup problems can be a real headache. *

>
> >> I have a "debug log" system that writes all sorts of information
> >> relating to startup including passing through key steps and catching
> >> and logging all exceptions. *It is invaluable.

>
> >> More invaluable is writing the service to be dual startup: *if you
> >> have a command line saying "-debug" (or something similar) it will run
> >> as a console based application program and write all debug log
> >> information to the screen.

>
> >I have a debug GUI application, as I have abstracted the internal
> >functionality off of the service. The GUI has not been tested on
> >64Bit. But it is crazy that a simple dummy service can't get started
> >on 64Bit. The service is simply that what visual studio template
> >generates.

>
> >So this in my view - simply - should work.

>
> Should does not mean does. *Welcome to services programming. *That is
> why I suggested the debug log. *My console app isn't the innards of
> the services but the identical code that runs as a service (if started
> by the service controller) or as a console app (if started with a
> specific command line). *Another enormous advantage of this is that
> you can then run it from the debugger as an application program and
> see exactly what is happening in the first steps of startup.
>
> An alternative is to make the service sleep for, say, ten seconds
> before doing anything at all giving you time to connect a debugger to
> it.
>
> One thing you must realize is that the service runs, depending on how
> you set it up, under different credentials than an application program
> and, if it tries to access any system resources, you have to make sure
> it has rights to do so.


I have identified the problem. The installation class was located in a
DLL and the service in an executable. Thus the Service installer
routine has used the DLL as the service. That will fail.

But when I use the installer class in an executble I get an error
while the commit phase.

Does any one have advice on 64Bit Windows 7 with the class as shown
here to enable on demant service registration (to mate the installer
updateable)?

using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using System.ServiceProcess;

namespace ServiceSetupDll
{
[RunInstaller(true)]
public partial class ServiceInstaller : Installer
{
public ServiceInstaller()
{
bool isInstalled = false;
ServiceController[] controllers =
ServiceController.GetServices();

foreach (ServiceController ctrl in controllers)
{
if (ctrl.DisplayName == "Service")
{
isInstalled = true;
}
}

if (!isInstalled)
{
InitializeComponent();
}
else
{
this.serviceController1 = new
System.ServiceProcess.ServiceController();
this.serviceController1.ServiceName = "Service";
this.BeforeUninstall += new
System.Configuration.Install.InstallEventHandler(this.ServiceInstaller_BeforeUninstall);
this.BeforeInstall += new
System.Configuration.Install.InstallEventHandler(this.ServiceInstaller_BeforeInstall);
this.AfterInstall += new
System.Configuration.Install.InstallEventHandler(this.ServiceInstaller_AfterInstall);
}
}

private void ServiceInstaller_AfterInstall(object sender,
InstallEventArgs e)
{
serviceController1.Start();
}

private void ServiceInstaller_BeforeUninstall(object sender,
InstallEventArgs e)
{
try
{
serviceController1.Stop();

int repeat = 10;

while ((repeat-- > 0) && serviceController1.Status ==
ServiceControllerStatus.Running)
System.Threading.Thread.Sleep(1000);
}
catch
{

}
}

private void ServiceInstaller_BeforeInstall(object sender,
InstallEventArgs e)
{
try
{
serviceController1.Stop();

int repeat = 10;

while ((repeat-- > 0) && serviceController1.Status ==
ServiceControllerStatus.Running)
System.Threading.Thread.Sleep(1000);
}
catch
{

}
}

private void ServiceInstaller_AfterUninstall(object sender,
InstallEventArgs e)
{
// Does not really work.

//ServiceProcessInstaller = new
System.ServiceProcess.ServiceProcessInstaller();
//ServiceInstaller = new
System.ServiceProcess.ServiceInstaller();
//ServiceProcessInstaller.Account =
System.ServiceProcess.ServiceAccount.LocalSystem;
//ServiceProcessInstaller.Password = null;
//ServiceProcessInstaller.Username = null;
//ServiceInstaller.ServiceName = "Service";
//ServiceInstaller.StartType =
System.ServiceProcess.ServiceStartMode.Automatic;

//ServiceProcessInstaller.Uninstall(e.SavedState);
//ServiceInstaller.Uninstall(e.SavedState);

}
}
}
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Windows The Windows Media Connect Service service failed to start due to the following error: Donald Bock Windows XP Help 1 5th Oct 2007 12:28 AM
Strange problem when running a Windows service using Windows Server 2003 Martijn Remmen Microsoft Dot NET 0 22nd Oct 2005 02:09 PM
Strange problem when running a Windows service using Windows Server 2003 Martijn Remmen Microsoft Dot NET 0 21st Oct 2005 03:34 PM
Windows Service - Windows application - Start/Stop Service Murali Microsoft C# .NET 1 22nd Apr 2005 12:49 PM
Process.Start() in windows service on Windows Server 2003, problem Tobias Johansson Microsoft C# .NET 2 21st Feb 2005 01:45 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:37 PM.