📄 myservicewinservice.cpp
字号:
// 这是 VC++ Windows 服务项目的主项目文件
#include "stdafx.h"
#include <string.h>
#include "MyServiceWinService.h"
using namespace MyService;
using namespace System::Text;
//若要安装服务,请键入: "MyService.exe -Install"
int _tmain(int argc, _TCHAR* argv[])
{
if (argc >= 2)
{
if (argv[1][0] == _T('/'))
{
argv[1][0] = _T('-');
}
if (_tcsicmp(argv[1], _T("-Install")) == 0)
{
//使用 InstallUtil.exe 安装此 Windows 服务
String* myargs[] = System::Environment::GetCommandLineArgs();
String* args[] = new String*[myargs->Length - 1];
args[0] = (myargs[0]);
Array::Copy(myargs, 2, args, 1, args->Length - 1);
AppDomain* dom = AppDomain::CreateDomain(S"execDom");
Type* type = __typeof(System::Object);
String* path = type->get_Assembly()->get_Location();
StringBuilder* sb = new StringBuilder(path->Substring(0, path->LastIndexOf(S"\\")));
sb->Append(S"\\InstallUtil.exe");
dom->ExecuteAssembly(sb->ToString(), 0, args);
}
}
else
{
ServiceBase::Run(new MyServiceWinService());
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -