How to delay the start of a specific service in Windows Services? - windows

I would like to delay the automatic start of a specific service, my tomcat client application here, that needs to wait few minutes before being launched so that another machine have enough time to start its own service before (database server here).
Is there any parameter for this in Windows server 2016?

Yes, this can be done for a specific service.
You need to :
First set your tomcat application Startup Type to "Automatic(Delayed Start)" in Services first.
2.Go to your registry and add a registry key named “AutoStartDelay” with type “DWORD (32-bit)” in below location:
HKLM\SYSTEM\CurrentControlSet\services<service name>\AutoStartDelay
3.Modify the value data of AutoStartDelay with decimal. The value indicated is in seconds. For example, the following is for 2 minutes of delay :
4.Save the change in Registry.

This doesn't work on Server 2022. AutoStartDelay is ignored at a service level.

Related

Why windows service not starting in sometimes AWS EC2 micro?

I have created a windows service exe from the python code, it starts when I start it manually in AWS Ec2 instances. Also Starts automatically some time when the ec2 boots up. But sometimes the service will not be stared in the instance, why is it happening some times. For your info I also increased the timeout to service start till 700000 in regedit key. still the service will not start automatically. Why is that happening? can I get some solution for this?
If the service is set to start automatically at boot but it isn't, there should be a record describing the failure in the "System" area in the Event Viewer. Check those logs.
Also, try setting the service's "Startup type" to "Automatic (Delayed Start)". Doing so will delay service startup by a couple of minutes, which may be enough to fix the problem if it is a "race condition" as the system starts.

Windows Azure Virtual Machine with Startup Task

Is there a way to add a (parametrized) Startup task to a Windows Azure Virtual Machine through the API? I need to execute a cmdlet after the machine has been started and the code depends on two parameters that will be different for each machine. I know this could be easily achieved for a Web/Worker role, but could it be done for Virtual Machines, as well?
For first-time runs of a VM, you can inject a startup task via CustomData. This works in both Linux and Windows VMs. You'll just need to properly base-64-encode your file (whether it's text or binary) based on the REST API docs.
CustomData is dropped into a file in a specific location, and you can have code that looks for this file, taking some type of startup action as appropriate:
Windows: %SYSTEMDRIVE%\AzureData\CustomData.bin
Linux: /var/lib/waagent/CustomData
Note: This will be added to the CLI as well (the pull request is already available - not sure if it's in the latest build.
EDIT Yes, customdata is now part of the Azure CLI, as a parameter to azure vm create, so no need to mess with base-64 encoding on your own :
No. currently there is no such feature provided out of the box.
However, given you will deal with VM anyway, you can create an image of your own. You can register a "Startup Task" in RunOnce registry key. And sysprep the OS with this settings.
This way you will basically have a startup task which will be executed when your machine boots for the first time and will not be executed on consequent VM restarts.
Taking parameters into the code for VM is not as easy for Web/Worker Role. For anything you want you have to query the Azure Management API directly. The only properties you can get from code running on an Azure VM are basically the normal OS properties - i.e. host name, host IP Address. You don't even know your cloud service name, nor your Virtual IP Address (this can be discovered via services as whatismyip.net or similar). So my approach would be to put parameters into an Azure Table Storage and use Machine Name as rowKey. So I can store any VM specific values based on VM Name. And my "Startup" task would query the Table storage, providing my host name as rowKey (and some common pattern for Partition Key), so it gets all required settings.
With IaaS Management Studio you can set a startup script that will run when your VM boot.
In summary, it activates remote powershell and run your script remotely when it detects the powershell port is open.
I am the developer of this tool, but I don't really get what you mean by "parametized", in other words you want your script to have access to the VM info ?

How to start automatically and run tomcat 6.0.37 version as a background process on Remote Desktop Server start up?

Currently I am running tomcat 6.0.37 version (64-bit windows) on remote desktop server(OS-Windows2008/64-bit), please help me to find answers for the following questions.
QUESTIONS
Q1) How can I run tomcat 6.0.37 version(64-bit windows) as a background process, after closing the tomcat server command prompt window?
(Note : "Tomcat windows service Installer" is not applicable for my scenario.)
Q2) How to start Tomcat 6.0.37 version(64-bit windows) automatically when remote desktop server(OS-Windows2008/64-bit) starts up and also when remote desktop server(OS-Windows2008/64-bit) gets restarted?
Please help me regarding the above questions with step-by-step procedure and some useful information regarding above questions.
Thanks,
Ashwini
The short version is you can't. The problems you are describing are exactly the type of problems running as a service is meant to solve.
I can't think of any valid reason why a web application couldn't run as a service. I'd challenge the supplier of your application as to why they are making such a claim.
Meanwhile, I'd run Tomcat as a service anyway. If the app needs access to network shares then you'll need to run the service as a domain user with access to those shares and make sure you specify them using the full UNC path rather than mapped drives.
I found the Solution on "How to start automatically and run tomcat 6.0.37 version as a background process on Remote Desktop Server start up?"
Step 1: In Environment Variables, set variable name and variable value as
CATALINA_HOME and C:\Tomcat6
Step 2: Environment Variables, set variable name and variable value as
CATALINA_OPTS and -server -Djava.awt.headless=true -Xms384M -Xmx1536M -XX:MaxPermSize=5750M(according to usage of your RAM size)
Step 3: Once installed tomcat service installer by setting the username = xyz, password= xyz and role=xyz-gui,manager-gui.
Then, in right corner of your desktop screen will get a Tomcat server symbol to start and stop the service. Right click on the icon, choose configure---->Java tab and enter those according to your system RAM.
In Java Options text box:
-Djava.awt.headless=true
-Xms1536M
-Xmx3072M
-XX:MaxPermSize=5750m(according to ur RAM size)
And set the values of:
Initial Memory Pool = 64MB
Maximum memory Pool = 5750(usage of RAM Size)
Thread Stack Size = 256MB
These steps are working perfectly for me. Tomcat service is running successfully without any problems.
Thanks,
Ashwini

