Header Ads Widget

Ticker

6/recent/ticker-posts

Phần mềm NSSM tạo services cho Windows

Sẻ có nhiều bạn sẻ cần đến NSSM để thực hiện vấn đề này đó là Create service on windows vâng key word mà bạn để tìm kiếm trên google là thế, nhưng theo dõi Blog của tớ phải biết thêm nhiều cái thú vị hơn sau hehe, thật ra để tạo Service trên Windows ta đã có sc.exe một chương trình có sẵn của Windows và ta có thể gọi nó ra bằng câu lệnh cmd nhưng đối với mình thì thấy nó cùi mía thế nào ấy nhiều khi sử dụng mà cảm thấy bực ghê nơi…

😅
thế services là gì ? vâng 1 câu hỏi đặt ra cho tất cả các bạn ở đây ??? sẻ mất vài giây để tra Google
sau khi tra mình được kết quả trả về như thế này
Mọi phiên bản Windows của Microsoft đều đi kèm với 1 bộ Services – phần lõi hoạt động bắt buộc trong hệ thống. Phần này có chức năng như những “bánh xe” giúp các phần còn lại của hệ thống gắn kết với nhau và có thể thực hiện các vận hành cơ bản một cách trơn tru.
Ta có thể gọi phần quản lý services ra bằng cách Windows + R và gõ lệnh services.msc 
đây là toàn bộ services của một hệ thống Windows
Ak quên cứ mãi nói đến services ta lại quên mất đi ứng dụng nhân vật chính của ngày hôm nay rồi chính là NSSM một phần mềm của bên thứ 3 tạo ra để thực hiện dễ dàng cho việc tạo 1 services cho hệ thống, có 2 hình thức GUI và cmd 
Download: Link
Sau khi download về bạn vào thư mục NSSM vừa giải nén chọn 64 hay 32 thì còn tùy vào Windows bạn đang sử dụng là loại nào nữa 
GUI thì chắc không cần hướng dẫn đâu nhỉ mình nghĩ các bạn ai IT ai cũng sẻ biết dung GUI mà nhỉ còn nếu bó tay thì cứ liên hệ mình nhưng với điều kiện click vào Quảng Cáo giúp mình hehe
ở đây mình sẻ Show lệnh cmd của nó ra mà thôi các bạn coi tiếp link trực tiếp của nó đi, thật ra CMD thì chỉ có vài thao tác đơn giản nhưng mình khuyên các bạn nên dung GUI vì nó sẻ ổn định hơn cmd, cmd chỉ thích hợp cho các bạn thích viết Bash Shell thôi

Managing services from the command line

nssm's core functionality has always been available from the command line.
Service installationnssm install <servicename>
nssm install <servicename> <program>
nssm install <servicename> <program> [<arguments>]

By default the service's startup directory will be set to the directory containing the program. The startup directory can be overridden after the service has been installed.nssm set <servicename> AppDirectory <path>

Service removalnssm remove
nssm remove <servicename>
nssm remove <servicename> confirm


Service management

As of version 2.22, nssm offers basic service management functionality. nssm will also accept a service displayname anywhere that a servicename is expected, since Windows does not allow a service to have a name or display name which conflicts with either the name or display name of another service. Both the service name (also called the service key name) and its display name uniquely identify a service.
Starting and stopping a servicenssm start <servicename>
nssm stop <servicename>
nssm restart <servicename>

Querying a service's statusnssm status <servicename>

Sending controls to servicesnssm pause <servicename>
nssm continue <servicename>
nssm rotate <servicename>


nssm rotate triggers on-demand rotation for nssm services with I/O redirection and online rotation enabled. nssm accepts user-defined control 128 as a cue to begin output file rotation. Non-nssm services might respond to control 128 in their own way (or ignore it, or crash).
Service editing

As of version 2.22, all parameters understood by nssm can be queried or configured on the command line. A subset of system parameters can also be queried and, in some cases, modified.
General syntax

Parameters can usually be queried as follows.nssm get <servicename> <parameter>

Some parameters are ambiguous and require a subparameter. See below.nssm get <servicename> <parameter> <subparameter>

Parameters can usually be set in a similar way.nssm set <servicename> <parameter> <value>
nssm set <servicename> <parameter> <subparameter> <value>


Most parameters can be reset to their defaults, which is equivalent to removing the associated registry entry.nssm reset <servicename> <parameter>
nssm reset <servicename> <parameter> <subparameter>
As a convenience, nssm will accept additional arguments beyond the value required, and concatenate them together, separated by single spaces. Thus the following two invocations are identical:
nssm set <servicename> AppParameters "-classpath C:\Classes"
nssm set <servicename> AppParameters -classpath C:\Classes

Parameters

A parameter is usually a string with the same name as the registry entry which controls the associated functionality. So, for example, the following command sets the startup directory for a service:nssm set <servicename> AppDirectory <path>

Values
Most parameters are configured by setting the same value as is documented for the associated registry entry. To enable file rotation, for example, you would use the following command:nssm set <servicename> AppRotation 1

See below for a list of parameters whose values are set differently.
Native parameters

