Load Application on Windows Startup Before Login - vb.net

I'm writing a VB.NET application that I want to load at Windows start up before the user logs in. It's going to run on a server and launch other process and kill and restart them as needed to get around a memory leak issue. It also needs to have a GUI to view the current status of the processes its managing.
Now, I can get the application to load when the user logs in but that's not very helpful because the server could reboot for some reason and no user would be logged on, but this application still needs to run in the background.
How do I do this? Do I need to write it as a service, or is there another way? I tried writing a WinForms app but it wouldn't load until after the user logs in.

You need to write a service. Also, probably best to write a second app that will interact with the service and provide a GUI to control what it does.

Related

How does one interact with the user from a vb.net service?

I've got one for you thats been bugging me for a bit.
If you run a Windows Service as Local System, how can that service display forms or prompts on the user desktop?
I tried this in one of my previous apps and couldn't get it to work; I settled on having an 'invisible' app running in the user context to handle any user interaction. But as time has passed, I've seen some apps that have nothing more than a service running as local system and yet they produce prompts and forms on the user desktop.
Thanks in advance for any info :)

Vb.net, How to restart an application with elevated admin rights?

I currently have 2 applications; The main application and an Updater. The main application runs with the manifest in "asInvoker", whilst the Updater runs with "requireAdministrator".
However, I currently need the main program to modify contents of its own folder in ProgramFiles, but in order to do this I need elevated access. Instead of creating another application to separate the process, would it be possible to have a messagebox appear saying "Restart in Admin Mode?" and then proceed to restart the application in Administrative mode only the one time?
I don't want the end user being spammed with Window's UAC every time they open the application, which is why I already separated the updater.
Any ideas and suggestions are greatly appreciated.
Simpliest solution is to not store application in Program Files, where access is restricted for non-administrators, but in %LocalAppData%, where is unrestricted access for logged user. This is how update is solved in ClickOnce-distributed applications.

Can a non-root user kill an OS X "login item" launched with ServiceManagement Framework?

I am deciding between using a login item and launch agent.
In this respect I have few questions:
Is it possible for a non root user to quit a login item helper if it is launched with service management framework using SMLoginItemSetEnabled? Will the helper app be reloaded by launchD if it is killed by user or in some cases OS?
Why does apple not recommend presenting a UI with an app that can be executed via a LaunchAgent? Is there a problem if we present a minimal UI?
A login item as a helper application requires the main application to call SMLoginItemSetEnabled. This implies that the main app must be called at least once to enable the login item. This differentiates it from a launch agent which can be loaded as soon as the plist is installed on the system. Can we execute the helper login item irrespective if the user has opened the main app or not?
Any help would be appreciable
LaunchAgents that are configured using SMJobBless are intended to be non-gui services. They run without UI in the background, and don't run as the logged in user.
If you want a gui, you're going to have to use SMLoginItemSetEnabled, or manually install a user LaunchAgent via a .plist with the "LimitLoadToSessionType" = "Aqua" property.
Helpers launched by SMLoginItemSetEnabled run as the current user, so they can be terminated by that user. The process will get relaunched if launchd detects that the agent went away because of a signal or due to an abnormal termination. If it terminates due to a clean termination it will not be restarted until the next login of the user (by clean termination we mean terminating with an exit code of 0, which will not happen if the program is killed e.g. via the activity monitor. If the helper has an option to quit, and that option causes it to exit with a 0 return code, then it will not be restarted, which would be considered good form by the application.
It's a stylistic thing - a user cannot disable the agent without interacting with the command line which would be considered poor standing. There is no issue displaying a UI from a LaunchAgent. As long as it's registered with the appropriate keys, it will be launched in the user's gui login context which means that it can be fully interactive. I have several applications which act like that - TunnelBlick, 1Password (this is via the LaunchAgent plist) and they only put up a menu bar item on startup.
If you're just shipping an application - e.g. via the app store, then there's no way to have anything automatically start without some interaction by the user - you have to launch the main app to get the helper to be enabled. The helper login item can be launched manually without ever launching the main application; but it won't have the 'launch at startup' magic enabled. If you can register a LaunchAgent plist, then you can get the launch at startup & starting it up immediately behaviour.
For uninstallation, however, LaunchAgents require the removal of the .plist, and interacting with launchd to disable it, items registered with the Service Mangement framework will naturally vanish once the app is dragged to the trash.
IMHO, (bit soapboxy, bit opinionated) If you're shipping a standard app with a helper, then rely on first launch before configuring such things as helper start on login; primarily because it keeps the user in control. Autoinstalling startup items is one of my pet peeves with windows applications (so many status bar items...).
The docs for SMLoginItemSetEnabled state the login item will be "kept running", which seems to indicate it will be relaunched if it is killed:
The Boolean enabled state of the helper application. This value is effective only for the currently logged in user. If true, the helper application will be started immediately (and upon subsequent logins) and kept running. If false, the helper application will no longer be kept running.
https://developer.apple.com/documentation/servicemanagement/1501557-smloginitemsetenabled

VB.Net running as a service

I have built an application that connects to the exchange server and does some scanning tasks on the incoming mail.
Application has a form where i can start and stop scanning,give in an interval, do some other configuration, and a notificationicon in the taskbar to show hide,end and so on..
The problem is that I would like the application to start as a service, because now a user has to log in first on the server before it starts working.
I tried some tools like RunAsService, i had a service, but obviously it didn't run the application.
Of course i understeand now that when the application will run as a service, scanning will be the only thing that will happen, no forms and no notification icons.
However i do not know where to start, should i extract the scanning logic from my configuration as a separate application? What application type should it become then ?
You have two easy options.
First one just create a new Windows Service Project from your New Project button in the Visual Studio, and then just program your app.
Second one, just create a service from the service management window in your computer and add the executable file of your program. It will start running as a service (with visible windows and everything as you coded it).
You should follow this link and schedule your vb.net windows program as windows task
In Your code, at the end ,when everything gets executed you should write Me.Close() to hide your form.

How to put Windows login process on hold

I am trying to create an application/service which will be running in the machine without any console or remote log-in. And if any user is trying to log-in this application will perform following task in sequence:
Put the log-in process on hold.
Do its own processing and and upon completion of its work,
It should allow the Windows to resume with the log-in process.
I could not find any way to put the windows log-in process on hold. Any suggestion/help appreciated.
Note: I am using Windows Embedded Standard 7.