Riddle Me This

P

pbd22

OK.

Can somebody explain why a windows service, when compiled in Debug
mode,
has no problem starting an executable program in one of its methods
and the
exe does what it is supposed to.

But, when the service is installed using installutil the exe fails.

Why might that be??

Thanks.
 
M

Michael C

pbd22 said:
OK.

Can somebody explain why a windows service, when compiled in Debug
mode,
has no problem starting an executable program in one of its methods
and the
exe does what it is supposed to.

But, when the service is installed using installutil the exe fails.

Why might that be??

Not really sure but I don't think a service should start an exe. What
happens if no-one is logged in? What happens if 2 people are logged in? What
account does the exe run under?

Michael
 
P

pbd22

LocalSystem.

It does start this exe in Debug mode - quite nicely, actually.
Not sure what you mean by "nobody logged in".
It starts automatically at boot.

I put the exe in C:/bin

It is a VB6 project called by a C# service.
 
N

Nicholas Paldino [.NET/C# MVP]

More likely than not, you are running the service executable as
yourself, which probably has elevated permissions. When you install it as a
service, it defaults to the LocalService account (I believe) which does not
have the same permissions. The new process runs under the user of the
process that spawned it.

If you set the service to run under your user account, I bet it would
work. Not that you should do this, though. Rather, you should find out the
permissions the app that the service runs needs, and then create an account
that has the appropriate permissions.
 
M

Michael C

pbd22 said:
LocalSystem.

It does start this exe in Debug mode - quite nicely, actually.
Not sure what you mean by "nobody logged in".

A service can run when no-one is logged in, how is it going to run the exe
when there is no desktop. When 2 people are logged in which person's desktop
is it going to go to?
It starts automatically at boot.

That's right *before* anyone logs in.

Michael
 
P

pbd22

Is this right? Do I need to give my service Admin or some privledge
more powerful
than LocalService to successfully use an external exe?
 
M

Michael D. Ober

pbd22 said:
LocalSystem.

It does start this exe in Debug mode - quite nicely, actually.
Not sure what you mean by "nobody logged in".
It starts automatically at boot.

I put the exe in C:/bin

It is a VB6 project called by a C# service.

Does the Debug version work as a service? Also, since most VB6 programs
require a user interface, how do you handle the fact that there is no UI for
a service?

Mike.
 
P

pbd22

Does the Debug version work as a service?

Yes, swimmingly.
Also, since most VB6 programs
require a user interface, how do you handle the fact that there is no UI for
a service?

I click my heels and say "there is no place like home"?

Well, this was the thinking behind the exe in the first place.
We wanted the DLL to be called from the service but the COM object
is STA and the service (C#) is MTA and we couldnt come up with a
reliable way to handle the differences. Declaring the service as
[STAThread] did not do the trick nor did other programmatic tricks.

So, this is what we are doing.

I am starting to come into Michael C's camp - it makes sense that the
LocalSystem
permissions are less powerful than my user account and therefore I am
having access
problems.

I tried setting my account to "User" and the username/pass to my
windows login.

But, now, when I try to start the service, it tells me I couldn't
login.

Question, must I set the windows account programmatically in the
service and
in the properties >> login tab in Services???

thanks.
 
T

Tobias Schröer

pbd22 said:
So, this is what we are doing.

I am starting to come into Michael C's camp - it makes sense that the
LocalSystem
permissions are less powerful than my user account and therefore I am
having access
problems.

Does your exe has any UI? I guess not, reading the other posts.
Does your exe access other resources than local resources (e.g.
network)? That would not be permitted to Local System.
I tried setting my account to "User" and the username/pass to my
windows login.

But, now, when I try to start the service, it tells me I couldn't
login.

Your account needs the "login as service" privilege (local security
settings).

HTH,
Tobi
 
D

DeveloperX

Does the Debug version work as a service?  Also, since most VB6 programs
require a user interface, how do you handle the fact that there is no UI for
a service?

Mike.

No they don't. Project properties -> Start up object -> Sub main.

What does the exe do? One handy trick is to import ExitProcess

Private Declare Sub ExitProcess Lib "kernel32" (ByVal uExitCode As
Long)

and then return a meaningful return code depending on where the exe
fails. At the very least it will tell you whether the exe manages to
start at all. I'm going with rights though. As you mention below, go
into services and specify your fully qualified account details (to
test) and then try and start it.
 
C

christery

An VB6 app that wants to be run as an service with
(click in checkbox for can interact with desktop)
or without UI should (must?) use ntsvc.ocx or whatever its called,
search on the net for that little tease ;)
//CY
 
F

Family Tree Mike

Or give execute rights to the LocalService account on your external exe and
any file paths that it uses. All of this assumes there is no desktop
interaction by the external application.
 
P

pbd22

Thank everybody for your suggestions.

The purpose of the EXE is to open a file, read its metadata,
create a text file, move the metadata to the text file,
close the file, exit.

So, it sounds to me like this very much uses the desktop!

I have tried clicking the interact with desktop option on the Logon
tab in services >> my service >> poperties but this didn't change
anything.

The EXE is, of course, STA. It originally had a UI but this bit of
code does not assume UI interaction in any way. It does what
I said it does above when it finds a file in the folder I point it to.

OK, I am going to try your suggestions (thanks). And, please
let me know if my info here further reveals the solution.

Regards,
Peter
 
P

pbd22

DeveloperX,
Private Declare Sub ExitProcess Lib "kernel32" (ByVal uExitCode As
Long)

This may sound dull, but I am assuming that this line of code belongs
in the EXE itself, and not in the service?

Peter
 
P

pbd22

DeveloperX,

Another question,

At what point should I be firing ExitProcess?
There is no FormUnload as there is no form or,
for that matter, any user interaction.

Can you provide a little more direction (or code?).

Thanks.
 
P

pbd22

OK.

Still not working.

I am thinking this HAS to be a permissions error and I
am just not putting my ducks in a row.

The Debug version works no prob, the service does not.
 
W

Willy Denoyette [MVP]

pbd22 said:
OK.

Still not working.

I am thinking this HAS to be a permissions error and I
am just not putting my ducks in a row.

The Debug version works no prob, the service does not.



Why do you call one a "Debug version" and the other a "service"?
You have a debug version and a release version or your service, but both are
services, right?
Does your debug version works as expected when installed using installutil?

Willy.
 

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