这种问题大家有没有碰到???

MEFULEU 2006-01-20 11:17:29
写了一个服务;

服务中可以实现各种功能; ^o^ 例如黑客

那么想从外边使用不同的参数来调用不同的功能;

问题来了;参数怎么传递进去的!!!

LPCTSTR ParamValue[2];
ParamValue[0]="MYService\0";
ParamValue[1]="fun1\0";

scm=OpenSCManager(NULL,NULL,SC_MANAGER_CONNECT);
if (scm!=NULL){
svc=OpenService(scm,"YGService",SERVICE_START);
if (svc!=NULL)
{
StartService(svc,2,ParamValue);//开始Service
CloseServiceHandle(svc);
}
CloseServiceHandle(scm);
}

可是参数怎么都传递不进去啊;

服务中,我已经用文件保存了参数,可惜的不到送进来的参数!!!!!!!!!!!
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
try
{
FILE *fp=fopen("d:\\ss1.txt","a+");
fprintf(fp,IntToStr(ParamCount()).c_str());

for (int i=0;i<=ParamCount();i++)
{
fprintf(fp,AnsiString(ParamStr(i)+"\n").c_str());
}
fclose(fp);
。。。。
}

郁闷!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
...全文
252 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
yuliwe 2006-01-26
  • 打赏
  • 举报
回复
cb?vb?TStringList->Loadfromfile()行不?
MEFULEU 2006-01-26
  • 打赏
  • 举报
回复
楼上的兄弟,发错地方了吧
lurel 2006-01-25
  • 打赏
  • 举报
回复
坐下学习
MEFULEU 2006-01-23
  • 打赏
  • 举报
回复
兄弟阿,我打击你一下;

我想使用的是封装好的vcl;我正在使用delphi察看为啥没有传递正确;

或者这是vcl的一个bug;你的那个方法确实可行;不过我只是想学点东西!

我调试好了就揭帖!
linkboy2004 2006-01-23
  • 打赏
  • 举报
回复
记得给分啊。我等级太低了。。555
linkboy2004 2006-01-23
  • 打赏
  • 举报
回复
我不是编程高手,不巧却是个小黑。呵呵,给你我的代码,有兴趣多交流。。
e-mail:linkboy2007@yahoo.com.cn

#include <stdio.h>
#include <windows.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);//服务控制函数
void WINAPI CmdStart(void);//要启动的程序函数
BOOL InstallService(); //安装服务的函数
BOOL DeleteService(); //删除服务的函数

int main(int argc, char* argv[])
{
printf("\twindows based service demo\n");
printf("\tgxisone@hotmail.com\n");
if(argc!=3)
{
printf("usage: %s -install[remove]",argv[0]);
return 0;
}
if(strcmp(argv[1],"-install")==0) /// install
{
if(InstallService())
printf("\n\nService Installed Sucessfully\n");
else
printf("\n\nError Installing Service\n");
}
else if(strcmp(argv[1],"-remove")==0) // remove
{
if(DeleteService())
printf("\n\nService remove sucessfully\n");
else
printf("\n\nError removing Service\n");
}
else
{
printf("\nusage: %s -install[remove]\n",argv[0]);
return 0;
}
//在进入点函数里面要完成ServiceMain的初始化,
//准确点说是初始化一个SERVICE_TABLE_ENTRY结构数组,
//这个结构记录了这个服务程序里面所包含的所有服务的名称
//和服务的进入点函数
SERVICE_TABLE_ENTRY
DispatchTable[]={{"WindowsMgr",ServiceMain},{NULL,NULL}};
//最后的NULL指明数组的结束
StartServiceCtrlDispatcher(DispatchTable);
return 0;
}

