重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

Python服务程序代码怎么写-创新互联

本篇内容主要讲解“Python服务程序代码怎么写”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“Python服务程序代码怎么写”吧!

创新互联建站专注于曾都企业网站建设,响应式网站开发,成都做商城网站。曾都网站建设公司,为曾都等地区提供建站服务。全流程按需定制,专业设计,全程项目跟踪,创新互联建站专业和态度为您提供的服务

#include "stdafx.h"


#include
using namespace std;

class CDSvr{
public:
static void ShowHelp(void);
CDSvr(){para=NULL;};
CDSvr(_TCHAR* argv[]);
~CDSvr(){};
void Run();
static bool CreateSvr(_TCHAR* svrname,_TCHAR* path);
static bool DeleteSvr(_TCHAR* svrname);
private:
_TCHAR**    para;
};

CDSvr::CDSvr(_TCHAR* argv[]){
para=argv;
Run();
}

void CDSvr::Run(){

}

void CDSvr::ShowHelp(){
cout<<" [use] "<<<" [svrname] [path] "<<" create the service "<<<" [svrname]"<<" delete   service "<}
bool CDSvr::CreateSvr(_TCHAR *svrname, _TCHAR *path){

SC_HANDLE    sch=::OpenSCManager(NULL,NULL,SC_MANAGER_CREATE_SERVICE);
if( NULL==sch ){
cout<<"openSCManager failed!"<return false;
}

SC_HANDLE sccs=NULL;
if( NULL==(sccs=::CreateService( sch,svrname,svrname,
SERVICE_ALL_ACCESS,
SERVICE_WIN32_OWN_PROCESS|SERVICE_INTERACTIVE_PROCESS,
SERVICE_AUTO_START,SERVICE_ERROR_NORMAL,path,NULL,NULL,NULL,NULL,NULL)
)
){
cout<<"CreateService Error"<::CloseHandle(sch);
::CloseHandle(sccs);
return false;
}
::CloseHandle(sch);
::CloseHandle(sccs);
return true;
}

bool CDSvr::DeleteSvr(_TCHAR *svrname){
SC_HANDLE    sch=::OpenSCManager(NULL,NULL,SC_MANAGER_CREATE_SERVICE);
if( NULL==sch ){
cout<<"openSCManager failed!"<return false;
}
SC_HANDLE    sc=::OpenService(sch,svrname,SERVICE_ALL_ACCESS);
if( NULL==sc ){
cout<<"open services failed!"<::CloseHandle(sch);
::CloseHandle(sc);
return false;
}
if(::DeleteService(sc)){
cout<<"delete "<}else{
cout<<"delete "<}
::CloseHandle(sch);
::CloseHandle(sc);

return true;
};

int _tmain(int argc, _TCHAR* argv[])
{
if( argc<2 ){
CDSvr::ShowHelp();
}else if( argc==2 ){
if(CDSvr::DeleteSvr( argv[argc-1])){
cout<< " DONE !!!"<}else{
cout<< " ERROR!!!"<}
}else if( argc==3 ){
if(CDSvr::CreateSvr(argv[argc-2],argv[argc-1])){
cout<<" DONE!!!"<}else{
cout<<" ERROR!!"<}
}

return 0;
}

到此,相信大家对“Python服务程序代码怎么写”有了更深的了解,不妨来实际操作一番吧!这里是创新互联建站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!


网站名称:Python服务程序代码怎么写-创新互联
浏览路径:http://cqcxhl.com/article/dhshhj.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP