Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Windows Server 2016-Command Line Management of Windows Services

2025-02-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

Microsoft Windows services (formerly known as NT services) allow users to create executable applications that can run for a long time in their own Windows sessions. These services can be started automatically when the computer starts, can be paused and restarted, and do not display any user interface. These features make the service ideal for use on the server, or for features that need to be run for a long time (without affecting other users working on the same computer). You can also run the service in the security context of a specific user account that is different from the logged-in user or the default computer account.

This example introduces three general methods, involving Net under DOS, SC under Powershell and get/start/stop/set/new/restart/resume-service under Powershell.

1.net command method:

C:\ > net /? The syntax of this command is: NET [ACCOUNTS | COMPUTER | CONFIG | CONTINUE | FILE | GROUP | HELP | HELPMSG | LOCALGROUP | PAUSE | SESSION | SHARE | START | STATISTICS | STOP | TIME | USE | USER | VIEW] C:\ > format: when to start and shut down the service. The syntax is: net start service name net stop service name

Example: check the status of Server service:

Example: stop & start the service:

2.sc command method:

C:\ > sc /? Description: SC is a command line program used to communicate with service control managers and services. Usage: sc [command] [service name]. The format of the option is "\\ ServerName" to get more help about the command by typing the following command: the "sc [command]" command: query- queries the status of the service, or enumerates the status of the service type. Queryex- queries the extended status of the service, or enumerates the status of the service type. Start- starts the service. Pause- sends a PAUSE control request to the service. Interrogate- sends an INTERROGATE control request to the service. Continue- sends a CONTINUE control request to the service. Stop- sends an STOP request to the service. Config- changes the configuration of the service (permanent). Description- changes the description of the service. The action performed by the service when the failure- change fails. Failureflag- changes the failed operation flag for the service. Sidtype- changes the service SID type of the service. Privs- changes the required privileges for the service. Managedaccount-- changes the service to mark the service account password for LSA management. Qc- queries the configuration information of the service. Description of the qdescription---- query service. The action performed by the service when the qfailure- query fails. The failed operation flag for the qfailureflag---- query service. Service SID type of the qsidtype- query service. The required privileges for the qprivs- query service. Trigger parameters for the qtriggerinfo---- query service. The preferred NUMA node for the qpreferrednode-- query service. The qmanagedaccount- query service uses accounts in conjunction with passwords managed by LSA. Qprotection- queries the process protection level of the service. Quserservice---- queries the local instance of the user service template. Delete-(from the registry) removes the service. Create- creates the service (and adds it to the registry). Control- sends control to the service. Sdshow- displays the security descriptor for the service. Sdset- sets the security descriptor for the service. Showsid- displays the service SID string corresponding to any name. Trigger parameters for the triggerinfo- configuration service. Preferrednode--- sets the preferred NUMA node for the service. GetDisplayName-- gets the DisplayName of the service. GetKeyName- gets the ServiceKeyName of the service. EnumDepend- enumerates service dependencies. The following command does not require a service name: sc boot- (ok | bad) indicates whether the last startup should be saved as the last known correct startup configuration Lock- lock service database QueryLock- query SCManager database LockStatus example: sc start MyServiceQUERY and QUERYEX select Item: if the query command is accompanied by the service name The status of the service will be returned. Other options are not suitable for this situation. If the query command takes no parameters or one of the following options, this service is enumerated. Type= the type of service to enumerate (driver, service, userservice, all) (default = service) state= the state of the service to enumerate (inactive All) (default = active) size of bufsize= enumeration buffer (in bytes) (default = 4096) recovery index number for ri= start enumeration (default = 0) group= service groups to enumerate (default = all groups) syntax example sc query-enumerate the state of active services and drivers Sc query eventlog-display the status of the eventlog service sc queryex eventlog-display the extended status of the eventlog service sc query type= driver-enumerate only the active driver sc query type= service-enumerate only the Win32 service sc query state= all-enumerate all services and drivers sc query bufsize= 50-enumerate buffer 50 bytes sc query ri= 14-restore index when enumerated = 14sc queryex group= " "- enumerate active services sc query type= interact that are not in the group-enumerate all inactive service sc query type= driver group= NDIS-enumerate all NDIS drivers SC is a command line program for communicating with service control managers and services Its syntax is: sc config service name start= demand / / manual sc config service name start= auto / / automatic sc config service name start= disabled / / disable sc start service name enable service sc stop service name stop service sc query service name view service status sc delete service name delete service sc qc service name view service configuration information sc create scname binPath=xxxxxx.exe create service

