ServiceMain

[Win32] 服务程序开发(1)基本概念和服务程序的框架 一。服务程序基本概念 二。服务程序的编写框架 1。StartServiceCtrlDispatcher函数 BOOL WINAPI StartServiceCtrlDispatcher( _In_ const SERVICE_TABLE_ENTRY *lpServiceTable ); 函数功能:连接到服务控制管理器 参数:一个SERVICE_TABLE_ENTRY结构的指针 阅读详情

ServiceMain

A ServiceMain function is the starting point for a service.

The LPSERVICE_MAIN_FUNCTION type defines a pointer to this callback function. ServiceMain is a placeholder for an application-defined function name.

VOID WINAPI ServiceMain(
  DWORD dwArgc,
  LPTSTR* lpszArgv
);
Parameters
dwArgc
[in] Number of arguments in the lpszArgv array.
lpszArgv
[in] Pointer to an array of pointers to null-terminated argument strings. The first argument in the array is the name of the service, and subsequent arguments are any strings passed to the service by the process that called the StartService function to start the service.
Return Values

This function does not return a value.

Remarks

A service program can start one or more services. A service process has a SERVICE_TABLE_ENTRY structure for each service that it can start. The structure specifies the service name and a pointer to the ServiceMain function for that service.

When the service control manager receives a request to start a service, it starts the service process (if it is not already running). The main thread of the service process calls the StartServiceCtrlDispatcher function with a pointer to an array of SERVICE_TABLE_ENTRY structures. Then the service control manager sends a start request to the service control dispatcher for this service process. The service control dispatcher creates a new thread to execute the ServiceMain function of the service being started.

The ServiceMain function should immediately call the RegisterServiceCtrlHandlerEx function to specify a HandlerEx function to handle control requests. Next, it should call the SetServiceStatus function to send status information to the service control manager. After these calls, the function should complete the initialization of the service. Do not attempt to start another service in the ServiceMain function.

The Service Control Manager (SCM) waits until the service reports a status of SERVICE_RUNNING. It is recommended that the service reports this status as quickly as possible, as other components in the system that require interaction with SCM will be blocked during this time. Some functions may require interaction with the SCM either directly or indirectly.

The SCM locks the service control database during initialization, so if a service attempts to call StartService during initialization, the call will block. When the service reports to the SCM that it has successfully started, it can call StartService. If the service requires another service to be running, the service should set the required dependencies.

Furthermore, you should not call any system functions during service initialization. The service code should call system functions only after it reports a status of SERVICE_RUNNING.

The ServiceMain function should call the RegisterWaitForSingleObject function on an event and exit. This will terminate the thread that is running the ServiceMain function, but will not terminate the service. The service control handler should signal this event when the service stops. A thread from the thread pool will execute the code that performs the cleanup and calls SetServiceStatus with SERVICE_STOPPED.

Windows NT:  On earlier platforms where RegisterWaitForSingleObject is not available, it is common practice for the thread executing the ServiceMain function to wait on an event that is signaled by the service control handler when the service stops. When the event is signaled, ServiceMain itself performs any cleanup and calls SetServiceStatus with SERVICE_STOPPED.

Example Code

For an example, see Writing a ServiceMain Function.

Requirements
ClientRequires Windows XP, Windows 2000 Professional, or Windows NT Workstation.
ServerRequires Windows Server 2003, Windows 2000 Server, or Windows NT Server.
Header

Declared in Winsvc.h; include Windows.h.

修改_ServiceMain__函数的名字.rar 立即下载

相关推荐

HDMI接口技术解析:从基础到应用

本文深入解析HDMI接口技术,从其发展历程、物理结构到传输原理,全面剖析HDMI如何成为影音传输的主流标准。通过对比不同版本的带宽升级和实际应用案例,展示HDMI在4K/8K视频传输中的卓越性能,并分享硬件设计中的实战经验与避坑指南。

weixin_30485379的博客 372

VC++ Service编程(四)服务ServiceMain函数

服务ServiceMain函数     当一个服务控制程序请求开启一个新的服务时,SCM(服务控制管理器)开启服务的同时,向控制调度器发送一个开始请求。控制调度器为服务创建一个新的线程来运行ServiceMain函数。     ServiceMain函数应该执行下面的这些任务:     1、立刻为服务调用RegisterServiceCtrlHandlerEx函数,用来注册一个处理控

Wang Shen 5359

LSTM模型股价波动率预测(含Python代码)

