Start local meteor app after windows boot - windows

A local meteor (1.2) application should get started in the background right after windows has been booted. What are my options to get the job done?

You can use the following steps, if you want to start Meteor automatically when a user logs in:
Create a batch file.
Open the newly created batch file and place the following lines into it:
#echo off
cd "<the path to your Meteor project>"
meteor
timeout /t 10
start "C:\Windows\SystemApps\Microsoft.MicrosoftEdge_8wekyb3d8bbwe" http://localhost:3000
Create a shortcut:
Open the Run window (Win + R).
Open shell:startup (or go to: C:\Users\John Doe\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup).
Copy the shortcut into the folder.
Now, when a user logs in, Meteor should start your project and Microsoft Edge should open http://localhost:3000 after 10 seconds.

Applications cannot run without a user being logged in. So "started in the background right after windows has been booted" is not something that is going to happen. You would need a service for that, and services are not interactive. Assuming that you're talking about the Meteor JS framework, you can't build a service out of that.
If you're talking about starting an application when a user logs in, then you can do that easily by adding a shortcut to the executable to the user's "Startup" folder. On modern versions of Windows, the path would be something like:
C:\Users\UserName\AppData\Local\Microsoft\Windows\Start Menu\Programs\Startup

Related

Windows Linux Subsystem: start Bash Application as a Service

As the title already summarizes:
How can I start a bash-script automatically, when the computer starts - ideally without the need to log in to windows - using the Microsoft Subsystem for Linux's Bash.
At the moment, this isn't supported, because the WSL session manager service will close after the last bash.exe wrapper instance closes. There are a few options, but the absolute simplest one at the moment is to use the run utility from the Xming developer and just add a shortcut to your startup folder (in the start menu) pointing to
run.exe bash.exe -c "/home/user/daemoninit.sh ; /bin/bash". Unfortunately, if your daemon initialization requires root access, for example, something like sshd, you will need to add an exception to sudoers that allows anybody to run the daemon with root privileges.
Also, there are problems getting it to run as a true Windows system service, since each lxss installation is user-specific. Some people have gotten it to run on system startup, but it launches in a separate Windows session for that user and makes it so you can't launch bash.exe in your current user session.

How do I run a windows task without flashing a command prompt box BUT still show a dialog box when I need to?

I creating a scheduled task in windows using windows command prompt:
schtasks /create /sc minute /mo 30 /tn "javadobe" /tr "\Program Files (x86)\BuildingIntelligence\javadobe\node.exe '\Program Files (x86)\BuildingIntelligence\javadobe\index.js'" /RL HIGHEST
Which is telling the command line to run "node index.js" every 30 minutes with the highest running privileges.
In my index.js file, I am checking a remote server for a version number I compare against a local version number. Now when they are the same, a node prompt window flashes briefly on the screen, which is obnoxious, and I would like to stop.
However, when the host server uploads a new version of the software, I show a dialog box asking the user if they want to install the update now or later. I want to keep this functionality.
How can I keep the dialog box popping up but not show the node.js command prompt flashing all the time?
Things I have tried:
I have tried running my script as a service instead of a scheduled task, which keeps the windows command prompt from appearing, but doesn't allow the dialog box to appear to the user (because services run in a different desktop session).
In normal windows command prompt, you can start a program minimized, using
START /MIN [application name]
and so I tried changing my /tr argument to "start node index.js /MIN" but that didn't work.
Thanks a bunch in advance for any help!
Whether or not Windows creates a console window for an application is controlled by the Windows Subsystem specified in the binary image (exe file) — something specified at compile time.
If this is CONSOLE (as node.js is), Windows creates the console window before the application begins executing. In other words, it is impossible to control at runtime whether or not a window appears. If WINDOWS, Windows does not create a console window, as it expects the application to create UI.
You will have to create a custom build of the node.js executable with subsystem WINDOWS.

Is there any way to open the CMD through teamcity so it will open and displayed on the desktop?

I have a batch job that i want to deploy from Teamcity to several servers,
to access several servers i use Winexe tool.
the batch is running but i can't see the session because it's started from teamcity,
but i can see that its running when looking at the process list.
My issue is that sometimes this job is having some errors,
which are being displayed on the cmd window when i run it manualy
but since i'm running it through TeamCity i can't see the CMD window so i can't see the error.
My question is:
Is there any way to open the CMD through teamcity so it will open and displayed on the desktop when i access the server as the same user?
note: bare in mind that i need to deploy it to several servers so i can't install several
agents via ZIP File.
So I found kind of a work-around to solve this problem,
I created a schedule task in windows that will run my batch.
when creating this task you need to set those settings:
1.) Run as: the user name that TeamCity is logging in.
2.) check the Run only if logged on check box.
3.) in the security tab give the user you use full permitions.
In order to run the schedule task you need to run this batch script:
Schtasks.exe /Run /TN name_of_schedule_task

Can't execute .exe with an additional param using the .bat file