Example: view the properties of server service:

Example: stop & start the service:

3.powershell command method:

PS C:\ > help *-service*Name Category Module Synopsis---- Resume-Service Cmdlet Microsoft.PowerShell.M... Resume-Service...Restart-Service Cmdlet Microsoft.PowerShell.M... Restart-Service...Set-Service Cmdlet Microsoft.PowerShell.M... Set-Service...Get-Service Cmdlet Microsoft.PowerShell.M... Get-Service...Suspend-Service Cmdlet Microsoft.PowerShell.M... Suspend-Service...Start-Service Cmdlet Microsoft.PowerShell.M... Start-Service...Stop-Service Cmdlet Microsoft.PowerShell.M... Stop-Service...New-Service Cmdlet Microsoft.PowerShell.M... New-Service...Get-Service [[- Name]] [- DependentServices] [- RequiredServices] [- Include] [- Exclude] [] Get-Service [- DependentServices] [- RequiredServices]-DisplayName [- Include] [- Exclude] [] Get-Service [- DependentServices] [- RequiredServices] [- Include] [- Exclude] [- InputObject] [] description: Fetch-Service cmdlet get representative computer Includes service objects that run and stop the service. You can indicate that this cmdlet only gets a specific service by specifying the name of the service or the display name of the service, or you can pass the service object to this cmdlet. 1: get all services on your computer Get-Service this command gets all services on your computer. It behaves as Get-Service * as you typed it. The default display displays the status, service name, and display name of each service. 2: get services that begin with a search string Get-Service "wmi*" this command retrieves services whose names begin with WMI (acronym for Windows Management Instrumentation). 3: display services containing search strings Get-Service-Displayname "* network*" this command displays services with a display name containing the word network. Even if the service name does not contain "Net" (for example, xmlprov, network configuration service), the search display name looks for network-related services. 4: get services starting with search string and exclusion Get-Service-Name "win*"-Exclude "WinRM" except for WinRM services, these commands only get services whose names begin with win. 5: show currently active services Get-Service | Where-Object {$_. Status-eq "Running"} this command shows only currently active services. It uses Get-Service cmdlet to get all the services on the computer. The pipe operator (|) passes the result to Where-Object cmdlet, which selects only services whose Status attribute is equal to Running. The state is just an attribute of the service object. To view all properties, type Get-Service | Get-Member. 6: get the service's dependent service Get-Service "WinRM"-RequiredServices this command gets the services required by the WinRM service. This command returns the value of the ServicesDependedOn property of the service. 9: get the service "WinRM" through the pipe operator | Get-Service this command gets the WinRM service on the local computer. This example shows that you can pass a service name string (enclosed in quotation marks) to Get-Service. You can also reference Get-Service through its built-in alias "gsv". This cmdlet can display services only if the current user has the right to view them. If this cmdlet does not display services, you may not have permission to view them. To find the service name and display name for each service on the system, type Get-Service. The service name is displayed in the name column and the display name is displayed in the DisplayName column. When you sort by status value in ascending order, the stopped service appears before the running service. The Status property of the service is an enumerated value, where the name of the state represents an integer value. Sorting is based on integer values, not names. "running" appears before stopped because the value of stopped is "1" and the value of "running" is "4".

Example: check the service status:

Example: shut down the service & start the service:

Note:

Start-Service, start the service. Stop-Service, stop the service. Restart-Service, restart the service. Suspend-Service, suspend / suspend service.

Resume-Service, continue to serve. Set-Service, set the properties of the service. New-Service, create a new service. Use it in a similar way.

Welcome to the official account of Wechat: Xiao Wen study Society.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report