快上网专注成都网站设计 成都网站制作 成都网站建设
成都网站建设公司服务热线:028-86922220

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

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://6mz.cn/article/dhshhj.html

其他资讯