- Create a user-defined service
- Summary
- Steps to create a user-defined service
- Introduction to Windows Service Applications
- Service Applications vs. Other Visual Studio Applications
- Service Lifetime
- Types of Services
- Services and the ServiceController Component
- Requirements
- File and Storage Services Overview
- Role description
- Practical applications
- New and changed functionality
- Data Deduplication
- iSCSI Target Server
- Storage Spaces
- Unified remote management of File and Storage Services in Server Manager
- Windows PowerShell cmdlets for File and Storage Services
Create a user-defined service
This article provides the steps to create a Windows NT user-defined service.
Original product version: В Windows 10 — all editions
Original KB number: В 137890
This article contains information about editing the registry. Before you edit the registry, make sure you understand how to restore it if a problem occurs. For information on how to do this, view the Restoring the Registry or the Restoring a Registry Key online Help topics in Registry Editor.
Summary
The Windows NT Resource Kit provides two utilities that allow you to create a Windows NT user-defined service for Windows NT applications and some 16-bit applications, but not for batch files.
Instrsrv.exe installs and removes system services from Windows NT and Srvany.exe allows any Windows NT application to run as a service.
Steps to create a user-defined service
To create a Windows NT user-defined service, follow these steps:
At an MS-DOS command prompt(running CMD.EXE), type the following command:
where path is the drive and directory of the Windows NT Resource Kit (for example, C:\RESKIT ) and My Service is the name of the service you’re creating.
Example: C:\Program Files\Resource Kit\Instsrv.exe Notepad C:\Program Files\Resource Kit\Srvany.exe
To verify that the service was created correctly, check the registry to verify that the ImagePath value under HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\service name is set to point to SRVANY.EXE. If this is not set correctly, the service will stop shortly after it starts and return an Event ID 7000 (The service name failed to start).
Using Registry Editor incorrectly can cause serious problems that may require you to reinstall your operating system. Microsoft cannot guarantee that problems resulting from the incorrect use of Registry Editor can be solved. Use Registry Editor at your own risk.
For information about how to edit the registry, view the following online Help topics in Registry Editor:
- Changing Keys And Values
- Add and Delete Information in the Registry
- Edit Registry Data
You should back up the registry before you edit it.
Run Registry Editor (Regedt32.exe) and locate the following subkey:
From the Edit menu, select Add Key. Type the following entries, and select OK:
- Key Name: Parameters
- Class:
Select the Parameters key.
From the Edit menu, select Add Value. Type the following entries, and select OK:
- Value Name: Application
- Data Type: REG_SZ
- String:
Close Registry Editor.
By default, a newly created service is configured to run automatically when the system is restarted. To change this setting to Manual, run the Services applet from Control Panel. Then change the Startup value to Manual. A service set to Manual can be started in one of several ways:
From the Services applet in Control Panel
From an MS-DOS command prompt, type the following command:
Use the Sc.exe utility from the Resource Kit. Type the following command from an MS-DOS command prompt:
is the drive and directory of the Windows NT Resource Kit (for example, C:\Reskit ).
Introduction to Windows Service Applications
Microsoft Windows services, formerly known as NT services, enable you to create long-running executable applications that run in their own Windows sessions. These services can be automatically started when the computer boots, can be paused and restarted, and do not show any user interface. These features make services ideal for use on a server or whenever you need long-running functionality that does not interfere with other users who are working on the same computer. You can also run services in the security context of a specific user account that is different from the logged-on user or the default computer account. For more information about services and Windows sessions, see the Windows SDK documentation.
You can easily create services by creating an application that is installed as a service. For example, suppose you want to monitor performance counter data and react to threshold values. You could write a Windows Service application that listens to the performance counter data, deploy the application, and begin collecting and analyzing data.
You create your service as a Microsoft Visual Studio project, defining code within it that controls what commands can be sent to the service and what actions should be taken when those commands are received. Commands that can be sent to a service include starting, pausing, resuming, and stopping the service; you can also execute custom commands.
After you create and build the application, you can install it by running the command-line utility InstallUtil.exe and passing the path to the service’s executable file. You can then use the Services Control Manager to start, stop, pause, resume, and configure your service. You can also accomplish many of these same tasks in the Services node in Server Explorer or by using the ServiceController class.
Service Applications vs. Other Visual Studio Applications
Service applications function differently from many other project types in several ways:
The compiled executable file that a service application project creates must be installed on the server before the project can function in a meaningful way. You cannot debug or run a service application by pressing F5 or F11; you cannot immediately run a service or step into its code. Instead, you must install and start your service, and then attach a debugger to the service’s process. For more information, see How to: Debug Windows Service Applications.
Unlike some types of projects, you must create installation components for service applications. The installation components install and register the service on the server and create an entry for your service with the Windows Services Control Manager. For more information, see How to: Add Installers to Your Service Application.
The Main method for your service application must issue the Run command for the services your project contains. The Run method loads the services into the Services Control Manager on the appropriate server. If you use the Windows Services project template, this method is written for you automatically. Note that loading a service is not the same thing as starting the service. See «Service Lifetime» below for more information.
Windows Service applications run in a different window station than the interactive station of the logged-on user. A window station is a secure object that contains a Clipboard, a set of global atoms, and a group of desktop objects. Because the station of the Windows service is not an interactive station, dialog boxes raised from within a Windows service application will not be seen and may cause your program to stop responding. Similarly, error messages should be logged in the Windows event log rather than raised in the user interface.
The Windows service classes supported by the .NET Framework do not support interaction with interactive stations, that is, the logged-on user. The .NET Framework also does not include classes that represent stations and desktops. If your Windows service must interact with other stations, you will need to access the unmanaged Windows API. For more information, see the Windows SDK documentation.
The interaction of the Windows service with the user or other stations must be carefully designed to include scenarios such as there being no logged on user, or the user having an unexpected set of desktop objects. In some cases, it may be more appropriate to write a Windows application that runs under the control of the user.
Windows service applications run in their own security context and are started before the user logs into the Windows computer on which they are installed. You should plan carefully what user account to run the service within; a service running under the system account has more permissions and privileges than a user account.
Service Lifetime
A service goes through several internal states in its lifetime. First, the service is installed onto the system on which it will run. This process executes the installers for the service project and loads the service into the Services Control Manager for that computer. The Services Control Manager is the central utility provided by Windows to administer services.
After the service has been loaded, it must be started. Starting the service allows it to begin functioning. You can start a service from the Services Control Manager, from Server Explorer, or from code by calling the Start method. The Start method passes processing to the application’s OnStart method and processes any code you have defined there.
A running service can exist in this state indefinitely until it is either stopped or paused or until the computer shuts down. A service can exist in one of three basic states: Running, Paused, or Stopped. The service can also report the state of a pending command: ContinuePending, PausePending, StartPending, or StopPending. These statuses indicate that a command has been issued, such as a command to pause a running service, but has not been carried out yet. You can query the Status to determine what state a service is in, or use the WaitForStatus to carry out an action when any of these states occurs.
You can pause, stop, or resume a service from the Services Control Manager, from Server Explorer, or by calling methods in code. Each of these actions can call an associated procedure in the service (OnStop, OnPause, or OnContinue), in which you can define additional processing to be performed when the service changes state.
Types of Services
There are two types of services you can create in Visual Studio using the .NET Framework. Services that are the only service in a process are assigned the type Win32OwnProcess. Services that share a process with another service are assigned the type Win32ShareProcess. You can retrieve the service type by querying the ServiceType property.
You might occasionally see other service types if you query existing services that were not created in Visual Studio. For more information on these, see the ServiceType.
Services and the ServiceController Component
The ServiceController component is used to connect to an installed service and manipulate its state; using a ServiceController component, you can start and stop a service, pause and continue its functioning, and send custom commands to a service. However, you do not need to use a ServiceController component when you create a service application. In fact, in most cases your ServiceController component should exist in a separate application from the Windows service application that defines your service.
For more information, see ServiceController.
Requirements
Services must be created in a Windows Service application project or another .NET Framework–enabled project that creates an .exe file when built and inherits from the ServiceBase class.
Projects containing Windows services must have installation components for the project and its services. This can be easily accomplished from the Properties window. For more information, see How to: Add Installers to Your Service Application.
File and Storage Services Overview
Applies To: Windows Server 2012 R2, Windows Server 2012
This topic is for Information Technology Professionals (IT Pros) looking for info about servers running the File and Storage Services role in Windows Server 2012 R2 and Windows Server 2012, including what’s new, a list of role services, and where to find evaluation and deployment information. For info about Windows Server 2016, see Storage in Windows Server 2016.
If you’re looking for help with Windows on a PC or tablet instead of a server, see Windows Help.
Did you know that Microsoft Azure provides similar functionality in the cloud? Learn more about Microsoft Azure storage solutions. Create a hybrid storage solution in Microsoft Azure: |
Did you mean…
Role description
File and Storage Services includes technologies that help you set up and manage one or more file servers, which are servers that provide central locations on your network where you can store files and share them with users. If your users need access to the same files and applications, or if centralized backup and file management are important to your organization, you should set up one or more servers as a file server by installing the File and Storage Services role and the appropriate role services.
The File and Storage Services role and the Storage Services role service are installed by default, but without any additional role services. This basic functionality enables you to use Server Manager or Windows PowerShell to manage the storage functionality of your servers. However, to set up or manage a file server, you should use the Add Roles and Features Wizard in Server Manager or the Install-WindowsFeature Windows PowerShell cmdlet to install additional File and Storage Services role services, such as the role services discussed in this topic.
Practical applications
Administrators can use the File and Storage Services role to set up and manage multiple file servers and their storage capabilities by using Server Manager or Windows PowerShell. Some of the specific applications include the following:
Storage Spaces — Use to deploy high availability storage that is resilient and scalable by using cost-effective industry-standard disks.
Folder Redirection, Offline Files, and Roaming User Profiles — Use to redirect the path of local folders (such as the Documents folder) or an entire user profile to a network location, while caching the contents locally for increased speed and availability.
Work Folders — Use to enable users to store and access work files on personal PCs and devices, in addition to corporate PCs. Users gain a convenient location to store work files and access them from anywhere. Organizations maintain control over corporate data by storing the files on centrally managed file servers and optionally specifying user device policies (such as encryption and lock screen passwords). Work Folders is a new role service in Windows Server 2012 R2.
Data Deduplication — Use to reduce the disk space requirements of your files, saving money on storage.
iSCSI Target Server — Use to create centralized, software-based, and hardware-independent iSCSI disk subsystems in storage area networks (SANs).
Server Manager — Use to remotely manage multiple file servers from a single window.
Windows PowerShell Use to automate the management of the majority of administration tasks for file servers.
New and changed functionality
For information about new File and Storage Services functionality in Windows Server 2016, see What’s New in Storage in Windows Server 2016.
The following table describes some of the major changes in File and Storage Services functionality that is available in Windows Server 2012 R2.
Feature/functionality | New or updated? | Description |
---|---|---|
Work Folders | New | Provides a consistent way for users to access their work files from their personal computers and devices. See Work Folders for more information. |
Server Message Block | Updated | Enhancements include automatic rebalancing of Scale-Out File Server clients, improved performance of SMB Direct, and improved SMB event messages. See What’s New in SMB for more information. |
Storage Spaces | Updated | Enhancements include SSD and HDD storage tiers, an SSD-based write-back cache, parity space support for failover clusters, dual parity support, and greatly decreased storage space rebuild times. See What’s New in Storage Spaces for more information. |
DFS Replication | Updated | Enhancements include database cloning for large performance gains during initial sync, a Windows PowerShell module for DFS Replication, a new DFS Replication WMI provider, faster replication on high bandwidth connections, conflict and preexisting data recovery, and support for rebuilding corrupt databases without unexpected data loss. See What’s New in DFS Replication and DFS Namespaces for more information. |
iSCSI Target Server | Updated | Updates include virtual disk enhancements, manageability enhancements in a hosted or private cloud, and improved optimization to allow disk-level caching. See What’s New in iSCSI Target Server for more information. |
The following table describes some of the major changes in File and Storage Services functionality that are available in Windows Server 2012.
Feature/functionality | New or updated? | Description |
---|---|---|
Data Deduplication | New | Saves disk space by storing a single copy of identical data on the volume. |
iSCSI Target Server | New | Provides block storage to other servers and applications on the network by using the Internet SCSI (iSCSI) standard. |
Storage Spaces and storage pools | New | Enables you to virtualize storage by grouping industry-standard disks into storage pools and then creating storage spaces from the available capacity in the storage pools. |
Unified remote management of File and Storage Services in Server Manager | New | Enables you to remotely manage multiple file servers, including their role services and storage, from a single window. |
Windows PowerShell cmdlets for File and Storage Services | New | Provides Windows PowerShell cmdlets to perform the majority of administration tasks for file and storage servers. |
For more information about what else is new in File and Storage Services and related technologies, see the following topics.
Data Deduplication
By using the Data Deduplication role service to reduce the number of duplicate blocks of data in storage, you can store much more data in a given amount of storage capacity than was possible in previous releases that used Single Instance Storage (SIS) or NTFS file system compression. General purpose file servers can typically reduce storage capacity utilization by a 2:1 ratio (for example, files that previously used 1 TB would use 500 GB after data deduplication). Servers that host virtualization data (such as VHD files) often reduce storage capacity utilization by a 20:1 ratio, which reduces 1 TB of data to 50 GB.
Data deduplication is highly scalable, resource efficient, and nonintrusive. It can run on dozens of large volumes of primary data simultaneously without affecting other workloads on the server. Low impact on the server workloads is maintained by throttling the CPU and memory resources that are consumed. By using data deduplication jobs, you can schedule when data deduplication should run, specify the resources to duplicate, and tune file selection. Data integrity and recoverability are maximized through checksum and other algorithms by using selective redundancy.
When combined with BranchCache, the same optimization techniques are applied to data that is transferred over the WAN to a branch office. This results in faster file download times and reduced bandwidth consumption.
What value does this change add?
Data deduplication uses variable-size chunking and compression, which together deliver storage optimization ratios of 2:1 for general file servers and up to 20:1 for virtualization data.
What works differently?
Windows Server 2012 includes Data Deduplication as a role service that you can install and manage by using Server Manager or Windows PowerShell cmdlets. The default settings can quickly reduce the amount of storage capacity that is used by your data. You can fine-tune the settings to see more gains or use Windows PowerShell cmdlets to create scripts that will trigger storage optimization when and where you want it.
For more detailed information, see Data Deduplication.
iSCSI Target Server
iSCSI Target Server provides block storage to other servers and applications on the network by using the Internet SCSI (iSCSI) standard. When combined with other continuously available technologies in Windows Server 2012, iSCSI Target Server provides continuously available storage that was previously available only on expensive, high-end storage area network (SAN) devices.
What value does this change add?
Network or diskless boot By using boot-capable network adapters or a software loader, you can deploy hundreds of diskless servers. With the iSCSI Target Server, the deployment is fast (in Microsoft testing, 256 computers deployed in 34 minutes). By using differencing virtual hard disks, you can save up to 90% of the storage space for the operating system images. This is ideal for large deployments of identical operating system images, such as a server farm that is running Hyper-V or high-performance computing (HPC) clusters.
Server application storage Some applications (for example, Hyper-V and Exchange Server) require block storage, which is raw storage that appears to applications as an unformatted disk, which is ready for direct management by the application. iSCSI Target Server can provide these applications with continuously available block storage. Because the storage is remotely accessible, iSCSI Target Server can also consolidate block storage for central or branch office locations.
Heterogeneous storage iSCSI Target Server supports iSCSI initiators on operating systems other than Windows, making it easy to share storage in a heterogeneous environment.
Dev, test, and demo lab environments With iSCSI Target Server, any computer running Windows Server 2012 can be a network-accessible block storage device. This is useful for testing applications prior to deployment on a SAN storage device.
What works differently?
In Windows Server 2012, iSCSI Target Server management functionality moves from a separate download to part of the Windows Server operating system. You can use Server Manager or Windows PowerShell cmdlets to set up, configure, and manage iSCSI Target Server. Windows Server 2012 also includes changes to the clustering resource model that improve scalability so that more initiators can connect to the target servers.
For more detailed information, see iSCSI Target Server.
Storage Spaces
Storage Spaces is a storage subsystem included in Windows that enables you to group industry-standard disks (such as Serial ATA or Serial Attached SCSI disks) into one or more storage pools, and then create virtual disks known as “storage spaces” from the available capacity in the storage pools. Storage Spaces provides resilient storage virtualization capabilities for business-critical virtual or physical deployments, including deployments on scalable multi-node servers.
After you group physical disks into storage pools, you can create virtual disks from the available capacity without individually managing each physical disk. This aggregation of disks enables you to create high performance, resilient, and cost-effective storage solutions. In Windows Server, you can use storage pools with Storage Spaces or with non-Microsoft storage subsystems, including subsystems that use the SMI-S standard.
What value does this change add?
Storage Spaces reduces administration costs by decreasing the time administrators spend provisioning storage. They also simplify administration tasks, enabling administrators who are not storage professionals to set up and manage resilient and high availability storage. Storage Spaces also saves hardware costs by using industry-standard disks for resilient storage with high availability.
What works differently?
With storage pools, instead of managing each disk individually, you add physical disks to one or more pools and then create virtual disks from the available capacity. You then create volumes on the virtual disks, as if they were physical disks.
Unified remote management of File and Storage Services in Server Manager
The File and Storage Services role in Server Manager enables you to remotely manage multiple file servers from a single window in Windows Server 2012 R2 or Windows Server 2012, including role services and storage. The File and Storage Services page in Server Manager provides the following sections to manage all servers running Windows Server 2012 R2 or Windows Server 2012 that have been added to Server Manager:
Servers Manage basic server functionality on servers running Windows Server 2012 R2, Windows Server 2012, Windows Server 2008 R2, or Windows Server 2008. You can use the Servers page to perform such tasks as restarting servers and launching administrative tools.
Storage Pools Manage storage pools, including the physical disks that make up the pools and virtual disks that are created from available capacity in the pools.
Volumes Manage volumes, including scanning for file system errors, extending volumes, and configuring Data Deduplication.
Shares Manage SMB and NFS shares, including creating new shares and setting up quotas.
iSCSI Virtual Disks Manage iSCSI virtual disks, including creating new iSCSI virtual disks and targets.
What value does this change add?
Managing multiple file servers and file server technologies from a single Server Manager window enables administrators to work more efficiently and get a better overall view of the servers they manage, so managing multiple servers becomes as easy as managing one.
What works differently?
Prior to Windows Server 2012, managing multiple file servers meant using Remote Desktop to connect to each server, or opening multiple instances of the administration console (one per server). In Windows Server 2012 R2 and Windows Server 2012, you can use Server Manager to perform many of the functions that are provided by the following standalone management consoles:
Share and Storage Management
File Server Resource Manager (quotas and assigning folder management properties to file shares)
Microsoft iSCSI Software Target (not available in Windows Server 2012)
Storage Manager for SANs (not available in Windows Server 2012)
In addition to the integrated functionality, you can use the Tools menu in Server Manager to launch administrative tools on any of the managed servers, including DFS Management, File Server Resource Manager, and Services for Network File System (NFS).
Although the File and Storage Services role in Server Manager does not support fully managing servers running Windows Server 2008 R2 or Windows Server 2008, you can add these servers to Server Manager and use the Servers , and All Servers pages to view details about the servers and launch administrative tools. For more information, see Managing Down-Level Windows-based Servers from Server Manager in Windows Server 2012.
Windows PowerShell cmdlets for File and Storage Services
Windows Server 2012 R2 and Windows Server 2012 include Windows PowerShell cmdlets to perform the majority of administration tasks for file and storage servers.
What value does this change add?
Extensive Windows PowerShell cmdlets allow administrators to automate common administration tasks by using Windows PowerShell scripts.
What works differently?
Instead of using a variety of snap-ins or disparate command-line utilities, administrators can manage their servers by using Windows PowerShell cmdlets and scripts. Windows Server 2012 R2 and Windows Server 2012 include Windows PowerShell cmdlets to manage the following file and storage technologies.
DFS Replication (New in Windows Server 2012 R2)