Install a Windows service using a Windows command prompt? - windows-services

I want to install a Windows service using a Windows command prompt (not the Visual Studio command prompt).
How do I do this?

Navigate to the installutil.exe in your .net folder (for .net 4 it's C:\Windows\Microsoft.NET\Framework\v4.0.30319 for example) and use it to install your service, like this:
"C:\Windows\Microsoft.NET\Framework\v4.0.30319\installutil.exe" "c:\myservice.exe"
Regarding a comment, for 64bit apps, use below:
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe

Nothing wrong with SC Create command.
Just you need to know the correct args :
SC CREATE "MySVC" binpath= "D:\Me\Services\MySVC\MySVC.exe"

If the directory's name has a space like c:\program files\abc 123, then you must use double quotes around the path.
installutil.exe "c:\program files\abc 123\myservice.exe"
It makes things much easier if you set up a bat file like following,
e.g. To install a service, create a "myserviceinstaller.bat" and "Run as Administrator"
#echo off
cd C:\Windows\Microsoft.NET\Framework\v4.0.30319
installutil.exe "C:\Services\myservice.exe"
if ERRORLEVEL 1 goto error
exit
:error
echo There was a problem
pause
to uninstall service,
Just add a -u to the installutil command.
cd C:\Windows\Microsoft.NET\Framework\v4.0.30319
C:\Windows\Microsoft.NET\Framework\v4.0.30319\installutil.exe -u "C:\Services\myservice.exe"

Perform the following:
Start up the command prompt (CMD) with administrator rights.
Type c:\windows\microsoft.net\framework\v4.0.30319\installutil.exe [your windows service path to exe]
Press return and that's that!
It's important to open with administrator rights otherwise you may find errors that come up that don't make sense. If you get any, check you've opened it with admin rights first!
To open with admin rights, right click 'Command Prompt' and select 'Run as administrator'.
Source:
http://coderamblings.wordpress.com/2012/07/24/how-to-install-a-windows-service-using-the-command-prompt/

Install Service:-
"C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe"
"C:\Services\myservice.exe"
UnInstall Sevice:-
"C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe" -u "C:\Services\myservice.Service.exe"

Create a *.bat file beside of your windows service exe file for installing with the following context:
CLS
ECHO Installing My Windows Service
START %windir%\Microsoft.NET\Framework\v4.0.30319\installutil.exe "%~d0%~p0\YourWindowsServiceExeName.exe"
Create a *.bat file beside of your windows service exe file for uninstalling with the following context:
CLS
ECHO Uninstalling My Windows Service
START %windir%\Microsoft.NET\Framework\v4.0.30319\installutil.exe -u "%~d0%~p0\YourWindowsServiceExeName.exe"
Run each of bat file as Admin to install or uninstall your windows service.

I must add one more point in this thread. To install/uninstall 64-bit version of assemblies one should use 64-bit version of tool. To install a service, the command should be:
"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe"
"C:\YourFolder\YourService.exe"
and to uninstall the command should be:
"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe" -u
"C:\YourFolder\YourService.exe"

Run Windows Command Prompt as Administrator
paste this code: cd C:\Windows\Microsoft.NET\Framework\v4.0.30319\ to go to folder
edit and run this too: installutil C:\ProjectFolder\bin\Debug\MyProject.exe
Note: To uninstall: installutil /u C:\ProjectFolder\bin\Debug\MyProject.exe

open Developer command prompt as Admin and navigate to
cd C:\Windows\Microsoft.NET\Framework\v4.0.30319
Now use path where is your .exe there
InstallUtil "D:\backup\WindowsService\WindowsService1\WindowsService1\obj\Debug\TestService.exe"

Open Visual studio and select new project by selecting Windows Service template in Windows Desktop tab. Than copy following code into your service_name.cs file.
using System.Diagnostics;
using System.ServiceProcess;
namespace TimerService
{
public partial class Timer_Service : ServiceBase
{
public Timer_Service()
{
InitializeComponent();
}
static void Main()
{
if (System.Diagnostics.Debugger.IsAttached)
{
Timer_Service service = new Timer_Service();
service.OnStart(null);
}
else
{
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new Timer_Service()
};
ServiceBase.Run(ServicesToRun);
}
}
protected override void OnStart(string[] args)
{
EventLog.WriteEvent("Timer_Service", new EventInstance(0, 0, EventLogEntryType.Information), new string[] { "Service start successfully." });
}
protected override void OnStop()
{
EventLog.WriteEvent("Timer_Service", new EventInstance(0, 0, EventLogEntryType.Information), new string[] { "Service stop successfully." });
}
}
}
Right-Click on service_name.cs file and open designer of service. than right-click and select Add Installer. than right-click on serviceProcessInstaller1 and change its property value of Account from User to Local System.
Remove static void main method from Program.cs file.
Than save and Build your project.
NOTE: goto bin\Ddebug folder of your project folder. Than open Properties of your service_name.exe file. Than goto Compatibility tab. Than click on Change Settings For All Users.
Select option Run this program as an administrator.
Now, You have to open CommandPromt as Administrator.
After open, set directory to where your InstallUtil.exe file is placed.
for ex: C:\Windows\Microsoft.NET\Framework64\v4.0.30319.
now write the following command:
C:\Windows\Microsoft.NET\Framework64\v4.0.30319>InstallUtil.exe -i C:\TimerService\TimerService\bin\Debug\TimerService.exe
Note: -i is for install he service and -u for Unsinstall.
after -i set the write the path where you want to install your service.
now write the command in CommandPromt as follows:
C:\TimerService\TimerService\bin\Debug>net start service_name
Note: use stop for stop the Service.
Now, open ViewEventLog.exe. Select Windows Logs>Application. There you can check your Service's log by start and stop the service.

