Windows Service Installation using Command Prompt - c#

The only way to install windows-service I know is using "Visual Studio 2010 Command Prompt", Is there a way to install windows-service on a machine which isn't having Visual Studio installed (assume that .Net version 4.X is installed)?

Call to SDK Command prompt, follow
Start>All Programs>Microsoft .NET Framework SDK v2.0>SDK Command prompt
Type in the SDK command prompt
installutil C:\MyWebServiceApp\bin\Debug\MyService.exe
this is your application's .exe path.
Now your Windows service has successfully installed with Windows Environment.
To start that, go to
Start>Run type services.msc and run it.
In this services window, find your Windows Service and Write Click on it and select Properties. Set Startup type as Automatic or Manual.
Now restart you machine and find your Windows Service by Task Manager. It will display in task manager under running services.
Reference here

Try installutil <Path of the Service>
C:\Windows\Microsoft.NET\Framework64\v4.0.30319

you can use batch file and call it from your installer or application
For Installation
#ECHO OFF
REM The following directory is for .NET 4.0
set DOTNETFX4=%SystemRoot%\Microsoft.NET\Framework\v4.0.30319
set PATH=%PATH%;%DOTNETFX4%
echo Installing WindowsService...
echo ---------------------------------------------------
InstallUtil /i YouServiceName.exe
echo ---------------------------------------------------
echo Done.
For Uninstall
#ECHO OFF
REM The following directory is for .NET 4.0
set DOTNETFX4=%SystemRoot%\Microsoft.NET\Framework\v4.0.30319
set PATH=%PATH%;%DOTNETFX4%
echo Installing WindowsService...
echo ---------------------------------------------------
InstallUtil /u YouServiceName.exe
echo ---------------------------------------------------
echo Done.

Related

How to install sudo and mpicc in windows?

I want to run a mpicc code written in C#. But to run the same I'll have to install sudo apt install mpich and to do that I need sudo command in windows cmd window. I tried using git bash and installed gsudo but didn't work. Is there any other way to run my file?
Commands to use to run my file:
mpicc p_mpi.c -o p_mpi
mpirun -np 4 ./p_mpi
Commands I used before using the above and failed:
sudo apt install mpich
winget install gsudo
gsudo apt install mpich
sudo is a linux command for running a program as administrator. It can not be used in windows.
If you are using windows but need to use linux only programs i sugest trying out wsl.
apt is also a program that does not work in windows. It is a program used for installing and updating programs in debian based linux distributions.

Transfer data from msi installer to the installed exe

I am trying to preform silent install to a windows servies via msi file and i want to transfer data at the installation to some config file(text file) that serve the exe windows service that the msi install.
The silent install command that i am executing is :
msiexec /u Installer.msi /q
When the msi installation is finish i call (automatically) to the "after install" event of the project installer and i want to build a txt file with few configuration for the windows service, one of the configuration parameters need to be inserted at the msi like ip address for some server.
Hope you get the idea and what i am struggling with..

Install service to server 2012

I developed new service using .net 4.0 c#, I want now to install to hosting server which does not contain visual studio command promot and installUtil.exe . How can Install the service to the server? It is required to install the VS version ?
Go to "C:\Windows\System32"
Right click on "cmd.exe" and "Run as administrator"
And run "InstallUtil.exe" like that:
"C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe" "C:\src\Service.exe"
The first parameter is the full path of InstallUtil.exe
For 64 bit executables use following:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe
For 32 bit executables use following:
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe
The second parameter is the full path of Service.exe to be installed.
I find the solution :
1- copy 'InstallUtil.exe' file to c: dirve in the server.
2- copy to the service execution file to same place.
3- open command promot in 'administrator mode'(run as admin)
4- write the following command : c:\InstallUtil c:\serviceName.exe
Note : ensure that the service and Installer are both 32-bit or 64-bit
I suggest you a small refactor to implement the whole service using Topshelf and you'll be able to install your Windows services with no additional tool than the service executable itself.
For example, yourexecutable install, yourexecutable uninstall, yourexecutable stop, yourexecutable start...

How to build Windows 8.1 app for Store (appxupload) in PowerShell?

Typically when I want to build Windows 8.1 or Windows Phone 8.1 app for Store I open Visual Studio 2015 and in Solution Explorer I start Store -> Create App Packages.. wizard.
I'd like to be able to produce identical signed .appxupload packages using PowerShell ideally just providing the target project file, target platform(s), build configuration and version number.
There is a page for packaging and deployment, but I just don't know what is the proper command order to use. There must be a simple solution for this standard task, right? Note I got Windows 10 and Visual Studio 2015 Pro installed, so all prerequisites should be there.
And a bonus question, is it possible to run Windows App Certification Kit on this created package as well from PowerShell?
Thanks
After log of digging I found the answer myself.
After associating the Project with Store and building app for Store using the Wizard and saving all changes it's then possible to build the store package again calling just 'msbuild' with the project/solution in a parameter.
I've described it in detail here:
https://www.suchan.cz/2015/09/building-windows-store-appxupload-packages-using-powershell/
These commands work with VS2013 on a W8.1 machine and a W8.1 project. I haven't been able to verify them with VS2015/W10 yet. I suppose they should work, as long as the required W8.1 SDK is installed.
"C:\Program Files (x86)\Windows Kits\8.1\bin\x86\makeappx.exe" pack /d "<BinDirOfProject>" /p "<BindirOfProject>\output\project.appx" /l
"C:\Program Files (x86)\Windows Kits\8.1\bin\x86\makecert.exe" /n "CN=tom" /r /h 0 /eku "1.3.6.1.5.5.7.3.3,1.3.6.1.4.1.311.10.3.13" /e "01/01/2020" /sv "<BinDirOfProject>\output\key.pvk" "<BinDirOfProject>\output\key.cer"
"C:\Program Files (x86)\Windows Kits\8.1\bin\x86\pvk2pfx.exe" /pvk "<BinDirOfProject>\output\key.pvk" /pi "<Pwd>" /spc "<BinDirOfProject>\output\key.cer" /pfx "<BinDirOfProject>\output\key.pfx"
"C:\Program Files (x86)\Windows Kits\8.1\bin\x86\signtool.exe" sign /fd SHA256 /a /f "<BinDirOfProject>\output\key.pfx" /p "<Pwd>" "<BinDirOfProject>\output\project.appx"
certutil -addStore TrustedPeople "<BinDirOfProject>\output\key.cer"
You will be prompted to enter a private-public keypair when creating the certificate (makecert.exe, you can ofcourse use an existing certificate).
<Pwd> is your private key for this certificate.

How to programmatically restart Microsoft Test Agent?

How can I programmatically restart the Microsoft Test Agent that would be equivalent to pressing the Restart button within the Test Agent Status window? I'm willing to go about it any way possible. Batch file, C# app, Powershell, etc.
Note: Since I am running UI tests, I need to run the Test Agent as an "Interactive Process" and not a "Service"
I had the same problem because of QTAgent handles not properly closed after a test execution and succeeded in restarting the agent by doing the following in a batch file:
taskkill /f /im qtagentprocessui.exe
start "" "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\QTAgentProcessUI.exe"
Restarting the agent services did not suffice to close the handles...
Hope this can help.

Categories

Resources