Certain parameters configure properties of the service itself rather than the behaviour of nssm. They too are named after their associated registry values.
DependOnGroup: Load order groups whose members must start before the service can start.
DependOnService: Services which must start before the service can start.
Description: The service's description
DisplayName: The service's display name, eg Application Layer Gateway Service. This is the name shown under the Name column in services.msc.
ImagePath: Path to the service executable, eg C:\Windows\System32\alg.exe. For nssm services, this will be the path to nssm.exe.
ObjectName: The name of the user account under which the service runs. The default is LOCALSYSTEM.
Name: The service key name, eg ALG. The key name cannot be changed. You can use nssm get <displayname> Name to find out the key name of a service.
Start: The service's startup type, eg Automatic.
Type: The service type. nssm can only edit services of type SERVICE_WIN32_OWN_PROCESS.

Non-standard parameters
When used with nssm get, AppEnvironment and AppEnvironmentExtra accept an optional subparameter. If no subparameter is given, nssm get will print all configured environment variables, one per line in the form KEY=VALUE. If a subparameter is given, nssm get will print the value configured for the named environment variable, or the empty string if that variable is not present in the environment block.
For example, suppose that AppEnvironmentExtra were configured with two variables, CLASSPATH=C:\Classes and TEMP=C:\Temp. The following invocation:
nssm get <servicename> AppEnvironmentExtra

would print:CLASSPATH=C:\Classes TEMP=C:\Temp
Whereas the syntax below:
nssm get <servicename> AppEnvironmentExtra CLASSPATH

would print:C:\Classes
When setting an environment block with nssm set, each variable should be specified as a KEY=VALUE pair in a separate argument. For example:
nssm set <servicename> AppEnvironmentExtra CLASSPATH=C:\Classes TEMP=C:\Temp

The AppExit parameter requires a subparameter specifying the exit code to get or set. The default action can be specified with the string Default.
For example, to get the default exit action for a service you should run:
nssm get <servicename> AppExit Default
To get the exit action when the application exits with exit code 2, run:
nssm get <servicename> AppExit 2
Note that if no explicit action is configured for a specified exit code, nssm will print the default exit action.
To set configure the service to stop when the application exits with an exit code of 2, run:
nssm set <servicename> AppExit 2 Exit

The AppPriority parameter takes a priority class constant as specified in the SetPriorityClass() documentation. Valid priorities are:

REALTIME_PRIORITY_CLASS
HIGH_PRIORITY_CLASS
ABOVE_NORMAL_PRIORITY_CLASS
NORMAL_PRIORITY_CLASS
BELOW_NORMAL_PRIORITY_CLASS
IDLE_PRIORITY_CLASS 

Non-standard native parameters
When used with nssm set, the DependOnGroup and DependOnService parameters treat each subsequent command line argument as a dependency group or service.
Groups can be specified with or without the SC_GROUP_IDENTIFIER prefix (the + symbol). Services can be specified via their key name or display name.
The following two invocations are equivalent:
nssm set <servicename> DependOnService RpcSS LanmanWorkstation
nssm set <servicename> DependOnService "Remote Procedure Call (RPC)" LanmanWorkstation
Groups will always be prefixed by the SC_GROUP_IDENTIFIER when queried with nssm get.
When used with nssm set, the ObjectName parameter requires an additional argument specifying the password of the user which will run the service.
To retrieve the username, run:

nssm get <servicename> ObjectName
To set the username and password, run:
nssm set <servicename> ObjectName <username> <password>
Note that the rules of argument concatenation still apply. The following invocation will have the expected effect:
nssm set <servicename> ObjectName <username> correct horse battery staple
If you absolutely must configure an account with a blank password, run: nssm set <servicename> ObjectName <username> ""


Valid values for the Start parameter are:

SERVICE_AUTO_START: Automatic startup at boot.
SERVICE_DELAYED_START: Delayed startup at boot.
SERVICE_DEMAND_START: Manual startup.
SERVICE_DISABLED: Service is disabled. Note that SERVICE_DELAYED_START is not supported on versions of Windows prior to  Vista
nssm will set the service to automatic startup if delayed start is unavailable.
The Type parameter is used to query or set the service type. nssm recognises all currently documented service types but will only allow setting one of two types:

SERVICE_WIN32_OWN_PROCESS: A standalone service. This is the default.
SERVICE_INTERACTIVE_PROCESS: A service which can interact with the desktop. A service may only be configured as interactive if it runs under the LOCALSYSTEM account. To guarantee success when attempting to configure an interactive service, run two commands in sequence:
nssm reset <servicename> ObjectName nssm set <servicename> Type SERVICE_INTERACTIVE_PROCESS

    Post a Comment

    1 Comments

    1. Đoạn đầu đọc còn hiểu đoạn sau thì chịu !

      ReplyDelete

    Vài lời muốn nói:
    * Không được nhận xét thô tục bởi mình biết các bạn là những người văn minh.
    * Pass giải nén mặt định là itblognote hoặc itblognote.com nếu có Pass khác thì mình sẽ ghim trong bài viết.
    * Click vào quảng cáo và chia sẻ bài viết để mình có thêm động lực viết bài nhé.