the following code , install and uninstall the Service,
Open the command prompt and run the program as an administrator and fire the below command and press enter.
Syntax
To Install
C:\windows\microsoft.net\framework\v4.0.30319>InstallUtil.exe + Your copied path + \your service name + .exe
eg :Our Path
InstallUtil.exe C:\MyFirstService\bin\Debug\MyFirstService.exe
To uninstall
C:\windows\microsoft.net\framework\v4.0.30319>InstallUtil.exe -u + Your copied path + \your service name + .exe
eg : Our path InstallUtil.exe -u C:\MyFirstService\bin\Debug\MyFirstService.exe
for more help you can see the following link: sample program

If you are using Powershell and you want to install .NET service you can use Install-Service module. It is a wrapper for InstalUtil tool.
It exposes 3 commands
Install-Service - invokesĀ InstallUtil.exe pathToExecutable command
Install-ServiceIfNotInstalled - first it checks if service is
installed if not perform the method Install-Service
Uninstall-Service- it uninstalls service. ServiceName of path to executable can be used.
Code to this module can be viewed here

start up the command prompt (CMD) with administrator rights.
Type c:\windows\microsoft.net\framework\v4.0.30319\installutil.exe [your windows service path to exe]
Press return

1.From the Start menu, select the Visual Studio directory, then select Developer Command Prompt for VS .
2.The Developer Command Prompt for Visual Studio appears.
3.Access the directory where your project's compiled executable file is located.
4.Run InstallUtil.exe from the command prompt with your project's executable as a parameter

when your assembly version and your Visual studio project Biuld setting on dot net 2 or 4 install with same version.
install service with installutil that same version
if build in dot net 4
Type c:\windows\microsoft.net\framework\v4.0.30319\installutil.exe
if build in dot net 2
Type c:\windows\microsoft.net\framework\v2.0.11319\installutil.exe

Follow these steps when deploying the Windows Service, don't lose time:
Run command prompt by the Admin right
Insure about release mode when compilling in your IDE
Give a type to your project installer on design view
Select authentication type in accordance the case
Insure about software dependencies: If you are using a certificate install it correctly
Go your console write this:
C:\Windows\Microsoft.NET\Framework\yourRecentVersion\installutil.exe c:\yourservice.exe
there is a hidden -i argument before the exe path -i c:\ you can use -u for uninstallling
Look your .exe path to seem log file. You can use event viewer to observing in the feature

you can do using command prompt and write:
C:\windows\microsoft.net\framework\v4.0.30319\InstallUtil.exe -i ".EXE file of window service"

You can use InstallUtil to install any windows service.
1: C:\Windows\Microsoft.NET\Framework64\v4.0.30319 in command prompt running as Adminstrator.
2: Copy the Exe path and type InstallUtil.exe "your exe path"
and hit enter.
If you want visual elaboration. Goto below link.
It helped me alot.
https://youtu.be/yrdyYxzI7SE

You should open command prompt, go to
C:\windows\microsoft.net\framework\v4.0.30319\InstallUtil.exe -i ".EXE file of window service"

Open command prompt as administrator, go to your Folder where your .exe resides.
To Install Exe as service
D:\YourFolderName\YourExeName /i
To uninstall use /u.

Related

Windows is not recognizing serverless as internal or external command

I wanted to install serverless in my windows 7 machine.My npm version is 6.1.0.
I used the command
npm install -g serverless
C:\Users\ADMIN\AppData\Roaming\npm\serverless -> C:\Users\ADMIN\AppData\Roaming\npm\node_modules\serverless\bin\serverless
C:\Users\ADMIN\AppData\Roaming\npm\slss -> C:\Users\ADMIN\AppData\Roaming\npm\node_modules\serverless\bin\serverless
C:\Users\ADMIN\AppData\Roaming\npm\sls -> C:\Users\ADMIN\AppData\Roaming\npm\node_modules\serverless\bin\serverless
> spawn-sync#1.0.15 postinstall C:\Users\ADMIN\AppData\Roaming\npm\node_modules\serverless\node_modules\spawn-sync
> node postinstall
> serverless#1.30.1 postinstall C:\Users\ADMIN\AppData\Roaming\npm\node_modules\serverless
> node ./scripts/postinstall.js
+ serverless#1.30.1
added 351 packages from 269 contributors in 154.064s
But when I type serverless in command prompt, it tells me
'serverless' is not recognized as an internal or external command,
operable program or batch file.
I had the same issue and I believe you are missing the npm path from your environment variables.
Go to Windows search and type:
"Edit the system environment variables"
(at least this is how you can find the Environment Variables in Windows 10).
Go to Advanced tab and click on Environment Variables.
Select Path from the User Variables and click Edit.
Click New and provide the following:
C:\Users[USER_NAME]\AppData\Roaming\npm\
or whatever is the path that you have installed npm - just change the [USER_NAME] with your username account.
Else you could navigate to the path above and execute "serverless" from inside that path.
Hope that helps :)
Try make use of npx
Example:
npx sls deploy
I had the same issue. In my Windows 10 system, I wanted to install serverless under Git Bash.
I was able to install serverless with the normal account just fine, but then the serverless command was not found (even after closing Git Bash and launching it again). After doing the same steps using Administrator privileges, everything worked fine even using the normal user account. Perhaps this will help someone.
^^Adding both environment paths, to npm and serverless/bin, worked for me. Same issue. Windows 10, trying to start a Serverless project after it seemingly installed correctly.
Going to it from /npm also worked, but the adding both environment paths was the permanent solution by #Suday Ghosh
Go to System Window (Control Panel\System and Security\System);
Click "Advanced System Settings"
Click "Environment Variables"
Select "Path" variables and click "Edit" Button
Under "Edit environment variable" window, Click "New" Button
Provide the following paths separately:
C:\Users[USER_NAME]\AppData\Roaming\npm\
AND
C:\Users[USER_NAME]\AppData\Roaming\npm\node_modules\serverless\bin
Happy !!!!!!

How to update your surge.sh project?

I deployed a surge.sh project and it was published successfully, however, I want to make some updates to the project, the updates have been applied locally and can be seen working but it tried to publish it to the same domain again yet it doesn't appear updated. I also tried to tear down the project and re-upload it still it shows the old project, I cleared the cache too but it still didn't update. Any idea why?
To update a project you just need to publish it again to the same domain.
You can do this quickly by creating a file called CNAME in the project root directory to set the default domain name, like this:
echo site-name.surge.sh >CNAME
Then each time to update:
surge .
Alternatively, without a CNAME file, specify the domain in the surge command like this:
surge --domain site-name.surge.sh .
See https://surge.sh/help/remembering-a-domain .
This will not solve the need to tear down and republish the site described in the original post, but if you're not having that problem, it will make it quick to update your surge.sh project, as per the title question, without the need to edit the domain the usual prompt.
Open Git Bash.
Switch to the project directory.
Type surge and click Enter.
Click Enter in line "project".
Enter URL of your project in line "domain" and click Enter.
That's it!
Use the following deploy script to update your deployed Surge Project
"deploy": "surge --project ./path_to_build_folder --domain custom-domain.surge.sh"
Just go to your project folder, use cd to select your project directory, then type npm run build , then change directory to build directory cd build and then use surge
Edit:
Example \
You need go to your project directory, in my case it's jamming
$ cd ../
King#DESKTOP-5ERNS17 MINGW64 ~/Documents/Projects/jamming (main)
$ pwd
/c/Users/King/Documents/Projects/jamming
King#DESKTOP-5ERNS17 MINGW64 ~/Documents/Projects/jamming (main)
Then you do npm run build, I guess you need to update the build.
King#DESKTOP-5ERNS17 MINGW64 ~/Documents/Projects/jamming (main)
$ npm run build
Once the build is compiled, go in to the build directory by using cd build and then do surge
King#DESKTOP-5ERNS17 MINGW64 ~/Documents/Projects/jamming (main)
$ cd build
King#DESKTOP-5ERNS17 MINGW64 ~/Documents/Projects/jamming/build
$ surge
That's how it worked with me. If I don't do npm run build before the surge just won't update it... I don't know if this is the right way...
To update your Surge project, simply run surge in the project directory and input the same domain you're already using in the domain: prompt.
Some users are describing a problem where they have to do a hard refresh to see their updates. This is to be expected, and happens with any static file host, since static files are cached by your browser to make page loads faster.
So to see the latest version of your Surge site, press Ctrl+Shift+J or F12 to open the developer tools, and right-click on the reload button in the browser's unibar, and click on Empty Cache and Hard Reload.
Open Cmd.
Switch to the project directory.
Type surge . and click Enter.
and change the random domain with your web that's want to update and hit enter.
That's it <3
Go to the directory project and use git or cmd and this structure:
type surge and hit enter
hit enter in project line
replace the random domain with your web url
hit enter

How to install mongodb in windows7 64x and how to use with ROR

I want to install mongodb in windows 7(64x) and use with ruby on rails what i do first and how?
download mongodb itself
Extract the archive to C:\ by right clicking on the archive and
selecting Extract All and browsing to C:.
Example: C:\mongodb-win32-x86_64-[version]
Start the Command Prompt by selecting the Start Menu, then
All Programs, then Accessories, then right click Command Prompt, and select Run as Administrator from the popup menu. In
the Command Prompt, issue the following commands:
cd \
move C:\mongodb-win32-* C:\mongodb
MongoDB requires a data folder to store its files. The default
location for the MongoDB data directory is C:\data\db. Create this
folder using the Command Prompt. Issue the following command
sequence:
md data
md data\db
Start MongoDB To start MongoDB, execute from the Command Prompt:
C:\mongodb\bin\mongod.exe
source

Hudson build server install as a windows service error