源代码文件可在gzh’finance褪黑素'回复【24012203】获取。

celiaweiwei的博客 3776

服务的ServiceMain函数

当服务控制程序请求运行新服务时,服务控制管理器(SCM)启动服务并向控制调度程序发送启动请求。控制调度程序创建一个新线程来执行服务的ServiceMain功能。 ServiceMain函数应执行以下任务: 初始化所有全局变量。 立即调用RegisterServiceCtrlHandler函数以注册Handler函数来处理服务的控制请求。RegisterServiceCtrlHa...

xinqingwuji的博客 3763

channel || channelGroup || ctx.writeAndFlush()发送字符串消息客户端接收不到的原因

一、原因 网络上传播的数据都是字节(二进制数据)类型。我们如果直接向网络流里面写入一个对象(如:String对象),是无法传输的。只有将对象序列化(转换为可以传输的字节类型)之后,才可以进行传输。所以问题的根源就很清楚了,需要把字符串转换成字节进行传输。、 二、解决办法 1、手动序列化 服务端: channelGroup.writeAndFlush(Unpooled.copiedBuffer("【客户端】"+remoteAddress+"已下线"+format.format(new Date()), Cha

haohaoxuexiyai的博客 4060

SAP 系统中的数字签名解决方案及应用案例分析

在当前企业信息化及数字化转型的大背景下,数据安全与身份认证显得尤为重要。数字签名技术作为保障数据真实性和完整性的重要手段,在 SAP 系统中得到了广泛应用。本文将详细探讨 SAP 系统中部分应用场景如何利用数字签名技术满足业务需求,涵盖 SAP Single Sign-On、质量管理、过程工业生产计划以及 SAP ArchiveLink 内容服务器等方面,力求通过深入解读,帮助读者更好地理解和应用这一关键技术。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 529

调试dll中的ServiceMain函数

调试dll中的导出函数ServiceMain 1、ServiceMain一般是被服务进程调用执行的,创建服务,启动起来之后,被执行,可以按调试服务的方式调试 2、直接rundll32.exe ServiceMain也行 打开OD,打开文件 C:\Windows\System32\rundll32.exe ,输入参数 C:\1.dll ServiceMain dll文件路径 导出函数名称 r...

weixin_46953583的博客 1419

SpringAI系列 - MCP篇(二) - MCP Server Boot Starter

此处需注意之前的。

罗小爬的技术宝书 1321

c语言编写系统服务程序,C语言Windows服务程序编写-ServiceMain

C语言编写的Windows服务程序,可以类比Linux/Unix环境下的daemon进程。一下是VS2010环境下的demo:// windows_service.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include #include #define SLEEP_TIME 5000 /*间隔时间*/#d...

weixin_34832594的博客 875

Spatial-ORMLLM: Improve Spatial Relation Understanding in the Operating Room with Multimodal Larg...

手术室(OR)中的精准空间建模是众多临床任务的基础,可为术中感知、风险规避及手术决策提供支持。现有方法虽利用大规模多模态数据集进行 latent 空间对齐,以隐式学习空间关系,但却忽视了多模态大型语言模型(MLLM)的3D能力。然而,这种方法存在两个问题:1)手术室通常缺乏多台视频和音频传感器,多模态3D数据难以获取;2)仅依赖易获取的2D数据训练,无法捕捉复杂场景中的细粒度细节。为解决这一问题,我们提出——首个针对手术室3D空间推理的大型视觉语言模型。

UnknownBody_2的博客 592

星敏感器:卫星姿态测量的“星空导航仪”

在卫星、航天器和深空探测器的姿态控制系统中,星敏感器(Star Tracker) 是最精确的姿态测量设备之一。它通过识别恒星的位置,计算出航天器在惯性空间中的三轴姿态,精度可达 角秒级(arcsecond),是许多高精度任务(如遥感、天文观测、深空探测)的核心传感器。

ScilogyHunter的博客 3703

Windows服务的ServiceMain函数

当服务控制程序请求运行新服务时,服务控制管理器(SCM)启动服务并向控制调度程序发送启动请求。控制调度程序创建一个新线程来执行服务的ServiceMain功能。有关示例,请参阅编写ServiceMain函数。 ServiceMain函数应执行以下任务: 1、初始化所有全局变量。2、立即调用RegisterServiceCtrlHandler函数以注册Handler函数来处理服务的控制请求。 R...

xinqingwuji的博客 3523

