using a console window from a service

Hi,

I am currently writing a service for window 2000. During the debugging
process I though it would be nice if I was able to output text to a console
window. During the startup of the service I made a call to AllocConsole()
(which appears to work), although I do not get a console window.

I also tried using OutputDebugString(), however since the service is
not running under a debugger I was unable to see the output (note,
using sysinternals DbgView I am able to capture the output).

I have a feeling that the problem is that there is no desktop associated
with the service so there is no where for the console window to be
display.

I am wondering if there is a way to get a console window for debug?
The question is now more acadamic since DbgView works.

George Huber
Computer Scientist
SRI, International

Technically, NT services aren’t supposed to access consoles or windows…
Even thought you can make them… I read that somewhere in MSDN…

For my project I’m using OutputDebugString and WinDebug on a separate PC
connect via a serial port. And that works very well for me… If I really
want to debug my service, I can either run my service as a Win32 Console
mode app or Attach to the process in the debugger.

Thanks,
Weston Fryatt

----- Original Message -----
From: “Huber, George K CECOM RDEC STCD SRI” <george.k.huber>
To: “NT Developers Interest List”
Sent: Friday, February 21, 2003 4:16 PM
Subject: [ntdev] using a console window from a service

> Hi,
>
> I am currently writing a service for window 2000. During the debugging
> process I though it would be nice if I was able to output text to a
console
> window. During the startup of the service I made a call to AllocConsole()
> (which appears to work), although I do not get a console window.
>
> I also tried using OutputDebugString(), however since the service is
> not running under a debugger I was unable to see the output (note,
> using sysinternals DbgView I am able to capture the output).
>
> I have a feeling that the problem is that there is no desktop associated
> with the service so there is no where for the console window to be
> display.
>
> I am wondering if there is a way to get a console window for debug?
> The question is now more acadamic since DbgView works.
>
> George Huber
> Computer Scientist
> SRI, International
>
>
>
> —
> You are currently subscribed to ntdev as: xxxxx@muuf.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
></george.k.huber>

George,

it’s probably best to have the service compiled as a console application
(this is just a subsystem flag in the PE header). It will aquire the console
automatically then. Next step would be to set the interactive flag for the
service and then start it. (I usually use Service Manager to achieve this:
www.nttools-online.de).

You might experience problems under certain circumstances, in case your
system was patched against the WM_TIMER exploit (shatter attack).

Cheers,

Oliver

Technically, NT services aren’t supposed to access consoles or windows…
Even thought you can make them… I read that somewhere in MSDN…

For my project I’m using OutputDebugString and WinDebug on a separate PC
connect via a serial port. And that works very well for me… If I really
want to debug my service, I can either run my service as a Win32 Console
mode app or Attach to the process in the debugger.

Thanks,
Weston Fryatt

----- Original Message -----
From: “Huber, George K CECOM RDEC STCD SRI” <george.k.huber>
> To: “NT Developers Interest List”
> Sent: Friday, February 21, 2003 4:16 PM
> Subject: [ntdev] using a console window from a service
>
>
> > Hi,
> >
> > I am currently writing a service for window 2000. During the debugging
> > process I though it would be nice if I was able to output text to a
> console
> > window. During the startup of the service I made a call to
> AllocConsole()
> > (which appears to work), although I do not get a console window.
> >
> > I also tried using OutputDebugString(), however since the service is
> > not running under a debugger I was unable to see the output (note,
> > using sysinternals DbgView I am able to capture the output).
> >
> > I have a feeling that the problem is that there is no desktop associated
> > with the service so there is no where for the console window to be
> > display.
> >
> > I am wondering if there is a way to get a console window for debug?
> > The question is now more acadamic since DbgView works.
> >
> > George Huber
> > Computer Scientist
> > SRI, International
> >
> >
> >
> > —
> > You are currently subscribed to ntdev as: xxxxx@muuf.com
> > To unsubscribe send a blank email to xxxxx@lists.osr.com
> >
>
>
>


---------------------------------------------------
May the source be with you, stranger :wink:

Contacts / Kontakte
eMail: xxxxx@gmx.net|info|de|com & xxxxx@ePost.de
ICQ UIN #281645
AIM: “nixahnungnicht” & “nixlosheute”
Y! aka YIM: “sherlock_holmes_and_dr_watson”
MSNM (Passport): “xxxxx@ePost.de
http://assarbad.org & http://assarbad.net</george.k.huber>

How about writing/appending the debug messages to a log text file say
mylogfile.txt (flush the data after every write to the log file), and
running a “tail.exe -f mylogfile.txt”. That’s the way I use for
services/windows program which doesn’t uses console etc.

Avi

-----Original Message-----
From: Weston Fryatt [mailto:xxxxx@muuf.com]
Sent: Friday, February 21, 2003 5:41 PM
To: NT Developers Interest List
Subject: [ntdev] Re: using a console window from a service

Technically, NT services aren’t supposed to access consoles or windows…
Even thought you can make them… I read that somewhere in MSDN…

For my project I’m using OutputDebugString and WinDebug on a separate PC
connect via a serial port. And that works very well for me… If I really
want to debug my service, I can either run my service as a Win32 Console
mode app or Attach to the process in the debugger.

Thanks,
Weston Fryatt

----- Original Message -----
From: “Huber, George K CECOM RDEC STCD SRI” <george.k.huber>
To: “NT Developers Interest List”
Sent: Friday, February 21, 2003 4:16 PM
Subject: [ntdev] using a console window from a service

> Hi,
>
> I am currently writing a service for window 2000. During the debugging
> process I though it would be nice if I was able to output text to a
console
> window. During the startup of the service I made a call to AllocConsole()
> (which appears to work), although I do not get a console window.
>
> I also tried using OutputDebugString(), however since the service is
> not running under a debugger I was unable to see the output (note,
> using sysinternals DbgView I am able to capture the output).
>
> I have a feeling that the problem is that there is no desktop associated
> with the service so there is no where for the console window to be
> display.
>
> I am wondering if there is a way to get a console window for debug?
> The question is now more acadamic since DbgView works.
>
> George Huber
> Computer Scientist
> SRI, International
>
>
>
> —
> You are currently subscribed to ntdev as: xxxxx@muuf.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>


You are currently subscribed to ntdev as: xxxxx@commvault.com
To unsubscribe send a blank email to xxxxx@lists.osr.com</george.k.huber>

> I am wondering if there is a way to get a console window for debug?

The usual way of doing this is writing a service which can be also
executed as a command-line app. For instance, MSSQLServer was such for
years.

Max

Set permission for the service. Check the box under service properties for
“Allow service to interact with desktop”.

Govind
www.nesttech.com

-----Original Message-----
From: Huber, George K CECOM RDEC STCD SRI
[mailto:George.K.Huber@us.army.mil]
Sent: Saturday, February 22, 2003 3:47 AM
To: NT Developers Interest List
Subject: [ntdev] using a console window from a service

Hi,

I am currently writing a service for window 2000. During the debugging
process I though it would be nice if I was able to output text to a console
window. During the startup of the service I made a call to AllocConsole()
(which appears to work), although I do not get a console window.

I also tried using OutputDebugString(), however since the service is
not running under a debugger I was unable to see the output (note,
using sysinternals DbgView I am able to capture the output).

I have a feeling that the problem is that there is no desktop associated
with the service so there is no where for the console window to be
display.

I am wondering if there is a way to get a console window for debug?
The question is now more acadamic since DbgView works.

George Huber
Computer Scientist
SRI, International


You are currently subscribed to ntdev as: xxxxx@nestec.net
To unsubscribe send a blank email to xxxxx@lists.osr.com