Problem
I am trying to install hudson build server on a windows server through remote desktop connection. I path to the Hudson folder in the C:\Hudson. The Hudson directory contains a folder called Home and the hudson.war file.
I tried to start it up using the following commands:
set JAVA_HOME=C:\Java\jdk1.6.0_20
set HUDSON_HOME=C:\Hudson\Home
java -jar C:\Hudson\hudson.war
Then I can navigate to http://localhost:8080 in internet explorer.
Question
When I try to use the Install as Windows Service function on the web interface, I get this error:
Installing a service
[Home] $ C:\Hudson\Home\hudson.exe install
WMI.WmiException: AccessDenied
at WMI.WmiRoot.BaseHandler.CheckError(ManagementBaseObject result)
at WMI.WmiRoot.ClassHandler.Invoke(Object proxy, MethodInfo method, Object[] args)
at WMI.Win32ServicesProxy.Create(String , String , String , ServiceType , ErrorControl , StartMode , Boolean , String[] )
at winsw.WrapperService.Run(String[] args)
at winsw.WrapperService.Main(String[] args)`
Why can't I install as a windows service and how can I fix this issue?
Answer
Found the solution.
When running the commands you need to open the command prompt by right clicking and selecting "run as administrator".
On the windows command prompt, execute: sc delete hudson
and for jenkins user, execute: sc delete jenkins
and then run install windows as a service.
Hope it helps :)
Try turning off User Account Control; that's what fixed it for me. Start > Run > UAC, then drag the dial to the lowest setting: "Never notify". May require a reboot.

How can I delete a service in Windows?

I have a couple old services that I want to completely uninstall. How can I do this?
Use the SC command, like this (you need to be on a command prompt to execute the commands in this post):
SC STOP shortservicename
SC DELETE shortservicename
Note: You need to run the command prompt as an administrator, not just logged in as the administrator, but also with administrative rights. If you get errors above about not having the necessary access rights to stop and/or delete the service, run the command prompt as an administrator. You can do this by searching for the command prompt on your start menu and then right-clicking and selecting "Run as administrator". Note to PowerShell users: sc is aliased to set-content. So sc delete service will actually create a file called delete with the content service. To do this in Powershell, use sc.exe delete service instead
If you need to find the short service name of a service, use the following command to generate a text file containing a list of services and their statuses:
SC QUERY state= all >"C:\Service List.txt"
For a more concise list, execute this command:
SC QUERY state= all | FIND "_NAME"
The short service name will be listed just above the display name, like this:
SERVICE_NAME: MyService
DISPLAY_NAME: My Special Service
And thus to delete that service:
SC STOP MyService
SC DELETE MyService
Click Start | Run and type regedit in the Open: line. Click OK.
Navigate to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services
Scroll down the left pane, locate the service name, right click it and select Delete.
Reboot the system.
As described above I executed:
sc delete ServiceName
However this didn't work as I was executing it from PowerShell.
When using PowerShell you must specify the full path to sc.exe because PowerShell has a default alias for sc assigning it to Set-Content. Since it's a valid command it doesn't actually show an error message.
To resolve this I executed it as follows:
C:\Windows\System32\sc.exe delete ServiceName
Use services.msc or (Start > Control Panel > Administrative Tools > Services) to find the service in question. Double-click to see the service name and the path to the executable.
Check the exe version information for a clue as to the owner of the service, and use Add/Remove programs to do a clean uninstall if possible.
Failing that, from the command prompt:
sc stop servicexyz
sc delete servicexyz
No restart should be required.
SC DELETE "service name"
Run the command on cmd as Administrator otherwise you will get this error :-
openservice failed 5 access is denied
If you have Windows Vista or above please run this from a command prompt as Administrator:
sc delete [your service name as shown in service.msc e.g moneytransfer]
For example: sc delete moneytransfer
Delete the folder C:\Program Files\BBRTL\moneytransfer\
Find moneytransfer registry keys and delete them:
HKEY_CLASSES_ROOT\Installer\Products\
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall\
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\EventLog\
HKEY_LOCAL_MACHINE\System\CurrentControlSet002\Services\
HKEY_LOCAL_MACHINE\System\CurrentControlSet002\Services\EventLog\
HKEY_LOCAL_MACHINE\Software\Classes\Installer\Assemblies\ [remove .exe references]
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Installer\Folders
These steps have been tested on Windows XP, Windows 7, Windows Vista, Windows Server 2003, and Windows Server 2008.
We can do it in two different ways
Remove Windows Service via Registry
Its very easy to remove a service from registry if you know the right path. Here is how I did that:
Run Regedit or Regedt32
Go to the registry entry "HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services"
Look for the service that you want delete and delete it. You can look at the keys to know what files the service was using and delete them as well (if necessary).
Delete Windows Service via Command Window
Alternatively, you can also use command prompt and delete a service using following command:
sc delete
You can also create service by using following command
sc create "MorganTechService" binpath= "C:\Program Files\MorganTechSPace\myservice.exe"
Note: You may have to reboot the system to get the list updated in service manager.
If they are .NET created services you can use the installutil.exe with the /u switch
its in the .net framework folder like
C:\Windows\Microsoft.NET\Framework64\v2.0.50727
This did the job for me on Windows 10:
start the cmd.exe as admin
run SC DELETE "com.docker.service"
reinstall docker
Here is a vbs script that was passed down to me:
Set servicelist = GetObject("winmgmts:").InstancesOf ("Win32_Service")
for each service in servicelist
sname = lcase(service.name)
If sname = "NameOfMyService" Then
msgbox(sname)
service.delete ' the internal name of your service
end if
next
sc delete name
Before removing the service you should review the dependencies.
You can check it:
Open services.msc and find the service name, switch to the "Dependencies" tab.
Source: http://www.sysadmit.com/2016/03/windows-eliminar-un-servicio.html
You can use my small service list editor utility Service Manager
You can choose any service > Modify > Delete. Method works immediately, no reboot required.
Executable file: [Download]
Source code: [Download]
Blog post: [BlogLink]
Service editor class: WinServiceUtils.cs
For me my service that I created had to be uninstalled in Control Panel > Programs and Features

Resources