手把手教你学simulink(16.10)-- 基于Simulink的IIR滤波器(Infinite Impulse Response Filter)项目

基于Simulink的IIR滤波器(Infinite Impulse Response Filter)项目的详细实例介绍。这个项目将重点放在IIR滤波器的设计、实现和仿真上,帮助你理解和应用IIR滤波器在信号处理中的作用。

MHD0815的博客 706

ServiceMain、StartServiceCtrlDispatcher

VOID WINAPI ServiceMain(     DWORD dwArgc,     LPTSTR* lpszArgv); 服务主函数的参数与main函数的参数使用方法类似,但是服务主函数的参数不是通过在命令启动时设定的,而是通过SCM的相关API进行传递的(StartService函数)       SCM要对服务进行管理,就必须知道服务程序的服务主函数。服务程序通过调用Sta

bsx881220的专栏 1737

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Writing a ServiceMain Function

Writing a ServiceMain FunctionThe MyServiceStart function in the following example is the ServiceMain function for the service. MyServiceStart has access to the command-line arguments, in the way that

小发猫 1197

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

工作日志--servicemain编译

servicemain的编译折腾了很久,写个日志记一下,以后好学习。 要编译servicemain要先编译ace,然后编译servernet 1、目录结构  bin linux bin.debug.Linux.i686  存放编译后的so和bin结果,编译ace后,要将libACE.so复制到这个目录,否则编译servernet时链接找不到函数 build linux   有Make

download_73的专栏 466

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

C语言Windows服务程序编写-ServiceMain

C语言编写的Windows服务程序,可以类比Linux/Unix环境下的daemon进程。       一下是VS2010环境下的demo: // windows_service.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include #include #define SLEEP_TIME 5000

super_bert的专栏 3328

TERMSRV : Not Personal Workstation--termsrv.dll两个有效起始断点termsrv!DllMain和termsrv!ServiceMain

rpcss is running.TERMSRV : Not Personal Workstation--termsrv.dll两个有效起始断点termsrv!DllMain和termsrv!ServiceMain

linux-0.11调试教程 511

VC++ Service编程(二)编写ServiceMain函数

编写ServiceMain函数     下面例子中的MyServiceStart函数是这个服务的ServiceMain函数。MyServiceStart函数可以使用命令行参数,就像控制台程序中main函数那样的方式。第一个参数是传递给服务的值的个数,并且这个个数的最小值总是1。第二个参数是一个字符数组指针。数组的第一项总是当前服务的名称。     MyServiceStart函数首先填充一个S

Wang Shen 2357

写一个ServiceMain函数

SvcMain函数首先调用RegisterServiceCtrlHandler函数来注册SvcCtrlHandler函数作为服务的Handler函数,然后开始初始化。RegisterSreviceCtrlHandler是在ServiceMain中第一个必须返回成功的函数,之后服务能够使用该函数返回的状态去调用SetServiceStatus函数设置状态,若发生错误,则状态设为SERVICE_STOPPED。

x-2010的笔记 3185

termsrv!ServiceMain函数里面的termsrv!InitializeSystemTrace函数分析

termsrv!ServiceMain函数里面的termsrv!InitializeSystemTrace函数分析

linux-0.11调试教程 406

Windows服务进程的创建

Windows服务进程的创建

tangaowen的专栏 5156

C++ windows 服务

http://www.2cto.com/kf/201111/111990.html 最近因为工作需要,得开发windows服务程序,网上找的大部分教程都是一样的,但是缺少ServiceMain函数的内容,转载某位大神的。这两天想学习关于如何编写windows服务程序的知识,就上网查了些资料。看了一篇文章《用C 语言编写Windows 服务程序的五个步骤》。但可能由于译者的疏忽,忘记了将关键代码放入该

Mr_LeeY的博客 1932

Windows下c语言read,C语言编写Windows服务程序详解-Read.PDF

C语言编写Windows服务程序详解-Read.PDFC 语言编写 Windows 服务程序详解一:Main 函数1:代码参考#include #include #define SLEEP_TIME 5000#define LOGFILE "C:\\MyServices\\memstatus.txt"void main(){SERVICE_TABLE_ENTRY ServiceTable[2];S...

weixin_29095049的博客 302

服务的代理

2019独角兽企业重金招聘Python工程师标准>>> ...

weixin_33755554的博客 102
上一篇: RegisterServiceCtrlHandlerEx
下一篇: SetServiceStatus
普通网友
博客等级 码龄22年 1万+粉丝 3156原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值