I installed a Windows Service under an account type user in service installer. When I try to start it from service lists I can't find it. If I change the account type to local service in the installer then I can find it. I need to built it under a user account. How to solve this?
save this text to a batch file(.bat) and run in the sample folder with your window service
#ECHO OFF
ECHO -----------------------------------------------------------------------------------------
ECHO ------------------------------ Auto Install Windows Service -----------------------------
ECHO -----------------------------------------------------------------------------------------
ECHO --- Typing the path of Windows Service need to install
#SET /p serviceName=
IF NOT "%serviceName%" == "" (
ECHO --- Installing "%serviceName%"
ECHO -------------------------------------------------------------------------------------
C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil %serviceName% -i
net start yourservicename
ECHO -------------------------------------------------------------------------------------
PAUSE
)
Sometimes this happen when you install the service and the List Service Window is open. just install the service with the service windows close, sound silly but it works.
Related
Good evening, I have been working on the project that has got a web app, api, a few libraries and some Azure functions. When I run only Azure function on its own it works just fine but today I noticed that when I select Multiple startup projects in VS2022 and run all project at once they are all running fine but my azure function is giving me error "No connection could be made because the target machine actively refused it.). In the console output I can see that the emulator starts whenever I start a Visual Studio however after selecting multiple projects I see the message "Stopping Azure Storage Azurite emulator..." I tried to restart Visual Studio but whenever I select it, it stops. Why is it stopping, is there any way how can I prevent stopping it? Thanks
As the default config uses ports of Blob, Queue and Table Services were 127.0.0.1:10000, 10001, 10002.
Make Sure no other processes listening on the Azure Storage Emulator Ports.
How to check if any ports are in use:
Open the AzureStorageEmulator.exe.config from the path C:\Program Files (x86)\Microsoft SDKs\Azure\Storage Emulator in a text editor.
From an administrator command prompt run these commands:
netstat -p tcp -ano | findstr :10000
netstat -p tcp -ano | findstr :10001
netstat -p tcp -ano | findstr :10002
You need to stop if any process is using the above ports or reconfigure the ports in the AzureStorageEmulator.exe.config file in order to be the port not being used by any other application.
Again, Run the Command Prompt as Admin > navigate to the above path (Storage Emulator Path) > Run the Command: AzureStorageEmulator.exe init
The storage emulator was successfully initialized and is ready to use - this message you will see if command runs successfully,
If the init command is not successful, check the error details and also the status of Azure Storage Emulator by running this command:
C:\Program Files (x86)\Microsoft SDKs\Azure\Storage Emulator>AzureStorageEmulator.exe status
It should show IsRunning: True
If above steps didn't work, then check the Application Event log for any errors by going to the Event Viewer (available on Start button Search).
Try to Delete/Reinstall the Azurite or Azure Storage Emulator.
Please check these references for more information:
Run automated tests by using Azurite
Azurite Emulator
Azurite
If the accepted answer doesn't solve your problem, this worked for me:
Find the Visual Studio option
Projects and Solutions->Service Dependencies->Auto stop local services
and set it to False:
I created a worker service in .net core 6 like example here and deployed it in Centos. its unit is like
[Unit]
Description=my test app
[Service]
Type=notify
ExecStart=/usr/bin/DaneshAfzar
[Install]
WantedBy=multi-user.target
systemctl start DaneshAfzar.service raises an error : Job for DaneshAfzar.service failed because the control process exited with error code. see "systemctl status DaneshAfzar.service" and "journalctl -xe" for details
output of journalctl -xe :
Failed at step EXEC spawning /usr/bin/DaneshAfzar: Permission Denied
I used chmod 777 for the whole directory but error persists.
Let's asume the service ist called myservice. I think it is better to deploy your .net service to the /opt/myservice directory or to /usr/local/myservice .
Then the structure would look like this:
# Folder path
/opt/myservice
# path of the executable
/opt/myservice/myservice
# or
/opt/myservice/myservice.dll
only the file /opt/myservice/myservice.dll must be executable
A service file then could be like this:
[Unit]
Description=IG Render Service
[Service]
WorkingDirectory=/opt/myservice
ExecStart=/usr/bin/dotnet myservice.dll
Restart=always
# Restart service after 10 seconds if the dotnet service crashes:
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=myservice
# Optionaly define a specific user to run the service
# User=someuser
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false
[Install]
WantedBy=multi-user.target
hope this helps.
I have created self-hosted WCF service using Console application. I have created msi using Installshield but when I am installing setup it will stuck and after some time failed to setup.
I have added log in code and found that on the line of hosting WCF service it was going to stuck and throw an error.
Any Idea how can I resolve this issue?
Service Install: Can you install and run it manually? You must install with admin rights, if you specify a user account to run the service it must have the "log on as a service" privilege (check by running secpol.msc or see here), the file you install must actually be a proper service - obviously - I sometimes mix up my test executables with the service binary. Ever forget? Happens to me :-).
Logging: Get yourself a proper log file first of all:
msiexec.exe /i "Setup.msi" /L*V "C:\Setup.log"
Or in silent mode:
msiexec.exe /i "Setup.msi" /QN /L*V "C:\Setup.log"
Some more information on Logging:
Installsite.org on logging
Event logging, etc...
Interpreting MSI log files, etc...
Credentials: Just adding that there are several built-in accounts you can use to run the service:
The difference between the 'Local System' account and the 'Network Service' account?
And there is the new concept of "managed service accounts". Step-by-Step.
And finally "group managed service account".
I am looking for an approach to develop a MS Office (Excel, Word, PowerPoint, etc.) addin. The addin is required to be written in C# or C/C++ and deployable in which end users can install it without administrator privilege.
There are a few working example such as Think-cell and Eikon. But I don't know how they archived it.
After some research, I'm aware of the following ways to create an add-in, but none of them does not meet the requirement.
1. Use Visual Studio Tools for Office (VSTO)
It seems that installing a VSTO plugin does not require admin rights, but it needs VSTO runtime to be installed and the runtime installer requires admin rights.
2. Implement the IDTExensibility2 interface
In this case, the DLL can be placed in somewhere like C:\Users\myuser\AppData\ without admin rights, but eventually the DLL must be
registered under HKEY_CLASSES_ROOT as a normal COM, and
registered under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\(PowerPoint|Excel|Word|Outlook|etc.)\Addins.
Here, the problem is the first registration requires admin rights.
So, is there any other ways to develop an office addin that does not require admin rights when installed, like Think-Cell and Eikon?
Note: I am OK with using .NET as recent Windows 8/10 has .NET runtime pre-installed. But it seems that .NET is not required, as seen in Think-cell and Eikon, to create an addin that does not require admin rights when installed.
This is a good question which I needed to answer myself. My solution was a small batch script which copies the files to a user-accessible directory (under the %appdata% directory) and puts all infos into the registry afterwards. Please note: With the reg command you can write into the registry without admin rights (as long as it is in HKCU). In order to provide the right path into the registry key it locates the target directory and puts it into the registry file instead of the placeholder.
So let me just give you the code which I used for my software SlideFab as a kind of backup installer if no admin rights were available. This script might not be pretty and has no error handling but it works.
#echo off
echo ___________________________________________________________
echo Welcome to the SlideFab installer batch
echo ___________________________________________________________
echo This batch will install SlideFab 2 for the active user only
echo No system files will be touched
echo ___________________________________________________________
echo IMPORTANT: Do not run this install batch from the zip file
echo directly. It won't work. Please extract the zip
echo file contents to a folder and run it from there.
echo
echo For further information visit https://SlideFab.com
echo ___________________________________________________________
:Ask
echo Would you like install SlideFab 2?(Y/N)
set INPUT=
set /P INPUT=Type input: %=%
If /I "%INPUT%"=="y" goto yes
If /I "%INPUT%"=="n" goto no
goto Ask
:yes
set "sourcepath=%cd%"
set installfolder="SlideFab 2"
set installpath="%appdata%\SlideFab 2"
cd %appdata%
rmdir /S /Q %installfolder%
mkdir %installfolder%
cd %sourcepath%
robocopy "SlideFab 2" %installpath% /E
powershell "(Get-Content SlideFab.reg) | foreach-object {($_ -replace \"FOLDER_APP_DATA\", (\"%appdata%\").replace(\"\\\",\"\\\\\"))} | foreach-object {($_ -replace \"FILEPATH_APP_DATA\", (\"%appdata%\").replace(\"\\\",\"/\"))} | Set-Content SlideFabLocalized.reg"
reg import SlideFabLocalized.reg
del SlideFabLocalized.reg
echo SlideFab 2 was installed
pause
exit
:no
echo SlideFab 2 was not installed
pause
And the registry entry looks like this:
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\SOFTWARE\Microsoft\Office\PowerPoint\Addins\HuehnSolutions.SlideFab2]
"FriendlyName"="SlideFab2"
"Description"="SlideFab. The most powerful Powerpoint automation tool ever built"
"Manifest"="FOLDER_APP_DATA\\SlideFab 2\\SlideFab2.vsto|vstolocal"
"LoadBehavior"=dword:00000003
[HKEY_CURRENT_USER\Software\Microsoft\VSTO\Security\Inclusion\a6cf3786-79d9-47b1-a547-d4f03100b58d]
"Url"="file:///FILEPATH_APP_DATA/SlideFab 2/SlideFab2.vsto"
"PublicKey"="<RSAKeyValue><Modulus>seBB06Hh+Io1QcLLu2OVLl761vIeB4PDMAKlHDRlS9TVD0RZU4tBZ4ty22npfRhvt1Uqm5b8At7GZpQrLuMtX1AAvjmoy9qlm7NsX95UCFBP8ip//YvupVmcVpg7okAzuKALBu3anJGC1aa+Q57h6IP3cDnfdswoCvC1e9KJKpSmzktXG29MQ3nQBLn7Oo3UUM4C9Om8h/96cjowiI8FdHuz6JXIj8K8OEEhtCWxGnIL2ebYvnrPxBRFIlBHkuDeGHZ2C0hJB4MWN6MkTQEkJp5YtfJrt1oDmYPvlVjzp3gcUHcLft2/1gLnOVJFMDrwBM93YZNetQAuwzQdgxesHQ==</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>"
I'm working on an application that will run as a windows service, and I'm trying to get it to update itself automatically.
My current approach is to to execute a powershell script, which will stop the service, run a msi installer, and then restart the service.
This is what the powershell script looks like at this time
Start-Sleep -s 10
Write-Host "update start"
Stop-Service ServiceName1
msiexec /i c:\ProgramData\ProgramName\Install\ServiceName.Setup.msi /passive /l*v C:\ProgramData\ProgramName\Install\log.txt | Out-Null
Start-Service ServiceName1
Write-Host "update finished"
This is how I'm running it from the app
Process.Start("Powershell", #"C:\ProgramData\ProgramName\Install\UpdateApp.ps1");
What happens, is the service stops and restarts, but it doesn't update. It's as though the msi never gets run. The log file doesn't even appear.
When I run the Service as a command line app from an elevated command prompt it works as expected and the app gets updated, so My current theory is that the service isn't running the powershell script with administrator privileges.
Other questions suggest that I set up the log on settings for the service to use an administrator account, so I set the service to run as the account that I was currently logged in under, who was able to open an elevated command prompt and/or manually run the installer, but doing that didn't change anything.
Is there any way to do what I'm trying to do?
I'm currently not committed to any particular automatic update strategy, but I do know that I want this service to update itself. So if I'm doing something completely wrong, I'm 100% open to attempting a different approach.
UPDATE:
I made the following change to log the error and output for msiexecc
Try{
c:\windows\system32\msiexec.exe /i c:\ProgramData\ProgramName\Install\ServiceName.msi /passive /l*v C:\ProgramData\ProgramName\Install\log.txt | Out-File -filepath C:\ProgramData\ProgramName\Install\output.txt
}
Catch {
$_ | Out-File C:\ProgramData\ProgramName\Install\errors.txt -Append
}
After running that script, I found the following error:
The term 'msiexec' is not recognized as the name of a cmdlet, function, script file, or operable program..
It looks like the call to msiexec isn't actually targeting c:\windows\system32\msiexec.exe
As per this question it seems that Powershell does not use the standard PATH environment variable, but has its own scheme, which perhaps doesn't work as expected in the context of a system service.
The simplest resolution, as you say, is to specify the full path, which is probably c:\windows\system32\msiexec.exe.
However, in production, it would probably be wise to avoid the use of a hardcoded path, since you might run into problems with localization, operating system changes, and so on. You could perhaps use SearchPath or a .NET equivalent from your service and either write out the Powershell script in real time or pass the path to msiexec as a command-line option, or there may be a sensible Powershell solution.