I need to run NetBeans 7.4 with an additional param such as --locale en:US.
I have no problems doing this using wingows 7 console like this:
>b:
>cd "Program Files\NetBeans 7.4\bin"
>netbeans64.exe --locale en:US
But this way is very cumbersome. Besides it closes the program itself if I close the console.
So I tryed to make a .bat file with the following content:
#echo off
echo Netbeans
start "netbeans" "b:\Program Files\NetBeans 7.4\bin\netbeans64.exe --locale en:US"
pause
exit
However this solution doesn't work. It tells that it can't find this file. If I remove the param '--locale en:US' it founds it. But it is necessary to use this param.
Something should be changed, but how?
Almost done. Just change where the quotes are placed
start "netbeans" "b:\Program Files\NetBeans 7.4\bin\netbeans64.exe" --locale en:US
And, for the console problem, from netbeans launcher documentation
Default behaviour - parent process console is attached. This means if
netbeans.exe is started from console it is "reused" for output, if
netbeans.exe is started by shortcut no console is created
If option "--console new" is specified netbeans.exe creates new
console for output. This is useful if you want to start NB by
shortcut and you want still see console output or if you need to
start several NB instances with different user dirs. Console window
will have correct icon and corresponding title e.g. netbeans
--userdir d:\test_userdir --console new) so it is easy to distinguish which console belongs to certain NB instance
If option "--console suppress" is specified no output will be written
to console you invoke it from
In this moment i have no access to netbeans installation to test, but it seems there are three ways
Start with --console new so netbeans gets its own console and do not depend on cmd
Start with --console suppress to dettach from console
Create a shortcut to netbeans (with your parameters, of course). If it is necessary to start netbeans from console, start the .lnk file (shortcut) instead of netbeans executable.
As said, i can not try. Maybe this works.

Run batch file as a Windows service

In order to run one application, a batch file has to be kicked off (which does things like start Jetty, display live logs, etc). The application will work only if this batch file is running. I am hence forced to have this batch file running and not logout from the Windows server.
Can this batch file be run as a service? I am experimenting with one of the suggestions from a similar question.
NSSM is totally free and hyper-easy, running command prompt / terminal as administrator:
nssm install "YourCoolServiceNameLabel"
then a dialog will appear so you can choose where is the file you want to run.
to uninstall
nssm remove "YourCoolServiceNameLabel"
There's a built in windows cmd to do this: sc create. Not as fancy as nssm, but you don't have to download an additional piece of software.
sc create "ServiceName" start= demand displayname= "DisplayName" binpath= [path to .bat file]
Note
start=demand means you must start the service yourself. Options include: boot, system, auto, demand, disabled, delayed-auto
whitespace is required after =
I did encounter an error on service start that the service did not respond in a timely manner, but it was clear the service had run the .bat successfully. Haven't dug into this yet but this thread experienced the same thing and solved it using nssm to install the service.
No need for extra software. Use the task scheduler -> create task -> hidden. The checkbox for hidden is in the bottom left corner. Set the task to trigger on login (or whatever condition you like) and choose the task in the actions tab. Running it hidden ensures that the task runs silently in the background like a service.
Note that you must also set the program to run "whether the user is logged in or not" or the program will still run in the foreground.
On Windows 2019 Server, you can run a Minecraft java server with these commands:
sc create minecraft-server DisplayName= "minecraft-server" binpath= "cmd.exe /C C:\Users\Administrator\Desktop\rungui1151.lnk" type= own start= auto
The .lnk file is a standard windows shortcut to a batch file.
--- .bat file begins ---
java -Xmx40960M -Xms40960M -d64 -jar minecraft_server.1.15.1.jar
--- .bat file ends ---
All this because:
service does not know how to start in a folder,
cmd.exe does not know how to start in a folder
Starting the service will produce "timely manner" error, but the log file reveals the server is running.
If you need to shut down the server, just go into task manager and find the server java in background processes and end it, or terminate the server from in the game using the /stop command, or for other programs/servers, use the methods relevant to the server.
As Doug Currie says use RunAsService.
From my past experience you must remember that the Service you generate will
have a completely different set of environment variables
have to be carefully inspected for rights/permissions issues
might cause havoc if it opens dialogs asking for any kind of input
not sure if the last one still applies ... it was one big night mare in a project I worked on some time ago.
While it is not free (but $39), FireDaemon has worked so well for me I have to recommend it. It will run your batch file but has loads of additional and very useful functionality such as scheduling, service up monitoring, GUI or XML based install of services, dependencies, environmental variables and log management.
I started out using FireDaemon to launch JBoss application servers (run.bat) but shortly after realized that the richness of the FireDaemon configuration abilities allowed me to ditch the batch file and recreate the intent of its commands in the FireDaemon service definition.
There's also a SUPER FireDaemon called Trinity which you might want to look at if you have a large number of Windows servers on which to manage this service (or technically, any service).
Since NSSM is no longer maintained, you can consider using WinSW. It has binaries that would work with or without .Net.
Basically you create an XML file and then install it. Here is a sample of a minimal XML:
<service>
<!-- ID of the service. It should be unique across the Windows system-->
<id>myapp</id>
<!-- Path to the executable, which should be started -->
<!-- CAUTION: Don't put arguments here. Use <arguments> instead. -->
<executable>%BASE%\myExecutable.exe</executable>
</service>
And then you can install and start it:
winsw install myapp.xml
winsw start myapp.xml
Install NSSM and run the .bat file as a windows service.
Works as expected
My easest way is using opensource svcbatch (https://github.com/mturk/svcbatch/) as wrapper of CMD(BAT) in sc :
sc create myservice binPath= ""%cd%\svcbatch.exe" myservice.bat"

Resources