Open a JDBC connection in a specific AS400 subsystem

I have a web service that calls some stored procedure on a AS400 via JTOpen.
What I would like to do is that the connections used to call the stored procedures was opened in a specific subsystem with a specific user, instead of qusrwrk/quser as now (default).
I think I can be able to clone the qusrwrk subsystem to make it start with a specific user, but what I cannot figure out is the mechanism to open the connection in the specific subsystem.
I guess there should be a property at connection level to say subsystem=MySubsystem.
But unfortunatly I haven't found that property.
Any hint would be appreciated.
Flavio
Let the system take care of the subsystem the job database server job is started in.
You should just focus on the application (which is what IBM i excels in).
If need be, you can tweak subsystem parameters for QUSRWRK to improve performance by allocating memory, etc.
The system uses a pool of prestarted jobs as described in the FAQ: When I do WRKACTJOB, why is the host server job running under QUSER instead of the profile specified on the AS400 object?
To improve performance, the host server jobs are prestarted jobs running under QUSER. When the Toolbox connects to a host server job in order to perform an API call, run a command, etc, a request is sent from the Toolbox to an available prestarted job. This request includes the user profile specified on the AS400 object that represents the connection. The host server job receives the request and swaps to the specified user profile before it runs the request. The host server itself originally runs under the QUSER profile, so output from the WRKACTJOB command will show the job as being owned by QUSER. However, the job is in fact running under the profile specified on the request. To determine what profile is being used for any given host server job, you can do one of three things:
1. Display the job log for that job and find the message indicating which user profile is used as a result of the swap.
2. Work with the job and display job status attributes to view the current user profile.
3. Use Navigator for i to view all of the server jobs, which will list the current user of each job. You can also use Navigator for i to look at the server jobs being used by a particular user.

On Terminal Server, how does a service start a process in a user's session?

From a Windows Service running on a Terminal Server (in global space), we would like to be able to start up a process running a windows application in a specific user's Terminal Server sessions.
How does one go about doing this?
The Scenerio: the windows service starts at boot time. After the user has logged into a Terminal Server user session, based on some criteria known only to the windows service, the windows service wants to start a process in the user's session running a windows application.
An example: We would like to display a 'Shutdown in 5 minutes' warning to the users. The windows service would detect this condition, and start up a process in each user session that starts the windows app that displays the warning. And, yes, I know there are other ways of displaying a warning dialog, this is the example, what we want to do is much more invasive.
You can use CreateProcessAsUser to do this - but it requires a bit of effort. I believe the following steps are the basic required procedure:
Get the user's session (WTSQuerySessionInformation).
Get a token for that user (WTSQueryUserToken).
Create a duplicate token for your use (DuplicateTokenEx).
Use the token to create an environment block (CreateEnvironmentBlock).
Launch the application with CreateProcessAsUser, using the block above.
You'll also want to make sure to clean up all of the appropriate handles, tokens, etc., after you've launched the process.
Really late reply but maybe somebody will find this helpful.
You can use PsExec to launch an application on a remote (or local) server inside a specified session by using the following command:
psexec \\COMPUTER_NAME -i SESSION_ID APPLICATION_NAME
Where SESSION_ID indicates the session id in which to launch the application.
You will need to know what sessions are active on the server and which session id maps to which user login. The following thread provides a nice code sample for this exact problem: How do you retrieve a list of logged-in/connected users in .NET?
Late reply but in the answer above DuplicateToken is not necessary since WTSQueryUserToken already returns a primary token.

Resources