void WINAPI ServiceMain(DWORD argc, LPTSTR *argv)
{
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("WindowsMgr",ServiceCtrlHandler);
if (m_ServiceStatusHandle == (SERVICE_STATUS_HANDLE)0)return;
m_ServiceStatus.dwCurrentState = SERVICE_RUNNING; //设置服务状态
m_ServiceStatus.dwCheckPoint = 0;
m_ServiceStatus.dwWaitHint = 0;
//SERVICE_STATUS结构含有七个成员,它们反映服务的现行状态。
//所有这些成员必须在这个结构被传递到SetServiceStatus之前正确的设置
SetServiceStatus (m_ServiceStatusHandle, &m_ServiceStatus);
bRunning=true;
//*
CmdStart(); //启动我们的服务程序
//*
return;
}
void WINAPI ServiceCtrlHandler(DWORD Opcode)//服务控制函数
{
switch(Opcode)
{
case SERVICE_CONTROL_PAUSE: // we accept the command to pause it
m_ServiceStatus.dwCurrentState = SERVICE_PAUSED;
break;
case SERVICE_CONTROL_CONTINUE: // we got the command to continue
m_ServiceStatus.dwCurrentState = SERVICE_RUNNING;
break;
case SERVICE_CONTROL_STOP: // we got the command to stop this service
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];
SC_HANDLE schSCManager,schService;
GetCurrentDirectory(1024,strDir);
GetModuleFileName(NULL,strDir,sizeof(strDir));

char chSysPath[1024];
GetSystemDirectory(chSysPath,sizeof(chSysPath));

strcat(chSysPath,"\\WindowsMgr.exe");
if(!CopyFile(strDir,chSysPath,FALSE))printf("Copy file OK\n"); // 把我们的服务程序复制到系统根目录

strcpy(strDir,chSysPath);
schSCManager = OpenSCManager(NULL,NULL,SC_MANAGER_ALL_ACCESS);
if (schSCManager == NULL)
{
printf("open scmanger failed,maybe you do not have the privilage to do this\n");
return false;
}

LPCTSTR lpszBinaryPathName=strDir;

schService = CreateService(schSCManager,"WindowsMgr","Windows Manger Control", //将服务的信息添加到SCM的数据库
SERVICE_ALL_ACCESS, // desired access
SERVICE_WIN32_OWN_PROCESS, // service type
SERVICE_AUTO_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)
{
printf("faint,we failed just because we invoke createservices failed\n");
return false;
}
CloseServiceHandle(schService);
return true;
}
BOOL DeleteService()
{
SC_HANDLE schSCManager;
SC_HANDLE hService;
schSCManager = OpenSCManager(NULL,NULL,SC_MANAGER_ALL_ACCESS);

char chSysPath[1024];
GetSystemDirectory(chSysPath,sizeof(chSysPath));
strcat(chSysPath,"\\WindowsMgr.exe");

if (schSCManager == NULL)
{
printf("faint,open scmanger failed\n");
return false;
}
hService=OpenService(schSCManager,"WindowsMgr",SERVICE_ALL_ACCESS);
if (hService == NULL)
{
printf("faint,open services failt\n");
return false;
}
if(DeleteFile(chSysPath)==0)
{
printf("Dell file Failure !\n");
return false;
}
else printf("Delete file OK!\n");
if(DeleteService(hService)==0)
return false;

if(CloseServiceHandle(hService)==0)
return false;
else
return true;
}

void WINAPI CmdStart(void)
{
//--------------------------------
//把你的要做成服务启动的程序代码添加到这里
//那么你的代码就可以作为NT服务启动了
//--------------------------------
}
jmsting 2006-01-23
  • 打赏
  • 举报
回复
学习一下!
constantine 2006-01-23
  • 打赏
  • 举报
回复
只写过控制服务的,服务程序我不会写
CityHost 2006-01-23
  • 打赏
  • 举报
回复
我来学习的,不发表评论
MEFULEU 2006-01-23
  • 打赏
  • 举报
回复
to:
penu(懒猫·子在川上之再上征程·杀人无心之寓怒于静)


我的服务已经手动停止了;

而且多说一句,我只是创建一个服务后,想开始这个服务;这里就是开始这个服务的语句

启动服务没有问题;问题是参数传递不进去~

````55555555555555~~~~~~~~~~~~
penu 2006-01-22
  • 打赏
  • 举报
回复
LPCTSTR ParamValue[2];
ParamValue[0]="MYService\0";
ParamValue[1]="fun1\0";

scm=OpenSCManager(NULL,NULL,SC_MANAGER_CONNECT);
if (scm!=NULL){
svc=OpenService(scm,"YGService",SERVICE_START);
if (svc!=NULL)
{
// <------这里是否应该插入停止服务语句?
StartService(svc,2,ParamValue);//开始Service
CloseServiceHandle(svc);
}
CloseServiceHandle(scm);
}
MEFULEU 2006-01-20
  • 打赏
  • 举报
回复
看过别人写的,

char *pra[] = {"-service", "\0"};

if (!StartService(newService,1,(const char **)pra))
{
printf("StartService() error = %d\nStart service failure!\n",GetLastError());
}
else
{
printf("Start service Success!\n");
}

}

参照这段程序参数也一样传递不过去!!!!!!!!!!!
MEFULEU 2006-01-20
  • 打赏
  • 举报
回复
%^0^%

在研究一些东西,学习学习嘛!!!!
cczlp 2006-01-20
  • 打赏
  • 举报
回复
MEFULEU又是做Hook又是做服务, 不会真的是黑客程序吧?

13,825

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