Home > Net >  C # write two service, A service program real-time detection B, prevent B service be malicious to st
C # write two service, A service program real-time detection B, prevent B service be malicious to st

Time:09-22

C # write two service, A service program real-time detection B, prevent B service by malicious stop

A real-time detection B service, if B service to stop, start the service
BOf course, A service must be permanently start

Statement: B program permanently is running in the background, there is no interface

CodePudding user response:

This program is called the watchdog, you use this keyword to Google

CodePudding user response:

Process to protect?

B is permanent and cannot be stopped ah..

Such as zhudongfangyu. Exe this service.. Can't stop unless unload...

You can search.

CodePudding user response:

Service is A monitoring process, it is suggested that using timer, once every 1 minute test, if there is no service B process, immediately restart service B (can invoke the bat batch file, more convenient),
Or, write powershell script detection and restart, monitoring service only execute the script, so has the problem of monitoring process don't need to modify the program, only it is ok to change the script,

CodePudding user response:

refer to the second floor by_ love reply:
process guard?

B is permanent and cannot be stopped ah..

Such as zhudongfangyu. Exe this service.. Can't stop unless unload...

You can search.


On the surface of the bosses, you can't hang a point card brand? You look at the upstairs

CodePudding user response:

Zha? The building Lord, saying, I have deployed at the scene with you this way, you have what problem? This is feasible,

CodePudding user response:

Mutual test, release, service to their respective resource file, the condition judgment, just released to perform
https://www.cnblogs.com/qiaoke/p/10062673.html

CodePudding user response:

refer to the second floor by_ love reply:
process guard?

B is permanent and cannot be stopped ah..

Such as zhudongfangyu. Exe this service.. Can't stop unless unload...

You can search.


I need now is this effect

CodePudding user response:

The
reference rabbit family, 4/f - second brother reply:
, you can't hang a point card to the brand? You look at the upstairs brand


I also want to strength does not allow.

CodePudding user response:

To do well the complex? A service is normal, you need to start your business Another service polling for detection the operating condition of one or more services, hung on the resumption of the service, you only do one thing this testing services, inspection services, hang up is open, the service way, boot on the resumption, deployed in the field of service, no one is very boring, you closed the testing services, instead of it, this is very simple thing, a few hours to fix, haven't finished? If the person at the scene, each leadership make progress, that's not my,

CodePudding user response:

Thank you for your comment, I'll study

CodePudding user response:

Testing services code

 
using System;
using System.Collections.Generic;
Using System.Com ponentModel;
Using System. The Configuration;
Using System. The Data;
Using System. Diagnostics;
using System.IO;
Using System. Linq;
Using System. ServiceProcess;
using System.Text;
Using System. The Threading;
Using System. The Threading. The Tasks;

The namespace StartService
{
Public partial class Service1: ServiceBase
{
//time interval
Private int nSpacingInterval=10000;
Private string filePath=AppDomain. CurrentDomain. BaseDirectory + "\ " + DateTime. Now. The ToString (" yyyy - MM - dd ") + ". TXT ".
Private string [] ServiceNames=null;
CancellationTokenSource cancelTokenSource=new CancellationTokenSource ();

Public Service1 ()
{
InitializeComponent();
}

Protected override void OnStart (string [] args)
{
WriteLog (" inspection service is open ");
NSpacingInterval=the Convert. ToInt32 (ConfigurationManager. AppSettings [" SpacingInterval "]) * 1000;
String strServiceNames=ConfigurationManager. AppSettings [" ServiceNameArr "];
ServiceNames=strServiceNames. Split (', ');

Task. Factory. StartNew (DoWork, cancelTokenSource. Token);
}

Protected override void OnStop ()
{
CancelTokenSource. Cancel ();
CancelTokenSource. The Dispose ();
WriteLog (" inspection service has stopped ");
}

Private void DoWork (object arg)
{
while (! CancelTokenSource. IsCancellationRequested)//Worker thread loop
{
for (int i=0; i {
StartService (ServiceNames [I]);
}
System. Threading. Thread. Sleep (nSpacingInterval);
}
}

///& lt; Summary>
///check and open service
///& lt;/summary>
///& lt; Param name="serviceName" & gt;
Private void StartService (string serviceName)
{
Using (System. ServiceProcess. ServiceController control=new ServiceController (serviceName))
{
If (control. The Status==System. ServiceProcess. ServiceControllerStatus. Stopped)
{
Control. The Start ();
WriteLog (serviceName + "reboot");
}
}
}

//write TXT documents, used for debugging log
Public void WriteLog (string STR)
{
Using (StreamWriter sw=File. AppendText (filePath))
{
Sw. WriteLine (DateTime. Now. The ToString () + ":" + STR);
Sw. Flush ();
}
}

}
}

CodePudding user response:

Thank you for your comment, I'll adjust

CodePudding user response:

Daemon: A guardian B, B to protect A, guarding each other, can be cracked and the green shield security is this line of thinking, but as long as the registry change, can be easily removed two daemons,

CodePudding user response:

C # level is lower, the registry don't have to move, the runtime unloading is finished,

CodePudding user response:

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  •  Tags:  
  • C#
  • Related