Hi,
I used the following code to create a new service in visual c++6.0. while i am running it (using ctrl+F5) it doesnot shows any output. - // sample.cpp : Defines the entry point for the console application.
-
//
-
-
#include "stdafx.h"
-
#include "Windows.h"
-
#include "Winsvc.h"
-
#include "time.h"
-
#include "stdio.h"
-
-
SERVICE_STATUS m_ServiceStatus;
-
SERVICE_STATUS_HANDLE m_ServiceStatusHandle;
-
BOOL bRunning=true;
-
void WINAPI ServiceMain(DWORD argc, LPTSTR *argv);
-
void WINAPI ServiceCtrlHandler(DWORD Opcode);
-
BOOL InstallService();
-
BOOL DeleteService();
-
int main(int argc, char* argv[])
-
{
-
if(argc>1)
-
{
-
if(strcmp(argv[1],"-i")==0)
-
{
-
if(InstallService())
-
printf("\n\nService Installed Sucessfully\n");
-
else
-
printf("\n\nError Installing Service\n");
-
}
-
if(strcmp(argv[1],"-d")==0)
-
{
-
if(DeleteService())
-
printf("\n\nService UnInstalled Sucessfully\n");
-
else
-
printf("\n\nError UnInstalling Service\n");
-
}
-
else
-
{
-
printf("\n\nUnknown Switch Usage\n\nFor Install use Srv1 -i\n\nFor UnInstall use Srv1 -d\n");
-
}
-
}
-
else
-
{
-
SERVICE_TABLE_ENTRY DispatchTable[]=
-
{{"Service1",ServiceMain},{NULL,NULL}};
-
StartServiceCtrlDispatcher(DispatchTable);
-
}
-
return 0;
-
}
-
-
void WINAPI ServiceMain(DWORD argc, LPTSTR *argv)
-
{
-
DWORD status;
-
DWORD specificError;
-
m_ServiceStatus.dwServiceType = SERVICE_WIN32;
-
m_ServiceStatus.dwCurrentState = SERVICE_START_PENDING;
-
m_ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP;
-
m_ServiceStatus.dwWin32ExitCode = 0;
-
m_ServiceStatus.dwServiceSpecificExitCode = 0;
-
m_ServiceStatus.dwCheckPoint = 0;
-
m_ServiceStatus.dwWaitHint = 0;
-
-
m_ServiceStatusHandle = RegisterServiceCtrlHandler("svc", ServiceCtrlHandler);
-
if (m_ServiceStatusHandle == (SERVICE_STATUS_HANDLE)0)
-
{
-
return;
-
}
-
m_ServiceStatus.dwCurrentState = SERVICE_RUNNING;
-
m_ServiceStatus.dwCheckPoint = 0;
-
m_ServiceStatus.dwWaitHint = 0;
-
if (!SetServiceStatus (m_ServiceStatusHandle, &m_ServiceStatus))
-
{
-
}
-
-
bRunning=true;
-
while(bRunning)
-
{
-
Sleep(3000);
-
//Place Your Code for processing here....
-
}
-
return;
-
}
-
-
void WINAPI ServiceCtrlHandler(DWORD Opcode)
-
{
-
switch(Opcode)
-
{
-
case SERVICE_CONTROL_PAUSE:
-
m_ServiceStatus.dwCurrentState = SERVICE_PAUSED;
-
break;
-
case SERVICE_CONTROL_CONTINUE:
-
m_ServiceStatus.dwCurrentState = SERVICE_RUNNING;
-
break;
-
case SERVICE_CONTROL_STOP:
-
m_ServiceStatus.dwWin32ExitCode = 0;
-
m_ServiceStatus.dwCurrentState = SERVICE_STOPPED;
-
m_ServiceStatus.dwCheckPoint = 0;
-
m_ServiceStatus.dwWaitHint = 0;
-
-
SetServiceStatus (m_ServiceStatusHandle,&m_ServiceStatus);
-
bRunning=false;
-
break;
-
case SERVICE_CONTROL_INTERROGATE:
-
break;
-
}
-
return;
-
}
-
-
BOOL InstallService()
-
{
-
char strDir[1024];
-
HANDLE schSCManager,schService;
-
GetCurrentDirectory(1024,strDir);
-
strcat(strDir,"\\Srv1.exe");
-
schSCManager = OpenSCManager(NULL,NULL,SC_MANAGER_ALL_ACCESS);
-
-
if (schSCManager == NULL)
-
return false;
-
LPCTSTR lpszBinaryPathName=strDir;
-
-
schService = CreateService(schSCManager,"Service1",
-
"The Display Name Needed", // service name to display
-
SERVICE_ALL_ACCESS, // desired access
-
SERVICE_WIN32_OWN_PROCESS, // service type
-
SERVICE_DEMAND_START, // start type
-
SERVICE_ERROR_NORMAL, // error control type
-
lpszBinaryPathName, // service's binary
-
NULL, // no load ordering group
-
NULL, // no tag identifier
-
NULL, // no dependencies
-
NULL, // LocalSystem account
-
NULL); // no password
-
-
if (schService == NULL)
-
return false;
-
-
CloseServiceHandle(schService);
-
return true;
-
}
-
-
BOOL DeleteService()
-
{
-
HANDLE schSCManager;
-
SC_HANDLE hService;
-
schSCManager = OpenSCManager(NULL,NULL,SC_MANAGER_ALL_ACCESS);
-
-
if (schSCManager == NULL)
-
return false;
-
hService=OpenService(schSCManager,"Service1",SERVICE_ALL_ACCESS);
-
if (hService == NULL)
-
return false;
-
if(DeleteService(hService)==0)
-
return false;
-
if(CloseServiceHandle(hService)==0)
-
return false;
-
-
return true;
-
}
what i missed here. i couldn't see the service1 in service control panel. how to resolve it.
thanks in advance
0 1111 Sign in to post your reply or Sign up for a free account.
Similar topics
by: R6_2003 |
last post by:
Hello all,
i dunno if that's the right newsgroup to ask, but i'll try, please
ignore me if u feel its not 0:)
i've been messing with a control panel app for so long.. previously i
was using...
|
by: AKR |
last post by:
I have to create control panel applet using C# . I have read in the
net that it is not possible using C# . How can i create control panel
applet using C# .
|
by: GregO |
last post by:
Windows 2000 Server SP3
..NET Framework 1.1
I have a problem opening the control panel on a number of servers.
Only when we kill the asp_wp.exe does the control panel kick into
life.
Is it...
|
by: pealy2 |
last post by:
Sorry if this is in the wrong group, I've searched long & hard without
finding anything even slightly useful. (recommendations for a more
relevant group gratefuly received)
I need to change the...
|
by: Glenn |
last post by:
Hello
Is there any documentation around which shows you ( if it is possible)
how to create a new category for the windows xp control panel.( in
category view)
I would like to create a new...
|
by: Jay |
last post by:
Hey There,
I've been trying to see if there is a way to programmatically block,
or hide, the Control Panel. Since it is a "Virtual Folder", just
blocking an .exe from running doesn't work. Even...
|
by: Frank Burleigh |
last post by:
A while ago I installed Net 2.0 to our Server 2003 web machine, but the
Control Panel folder icon for configuring Net 2.0 never made it to the
Control Panel folder. Thinking this might indicate a...
|
by: strontiumpaul |
last post by:
Hi,
First, let me state, I am a total newbie!!!
C# Application.
I want to create a floating control panel similar to the PhotoShop's floating designer panel (with images as buttons). It must...
|
by: Grok |
last post by:
My C# application is a Windows Service. I have two problems that I
would like to solve in the correct way using C#.NET.
1) There are a number of user settings which I'd like to store in an
XML...
|
by: xtremebass |
last post by:
Hi Bytes,
In my system, cant show the tool Add/Remove Programs in Control Panel.
can you please suggest how can i recover it?
Os :Windows XP,Service Pack 3,
Help..
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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: 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...
|
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...
| |