473,657 Members | 2,434 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C++.Net Windows Service

Hi guys ...

I am writing a Windows Service in C++.Net, and have run
into difficulties with installing this successfully using
InstallUtil.exe ...

Exception occurred while initializing the installation:

System.IO.FileL oadException: Unverifiable
image 'my_service.exe ' can not be run..

I can post my code here for people to have a look, but was
curious as to whether anybody has or knows of a very
simple C++ .NET Windows Service example, that installs and
uninstalls using InstallUtil.exe successfully ?

I have found many C# and VB.Net examples ... but
specifically need C++.Net example / tutorial. The example
doesn't need to have any functionality, just install /
Uninstall correctly :-)

I was curious as to whether M$ had announced any problems
here, as there dont appear to be any examples ?!?

Any help is much appreciated,
STeve
Nov 16 '05 #1
7 6021
I think installutil can't deal with assemblies that have native code. You
need to write installer in C# and then use installutil or just call win32
api from C++.
http://msdn.microsoft.com/library/en..._a_service.asp

CreateService/OpenService/DeleteService

"STeve" <St*******@hotm ail.com> wrote in message
news:16******** *************** *****@phx.gbl.. .
Hi guys ...

I am writing a Windows Service in C++.Net, and have run
into difficulties with installing this successfully using
InstallUtil.exe ...

Exception occurred while initializing the installation:

System.IO.FileL oadException: Unverifiable
image 'my_service.exe ' can not be run..

I can post my code here for people to have a look, but was
curious as to whether anybody has or knows of a very
simple C++ .NET Windows Service example, that installs and
uninstalls using InstallUtil.exe successfully ?

I have found many C# and VB.Net examples ... but
specifically need C++.Net example / tutorial. The example
doesn't need to have any functionality, just install /
Uninstall correctly :-)

Nov 16 '05 #2
Hi Pent ...

I understood that managed C++ code, only using the .Net
framework libraries, should have very simililar MSIL code
to C# and VB.Net ... subsequently there would be little
difference for C++.Net and no native code ?
Nov 16 '05 #3
Only if you create "verifiable " assembly. You have to follow specific steps
in VS.NET 2003:
http://msdn.microsoft.com/library/en...thmanagedc.asp
"STeve" <St*******@hotm ail.com> wrote in message
news:07******** *************** *****@phx.gbl.. .
Hi Pent ...

I understood that managed C++ code, only using the .Net
framework libraries, should have very simililar MSIL code
to C# and VB.Net ... subsequently there would be little
difference for C++.Net and no native code ?

Nov 16 '05 #4
Pent ... this is great information .. let me process this
and get back to you !

STeve
Nov 16 '05 #5
Pent ...

I've now read 3 articles on Verifiable Assemblies. They
state that this is not only difficult to achieve due to
the number of restrictions, but also not a recommendable
solution.

I now appreciate that this is not a realistic option, and
that also throws using InstallUtil (directly) and the
ServiceInstalle r class out the window.

I do find it hard to believe however, that we are provided
with the install mechanism in each VC++.net service
project, but no way to uninstall without registry removals
and a reboot ?!?!?

Why do we have a :
if (_tcsicmp(argv[1], _T("-Install")) == 0)

and no :
else if (_tcsicmp(argv[1], _T("-UnInstall")) == 0)
Can you confirm this please ?

Your help is much appreciated,
STeve
Nov 16 '05 #6
Hi guys,

I have found a solution, courtesy of C++.Net Guru Kate
Gregory
http://www.gregcons.com/kate.htm
These issues are addressed in her new book published this
week:
http://www.visualc-kickstart.com/

The C++ .Net Windows Service install is undertaken as
follows :
myservice.exe -install

The C++ .Net Windows Service UnInstall is undertaken as
follows :
myservice.exe -install /u

This is all processed via the standard default code
provided for you in the C++.Net Windows Service Project
template :

if ((sCmdLineArg->ToUpper())->CompareTo(S"-INSTALL") == 0)
{
// ***** NOTE ***** This small routine will Install
and UnInstall this Service

String* myargs[] =
System::Environ ment::GetComman dLineArgs();
String* args[] = new String*[myargs->Length - 1];
args[0] = (myargs[0]);
Array::Copy(mya rgs, 2, args, 1, args->Length -
1);

Type* type = __typeof(System ::Object);
String* path = type->get_Assembly ()->get_Location() ;
StringBuilder* sb = new StringBuilder(p ath->Substring
(0, path->LastIndexOf(S" \\")));
sb->Append(S"\\Ins tallUtil.exe");

AppDomain* dom = AppDomain::Crea teDomain(S"exec Dom");
dom->ExecuteAssembl y(sb->ToString(), 0, args);
}

Best Regards,
STeve

Nov 16 '05 #7
Oh ok that works fine. Just add -UnInstall switch handling and pass /u as
arg to InstallUtil. I just tried it and it works great. This is on VS2003

"STeve" <St*******@Hotm ail.com> wrote in message
news:20******** *************** *****@phx.gbl.. .
Pent ...

I've now read 3 articles on Verifiable Assemblies. They
state that this is not only difficult to achieve due to
the number of restrictions, but also not a recommendable
solution.

I now appreciate that this is not a realistic option, and
that also throws using InstallUtil (directly) and the
ServiceInstalle r class out the window.

I do find it hard to believe however, that we are provided
with the install mechanism in each VC++.net service
project, but no way to uninstall without registry removals
and a reboot ?!?!?

Why do we have a :
if (_tcsicmp(argv[1], _T("-Install")) == 0)

and no :
else if (_tcsicmp(argv[1], _T("-UnInstall")) == 0)
Can you confirm this please ?

Your help is much appreciated,
STeve

Nov 16 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
2259
by: Michael Riggio | last post by:
Is there a way to have a windows service instantiate a class that is a web service, which will then be accessible to clients via HTTP? Thanks, -Mike
1
5682
by: Artur Kowalski | last post by:
I have a NotifyIcon in my Windows Service project and I am trying to add a ContextMenu to this NotifyIcon or use some of the mouse events. Everything isn't working. I think so base class of the service System.ServiceProcess.ServiceBase don't catchWindows messages like mouse or timer messages. Any Idea? Thanks,
9
7252
by: SP | last post by:
Hi All, I wrote a windows service which is supposed to stop after specified amount of time. I am calling OnStop() after specified time. OnStop() methods executed but I dont see the service stopping. Please advise how to stop the service. Thanks, SP
1
3446
by: Scott Davies | last post by:
Hi, I'm looking for some help on a small program that I'm trying to develop in VB.NET. I'm having trouble getting the code that I've written to work, can anyone shed some light as to where I'm going wrong. The program has been written to do the following tasks: - Select remote server - Select from two specific services
0
3931
by: Scott Davies | last post by:
Hi, I'm looking for some help on a small program that I'm trying to develop in VB.NET. The program I'm trying to develop needs to be able to do the following: - Select remote server - Select from two specific services - Check the status of the server
3
3684
by: Doug Bailey | last post by:
I am trying to control a Windows Service via a Web Service interface. (I am developing in .NET2003) I am using the ServiceController object which allows me to read the state of the services with no problems. However, I am not able to start or stop the service unless I go through the process of impersonating an administrative user. (See MSDN KB 306158) Since it appears to be a privilege issue, I set the folders in IIS holding the Web...
2
6888
by: deko | last post by:
When to use a privileged user thread rather than a windows service? That's the question raised in a previous post . It was suggested that if the service needs to interact with a WinForms app (which is the UI used to adjust the actions taken by, and the schedule of the service), then a privileged user thread should be used in the UI - no service required. But... "A windows service enables the creation of long-running executable
4
4174
by: tshad | last post by:
What would be a good way to check programmatically whether a service was running? We have a service that dies periodically and I need to check to see if this service is running. I know how to check to see if the status is in stopped or running mode. But that doesn't tell me if it is actually running. I need to know this so that if it happens I can programmatically start the same service on another machine.
5
3296
by: dm3281 | last post by:
I'm really starting to hate writing services -- or trying to, anyway. Why do I need to rename my project to the service name? Why do I need to set the "ServiceName" property to my service name? Why do I need to set a property within my code to the service name? Are all these required or am I just doing this for consistency purposes?
1
2081
by: =?Utf-8?B?TWFuanJlZSBHYXJn?= | last post by:
Hi, I created a web service that I want to host in windows service. The problem is that if I host it as windows service it does not use the configuration file. I have to define the binding, endpoint etc. programmatically in the Program.cs file. Any idea what I might be doing wrong? Cheers,
0
8395
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8826
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8732
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8605
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6166
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4155
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4306
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1615
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.