C++.Net Windows Service

S

STeve

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.FileLoadException: 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
 
S

STeve

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 ?
 
S

STeve

Pent ... this is great information .. let me process this
and get back to you !

STeve
 
S

STeve

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
ServiceInstaller 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
 
S

STeve

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::Environment::GetCommandLineArgs();
String* args[] = new String*[myargs->Length - 1];
args[0] = (myargs[0]);
Array::Copy(myargs, 2, args, 1, args->Length -
1);

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

AppDomain* dom = AppDomain::CreateDomain(S"execDom");
dom->ExecuteAssembly(sb->ToString(), 0, args);
}

Best Regards,
STeve
 
P

Pent

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top