Hi all,
I created a Minimal Windows Service Program in Visual Studio.NET VC# using
the Wizard...i just added the MessageBox Display in OnStart() function and my
service is installed properly...but when i started the Service it display
that "Local Service started and stopped , Serivces should have Log Support
and Alerts Isssued"..
what is this error??...am running Windows XP Home Edition,
i have given the AccountType as "LocalService",i tried with everything
excpet with User...i no need to run as User...
i would be happy if anyone could help me sort out this ...
with regards,
C.C.Chakkaradeep 12 4838
The errors is that you should not show a message box from a service.
Services are meant to run in the background without any user interaction
requirements.
Willy.
"Chakkaradeep" <Ch**********@discussions.microsoft.com> wrote in message
news:12**********************************@microsof t.com... Hi all,
I created a Minimal Windows Service Program in Visual Studio.NET VC# using the Wizard...i just added the MessageBox Display in OnStart() function and my service is installed properly...but when i started the Service it display that "Local Service started and stopped , Serivces should have Log Support and Alerts Isssued"..
what is this error??...am running Windows XP Home Edition,
i have given the AccountType as "LocalService",i tried with everything excpet with User...i no need to run as User...
i would be happy if anyone could help me sort out this ...
with regards, C.C.Chakkaradeep
Hi Willy,
so then how to check it out whether it is running or not..and is Socket
Communication possible in Services.....that is,..my service should act as a
Multithreaded Server monitoring a Port Number and if any informations come to
the port it should accept the sockets and exeute something so that the
Service has completed it's job...
am a newbie to to this Service...
with regards,
C.C.Chakkaradeep
"Willy Denoyette [MVP]" wrote: The errors is that you should not show a message box from a service. Services are meant to run in the background without any user interaction requirements.
Willy.
"Chakkaradeep" <Ch**********@discussions.microsoft.com> wrote in message news:12**********************************@microsof t.com... Hi all,
I created a Minimal Windows Service Program in Visual Studio.NET VC# using the Wizard...i just added the MessageBox Display in OnStart() function and my service is installed properly...but when i started the Service it display that "Local Service started and stopped , Serivces should have Log Support and Alerts Isssued"..
what is this error??...am running Windows XP Home Edition,
i have given the AccountType as "LocalService",i tried with everything excpet with User...i no need to run as User...
i would be happy if anyone could help me sort out this ...
with regards, C.C.Chakkaradeep
Socket communications are no issue. But you should be aware that services
are (should be) running in a restricted security context:
- They should not assume the presence of an interactive desktop nor an
interactive user (logon session).
- For security reasons, they should run with the least privileges possible
(run as NetworkService or LocalService).
Running as LocalSystem gives the service high privileges on the local system
but no access to remote system resources, it's the only account that enables
a service to interact with the desktop (to enable this - run services applet
and check/enable this property).
While it's possible to enable this option for quick and dirty debugging, I
would suggest you use one of the other facilities offered by .NET for
debugging and tracing (write to log file or eventlog, output to debugger
window etc.).
Willy.
"Chakkaradeep" <Ch**********@discussions.microsoft.com> wrote in message
news:E1**********************************@microsof t.com... Hi Willy,
so then how to check it out whether it is running or not..and is Socket Communication possible in Services.....that is,..my service should act as a Multithreaded Server monitoring a Port Number and if any informations come to the port it should accept the sockets and exeute something so that the Service has completed it's job...
am a newbie to to this Service...
with regards, C.C.Chakkaradeep
"Willy Denoyette [MVP]" wrote:
The errors is that you should not show a message box from a service. Services are meant to run in the background without any user interaction requirements.
Willy.
"Chakkaradeep" <Ch**********@discussions.microsoft.com> wrote in message news:12**********************************@microsof t.com... > Hi all, > > I created a Minimal Windows Service Program in Visual Studio.NET VC# > using > the Wizard...i just added the MessageBox Display in OnStart() function > and > my > service is installed properly...but when i started the Service it > display > that "Local Service started and stopped , Serivces should have Log > Support > and Alerts Isssued".. > > what is this error??...am running Windows XP Home Edition, > > i have given the AccountType as "LocalService",i tried with everything > excpet with User...i no need to run as User... > > i would be happy if anyone could help me sort out this ... > > with regards, > C.C.Chakkaradeep
Hi Willy,
so u mean to say that i can accept a socket and receive messages but i cant
send messages back to the client??
with regards,
C.C.Chakkaradeep
"Willy Denoyette [MVP]" wrote: Socket communications are no issue. But you should be aware that services are (should be) running in a restricted security context: - They should not assume the presence of an interactive desktop nor an interactive user (logon session). - For security reasons, they should run with the least privileges possible (run as NetworkService or LocalService). Running as LocalSystem gives the service high privileges on the local system but no access to remote system resources, it's the only account that enables a service to interact with the desktop (to enable this - run services applet and check/enable this property). While it's possible to enable this option for quick and dirty debugging, I would suggest you use one of the other facilities offered by .NET for debugging and tracing (write to log file or eventlog, output to debugger window etc.).
Willy.
"Chakkaradeep" <Ch**********@discussions.microsoft.com> wrote in message news:E1**********************************@microsof t.com... Hi Willy,
so then how to check it out whether it is running or not..and is Socket Communication possible in Services.....that is,..my service should act as a Multithreaded Server monitoring a Port Number and if any informations come to the port it should accept the sockets and exeute something so that the Service has completed it's job...
am a newbie to to this Service...
with regards, C.C.Chakkaradeep
"Willy Denoyette [MVP]" wrote:
The errors is that you should not show a message box from a service. Services are meant to run in the background without any user interaction requirements.
Willy.
"Chakkaradeep" <Ch**********@discussions.microsoft.com> wrote in message news:12**********************************@microsof t.com... > Hi all, > > I created a Minimal Windows Service Program in Visual Studio.NET VC# > using > the Wizard...i just added the MessageBox Display in OnStart() function > and > my > service is installed properly...but when i started the Service it > display > that "Local Service started and stopped , Serivces should have Log > Support > and Alerts Isssued".. > > what is this error??...am running Windows XP Home Edition, > > i have given the AccountType as "LocalService",i tried with everything > excpet with User...i no need to run as User... > > i would be happy if anyone could help me sort out this ... > > with regards, > C.C.Chakkaradeep
"Chakkaradeep" <Ch**********@discussions.microsoft.com> wrote in message
news:1E**********************************@microsof t.com... Hi Willy,
so u mean to say that i can accept a socket and receive messages but i cant send messages back to the client??
No, I said Sockets are no problem.
Willy.
hi,
so then Sockets are not issue...hmm...nice to hear...so i can just create
Sockets using TcpListener and accept TcpClients,rite?.....and how to check
for OnStart() function...by storing some informations in files???
with regards,
C.C.Chakkaradeep
"Willy Denoyette [MVP]" wrote: "Chakkaradeep" <Ch**********@discussions.microsoft.com> wrote in message news:1E**********************************@microsof t.com... Hi Willy,
so u mean to say that i can accept a socket and receive messages but i cant send messages back to the client??
No, I said Sockets are no problem. Willy.
"Chakkaradeep" <Ch**********@discussions.microsoft.com> wrote in message
news:DF**********************************@microsof t.com... hi,
so then Sockets are not issue...hmm...nice to hear...so i can just create Sockets using TcpListener and accept TcpClients,rite?.....and how to check for OnStart() function...by storing some informations in files???
Just write a message to the eventlog.
Willy.
hi willy ,
here is my code for Service...
/*********Service OnStart( ) function starts here**********************/
protected override void OnStart(string[] args)
{
// TODO: Add code here to start your service.
System.Net.IPAddress localAdd=System.Net.IPAddress.Parse("127.0.0.1");
const int portNumber = 3000;
TcpListener tcpListener = new TcpListener(localAdd,portNumber);
tcpListener.Start();
//try
{
//Accept the pending client connection and return a TcpClient initialized
for communication.
TcpClient tcpClient = tcpListener.AcceptTcpClient();
NetworkStream networkStream =
tcpClient.GetStream();
string responseString = "You have successfully connected to me";
Byte[] sendBytes = Encoding.ASCII.GetBytes(responseString);
networkStream.Write(sendBytes, 0, sendBytes.Length);
tcpClient.Close();
tcpListener.Stop();
}
}
/*********Service OnStart( ) function ends here**********************/
I tried with evry Account....when i start the service,it is taking much time
and then finally tells that the servie cannot be installed becoz it is out of
time.....what is my error???
The client progrm is here...
/*********Client Program Starts here**********************/
static void Main(string[] args)
{
TcpClient tcpClient = new TcpClient();
try {
tcpClient.Connect("localhost", 3000);
NetworkStream networkStream = tcpClient.GetStream();
if(networkStream.CanWrite && networkStream.CanRead){
// Does a simple write.
Byte[] sendBytes = Encoding.ASCII.GetBytes("Is anybody there");
networkStream.Write(sendBytes, 0, sendBytes.Length);
// Reads the NetworkStream into a byte buffer.
byte[] bytes = new byte[tcpClient.ReceiveBufferSize];
networkStream.Read(bytes, 0, (int) tcpClient.ReceiveBufferSize);
// Returns the data received from the host to the console.
string returndata = Encoding.ASCII.GetString(bytes);
Console.WriteLine("This is what the host returned to you: " +
returndata);
}
else if (!networkStream.CanRead)
{
Console.WriteLine("You can not write data to this stream");
tcpClient.Close();
}
else if (!networkStream.CanWrite)
{
Console.WriteLine("You can not read data from this stream");
tcpClient.Close();
}
}
catch (Exception e )
{
Console.WriteLine(e.ToString());
}
}
/*********Client Program ends here**********************/
The Server and Client Samples were taken from MSDN only.....
what would be the problem...
with regards,
C.C.Chakkaradeep
"Chakkaradeep" <Ch**********@discussions.microsoft.com> ha scritto nel
messaggio news:F5**********************************@microsof t.com... hi willy ,
here is my code for Service...
/*********Service OnStart( ) function starts here**********************/ protected override void OnStart(string[] args) { // TODO: Add code here to start your service. System.Net.IPAddress localAdd=System.Net.IPAddress.Parse("127.0.0.1"); const int portNumber = 3000; TcpListener tcpListener = new TcpListener(localAdd,portNumber); tcpListener.Start(); //try { //Accept the pending client connection and return a TcpClient initialized for communication. TcpClient tcpClient = tcpListener.AcceptTcpClient(); NetworkStream networkStream = tcpClient.GetStream(); string responseString = "You have successfully connected to me";
Byte[] sendBytes = Encoding.ASCII.GetBytes(responseString); networkStream.Write(sendBytes, 0, sendBytes.Length);
tcpClient.Close(); tcpListener.Stop();
} } /*********Service OnStart( ) function ends here**********************/
I tried with evry Account....when i start the service,it is taking much time and then finally tells that the servie cannot be installed becoz it is out of time.....what is my error???
This code is correct, but it can't work; the SCM calls the OnStart()
function and expects it to return, or it will report the timout you're
experiencing; so you can do only initializations there, not your main
processing (i.e. waiting for connections). You'll have to run the service on
a different thread than the one who calls OnStart. You have two choiches
here: spawn the worker thread manually and have it run the same code you
tried to run inside OnStart(), or use async sockets..
Massimo
"Chakkaradeep" <Ch**********@discussions.microsoft.com> wrote in message
news:F5**********************************@microsof t.com... hi willy ,
The Server and Client Samples were taken from MSDN only.....
what would be the problem...
with regards, C.C.Chakkaradeep
You should not do anything that takes longer than 30 seconds in your OnStart
method. What you should do in your OnStart is spawn a background threads and
run your code on that thread. When your thread has started you simply return
from OnStart.
Willy.
Hi,
at last i did write a Service which acts a Multithreaded Server...thanks for
ur help Willy and others.....
i did these steps...
In OnStart() spawned a thread to Start Listening over a port,when a socket
is received...accept it and spawn another thread so that i can be executed in
it's own area...thus there wil be 2 threads created in my program .....
a)One thread for Listening,done only once
b)For each client , a thread will be spawned
With regards,
C.C.Chakkaradeep.
"Willy Denoyette [MVP]" wrote:
"Chakkaradeep" <Ch**********@discussions.microsoft.com> wrote in message news:F5**********************************@microsof t.com... hi willy ,
The Server and Client Samples were taken from MSDN only.....
what would be the problem...
with regards, C.C.Chakkaradeep
You should not do anything that takes longer than 30 seconds in your OnStart method. What you should do in your OnStart is spawn a background threads and run your code on that thread. When your thread has started you simply return from OnStart.
Willy.
Yes, there is.
Add following class to the cs file that contains the Installer class (class
derived from System.Configuration.Install.Installer).
Change the class ServiceInstaller into ServiceInstallerEx and create an
instance of ServiceInstallerEx instead of ServiceInstaller .
Finally add - using System.Management;
class ServiceInstallerEx : System.ServiceProcess.ServiceInstaller
{
public ServiceInstallerEx() : base()
{
// Set eventhandler to call UpdateServiceConfig when install commited
base.Committed += new InstallEventHandler( this.UpdateServiceConfig );
}
// Eventhandler, called after service installer committed.
// This method uses System.Management classes to change service config.
// Note that enabling "DesktopInteract" will fail if Service account is not
LocalSystem !!
void UpdateServiceConfig(object sender, InstallEventArgs e)
{
int ret;
ManagementBaseObject inParams = null;
ManagementObject srvc = new ManagementObject("Win32_Service=" + "\"" +
this.ServiceName + "\"");
inParams = srvc.GetMethodParameters("Change");
inParams["DesktopInteract"] = true; // Enable interactive mode (Interact
With Desktop)
ManagementBaseObject outParams = srvc.InvokeMethod("Change", inParams,
null);
if((ret = Convert.ToInt32(outParams.Properties["ReturnValue"].Value)) !=
0)
Console.WriteLine("Failed to set option: {0}", ret);
else
Console.WriteLine("Option set");
}
}
Willy.
"Chakkaradeep" <Ch**********@discussions.microsoft.com> wrote in message
news:68**********************************@microsof t.com... Hi,
at last i did write a Service which acts a Multithreaded Server...thanks for ur help Willy and others.....
i did these steps...
In OnStart() spawned a thread to Start Listening over a port,when a socket is received...accept it and spawn another thread so that i can be executed in it's own area...thus there wil be 2 threads created in my program ..... a)One thread for Listening,done only once b)For each client , a thread will be spawned
With regards, C.C.Chakkaradeep.
"Willy Denoyette [MVP]" wrote:
"Chakkaradeep" <Ch**********@discussions.microsoft.com> wrote in message news:F5**********************************@microsof t.com... > hi willy ,
> > The Server and Client Samples were taken from MSDN only..... > > what would be the problem... > > with regards, > C.C.Chakkaradeep > You should not do anything that takes longer than 30 seconds in your OnStart method. What you should do in your OnStart is spawn a background threads and run your code on that thread. When your thread has started you simply return from OnStart.
Willy.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Stefan Hinz |
last post by:
Degan,
jumping in to try and solve some problems that look pretty obvious to
me ...
> #options for default service (mysqld2)
> (mysqld2)
It should be , not (mysqld2).
|
by: Bill Sonia |
last post by:
I've written a Windows Service to send e-mails on events like OnStart,
OnStop, OnShutDown using System.Web.Mail. It works for everything but
OnShutdown. My guess is that for OnShutDown, once my...
|
by: illegal.prime |
last post by:
Hi all, I have a service that needs to start a regular windows
application.
I'm running the service as ServiceAccount.LocalSystem.
But, when it starts the process (using Process.Start) the GUI...
|
by: =?Utf-8?B?dmlzaHJ1dGg=?= |
last post by:
This code works fine in Windows Application.
In Windows Application, I am able to zip the image files properly and it
totally contains 900MB
My problem is the same code which I used in my Windows...
|
by: =?Utf-8?B?dmlzaHJ1dGg=?= |
last post by:
Hi,
I have 2 applications running, one Windows application project and the other
windows services project.
I want to call my Windows application in my windows services.
I want to run them as...
| |
by: =?Utf-8?B?dmlzaHJ1dGg=?= |
last post by:
Hi,
I have 2 applications running, one Windows application project and the other
windows services project.
I want to call my Windows application in my windows services.
I want to run them as...
|
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?...
|
by: AmberJain |
last post by:
Windows Autorun FAQs: Overview
NOTE- This complete article on "Windows Autorun FAQs" applies theoretically to all Windows NT-based OSes till Windows Vista (and probably Vista's successors too)....
|
by: AmberJain |
last post by:
Windows Autorun FAQs: List of autostart locations
Linked from the Original article- "Windows Autorun FAQs: Description".
Que: Can you list all the autostart locations for windows?
Ans: Here is...
|
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,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |
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,...
|
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |