Run a project as a Windows service
Your IWS project can be configured to run under Windows services.
Microsoft Windows services, formerly known as NT services, allow you to create long-running programs that run in their own Windows sessions. These sessions can be automatically started when the computer starts up, 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, please refer to the Microsoft Developer Network (MSDN) Library.
- To ensure that your project always runs with whatever system privileges it needs, regardless of the privileges of the user that is currently logged on to Windows;
- To prevent the user from interfering with your project while it is running; or
- To let your project keep running when there is no user logged on at all.
Create and configure the Windows service
Also, to perform these actions, you must be logged on as a user with Administrator privileges and you should know how to use the Computer Management console. (To access the console, right-click the Computer icon, and then click Manage on the shortcut menu.)
There are two ways to create and configure the Windows service for your project: you can use the Service Configuration tool in the IWS development environment, or you can use the command-line utility that is installed with the InduSoft Web Studio software.
Service Configuration Tool
- Application
- The location of the project file (projectname.app) that the service will load and run when it is started. This must be a complete file path. Use the browse button (…) to find and select the project file on your computer.
- User
- The Windows user account under which the service will run. This is an optional setting; if it is not used, then the service will run under Local System.
Note: Try to avoid running the service under Local System. That account has too much privilege to the file system and too little privilege to run the OPC Client and Server modules properly. The best alternative is to create a user solely to run IWS and configure its privileges to fit the needs of your project. For more about this, see “Configuring User Privileges” below.
- Password
- The password for the specified user account. This is an optional setting; it is not needed if no user is specified or if the specified user does not have a password.
- Startup Type
- How the Windows service will start. The following options are available:
- Automatic: The service will start automatically when the computer starts up.
- Manual: The service can be started manually in the Computer Management console or by clicking Start, as described below.
- Disabled: The service will be created and then disabled. It cannot run until a user with Administrator privileges enables it in the Computer Management console.
- Action pane
- Start or stop the service. Please note that these buttons are not enabled until the service is actually created.
Creating a New Service
- Next to the Project box, click … to open a standard Windows file browser. Use the browser to find and select your project file.
- In the User and Password boxes, type the username and password (if any) for the Windows user account under which the service will run.
- Select a Startup Type.
- Click Apply. The service is created with the specified settings.
After the service has been created, it will appear in the Services console (Start > Control Panel > System and Security > Administrative Tools > Services) under the name “InduSoft Web Studio“. You can use that console to quickly stop and restart the service, if you do not want to run the IWS development application.
Command-line Utility
You can also configure the service by using the command-line utility, StdSvcInst.exe. It offers a few more options than the Service Configuration tool described above — such as specifying a name and description for the service — and it can be used without running the IWS development application. The utility is located in the Bin folder of your IWS program directory. To run the utility, open a command prompt, navigate to the Bin folder (C:Program FilesInduSoft Web Studio v7.1Bin), and then enter the command with the desired parameters.
StdSvcInst { -create -app filepath -startup { auto | manual | disabled } -user username -password password -name displayname -descr description | -start | -stop | -delete }
- -create
- Creates the Windows service.
- -app filepath
- Specifies which project file (projectname.app) the service will load and run when it is started. (This is the same as the Project box in the Service Configuration dialog.) You must include the complete file path, and it must be enclosed in quotes.
This parameter is required when you create a new service.
- -startup { auto | manual | disabled }
- Specifies how the service will start. (This is the same as the Startup Type in the Service Configuration box.) This parameter is optional; if it is not used, then the default behavior for a new service is manual.
- -user username
- Specifies the Window user account under which the service will run. (This is the same as the User box in the Service Configuration dialog.) This parameter is optional; if it is not used, then the service will run under Local System.
- -password password
- Specifies the password for the given user account. (This is the same as the Password box in the Service Configuration dialog described above.) This parameter is optional; it is not needed if no user is specified or if the specified user does not have a password.
- -name displayname
- Defines the service name that is displayed in the Computer Management console. The name must be enclosed in quotes. This parameter is optional; the default name is “Studio”.
- -descr description
- Defines the service description that is displayed in the Computer Management console. The description must be enclosed in quotes. This parameter is optional.
- -start
- Starts the service. This is the same as starting the service using the Computer Management console or by clicking Start in the Service Configuration dialog.
- -stop
- Stops the service. This is the same as stopping the service using the Computer Management console or by clicking Stop in the Service Configuration dialog.
- -delete
- Deletes the service.
Example: Creating the Service
IWS Project File | C:UsersusernameDocumentsInduSoft Web Studio v7.1 Projectsprojectnameprojectname.app |
Startup Mode | Automatic |
User | IWS |
Password | IWS |
Service Name | “InduSoft Web Studio“ |
Service Description | “Starts IWS project” |
Note that the system must already have a user account named “IWS” with password “IWS“.
- Make sure you are logged on as a user with Administrator privileges.
- Open a command prompt ( ).
- Navigate to the Bin folder:
cd "C:Program FilesInduSoft Web Studio v7.1Bin"
- Enter the command:
StdSvcInst –create –app "C:UsersusernameDocumentsInduSoft Web Studio v7.1 Projectsprojectnameprojectname.app" -startup auto –user IWS -password IWS –name "InduSoft Web Studio" –descr "Starts IWS project"
If the procedure is successful, then the system will display the message Service created. Otherwise, it will display an error message.
Example: Changing the Project File
- Make sure you are logged on as a user with Administrator privileges.
- Stop the service if it is running.
- Open a command prompt.
- Navigate to the Bin folder.
- Enter the command — for example, to set MyProject as the project file:
StdSvcInst –app "C:UsersusernameDocumentsInduSoft Web Studio v7.1 ProjectsMyProjectMyProject.app"
Example: Deleting the Service
- Make sure you are logged on as a user with Administrator privileges.
- Stop the service if it is running.
- Open a command prompt.
- Navigate to the Bin folder.
- Enter the command:
StdSvcInst –delete
Configure user privileges
The service will run under the privileges of the user account specified in the User field of the Service Configuration tool (or by the -user parameter of the command-line utility). If IWS needs some system resource to which that account does not have privileges, it will fail. Therefore, you must configure the account to have the necessary privileges.
Enabling the User Account to Log On as a Service
- Open the Local Security Settings console ( ).
- In the console window, select the User Rights Assignment folder ( ).
- In the list of policies, double-click Log on as a service.
The Log on as a service dialog box is displayed.
- Click Add User or Group.
The Select Users or Groups dialog is displayed.
- Type the name of the user account under which you want the service to run.
- Click OK.
Giving the User Account Full Control Over the Project Folder
- In Windows Explorer, locate your IWS project folder (i.e., the folder that contains the file projectname.APP).
- Right-click the folder, and then click Properties on the shortcut menu.
- In the properties sheet, click the Security tab, and then click Edit.
- In the Permissions dialog box, click Add, and then add the user account that you specified when you created the service.
- Select the user that you added, and then in the list of permissions, set Full Control to Allow.
- Click OK to apply your changes and close the dialog, and then click OK again to close the properties sheet.
Allowing the User Account to Run the OPC Client/Server Module
- Open the Component Services console (Start > Control Panel > System and Security > Administrative Tools > Component Services).
- In the console window, select the DCOM Config folder ( ).
- In the DCOM Config pane, right-click Studio Scada OPC Server, and then click Properties on the shortcut menu.
- In the properties sheet, click the Identity tab.
- Select This user and then complete the fields with the same username and password that you specified when you created the service.
- Click OK to apply your changes and close the properties sheet.
- Close the Component Services console.
Troubleshooting
When you run your IWS project as a Windows service, it has no user interface. Therefore, if an error occurs, it will only be logged as a Windows application event. You can check the messages by using the Event Viewer console ( ).