Cannot receive UDP packets from app run via Task Scheduler - c#

I created a small C# app with Visual Studio 2012 that I want to use messages with to another app. This app uses UI Automation to grab text from another running app. I need to run this as an administrator because otherwise it cannot grab the text I need since that other app apparently runs under an adminstrator account as well.
My client app needs to run under any account, elevated or unelevated, hence the reason why I separated the admin part from it. The idea was to get the info I needed from the app granted admin rights and broadcast it to the other app via UDP.
Unfortunately, this doesn't work out so well.
If I open both tasks via Explorer it works, but if I open the listener/client app myself using Explorer and try to have the admin portion run automatically via Task Scheduler I never see the broadcasts. I set it up to run both on start and on logon and have specified an admin username/password. I can see the admin app running in Task Manager but don't get the UDP broadcasts.
My understanding is that apps started through Task Scheduler don't have UI access, but are their local socket communications blocked as well?

Related

Without Administrator Privileges Launching Desktop Application in a logged in User context with Administrator Privileges

I wanted to run local desktop applications which are installed in Program Files and Program File (x86) folders only, the application should run with administrator privileges as logged in user context. I have googled and got to know some.
Required as per my idea:-
File Explorer GUI with Socket Client
A Service
Local Application Launching Executable with Socket Server ( console application)
Note: The communication between File Explorer will happen using socket client and server. The service will launch the local application server in system context.
Imagine that File Explorer, Service and Application Launching server are installed.
Using File explorer the app will be selected and selected application information will be sent to the server. The server will do check on the requested path whether it is from trusted path or not.
If it is from trusted path, the server will get handle from "winlogon.exe" and get the handle to the access token, then duplicate the access token and adjust its privileges (default system privilege will be there and i don't want that as system will have full privileges) then use CreateProcessAsUser to launch the application.
Once launched bring the UI to the foreground. The application need to be run in user context with administrator privileges.
My questions are stated below:-
To achieve this do i need to enable the interactive process in the
service ?
If interactive is necessary, the communication between the
user and local server is happening using socket and user do not
interact with service directly, just wanted to know whether am i
following the Microsoft safety measures as stated in below
documentation or am i breaching it?.
https://learn.microsoft.com/en-us/windows/win32/services/interactive-services
Do we have any other way to launch an application with admin
privileges in logged on user context without actual administrator privilege ?
The targeted OS is Windows 10 1803 and 1809.
Have a look for the tools psexec or paexec (they're mostly identical, the major difference being that the later is open-source).
These tools allow you to start a process as another user and/or on another computer. This should work from a service as well.

How to monitor an external process (simplest approach)

I have a csharp app running in my customer's server. The app is a Windows Service.
I want to be able to tell if app is running, if it is stopped and lastly I want to be able to restart it. Everthing must be done from a web client app.
Because access from external networks to this machine is restricted by my customer, I was thinking about implementing an "Agent Client", which will be just another Windows Service running locally and that could execute the "restart" and "stop" commands. It would be pulling an external "Agent Server" to find out if commands need to be executed.
What do you think about this? Any better ideas?
Thanks a lot!

How to let my application to be running even when Logged off the machine?

I have developed a TCP Server. I want my TCP server to be running even when I log off my machine. So clients can connect to it even when my computer is logged off. I was thinking if I must create a Windows Service to implement this approach, but I am not sure how to do so.
Please tell me how can I let my application to keep working even when my machine is logged off.
You can create a service by following these instructions:
http://support.microsoft.com/kb/251192
And then installing it to your PC should be as simple as using
installutil MyService.msc
(installutil will be part of your .NET installation, eg in C:\Windows\Microsoft.NET\Framework\v3.5)
You can the configure it to Startup Automatically by running services.msc from the command prompt.
You could launch it as a task from Windows Task Scheduler and set it to run even if you aren't logged in. This would work even if the application isn't a service.
If you want to be able to shut down your machine and still let the client connect then you need to deploy your application on a server.
Create a windows service and run it as LocalService http://msdn.microsoft.com/en-us/library/zt39148a(v=vs.80).aspx

Run Batch-Files in Windows Service while logged off

I wrote a windows service in C# .NET 3.5.
It starts up automatically and runs as Local System User (no log in required).
If i run a Shutdown-Batch-File (shutdown -s -t 30) with my service by calling Process.Start(), nothing happens until i log in to windows. So it waits for logging in and then starts the batch.
Is it possible to run this batch in logged off state?
Greetings
There is a property for each service application called Allow Interact With Desktop that should be set True for your service to be able to run Shutdown-Batch-File.
Take a look at these links:
Interact With Desktop when Installing Windows Service
Allow service to interact with desktop in C#
Have you checked to make sure this is not a permission issue? Ie does it work if the service is running as an administrator?
You might also want to try the alternative methods of shutting down mentioned in this question how-to-shutdown-the-computer-from-c#.

How to create invincible windows application using c# and windows services

I wrote a windows form application running in my local system. I wanna make it invictible. I mean, I want to the users cannot kill the process using task manager or any other third party application. So I wrote a windows service to run this application on startup. I thought I need to run windows service as SYSTEM but how can I do that ?
Is there any spesific suggestion for this kind a situation ?
I also had the same problem with an application at work, which the users shouldn't be able to close.
You have to allow the servie Allow service to interact with desktop.
Heres an example how to do this while installing the service: http://www.codeproject.com/KB/install/cswindowsservicedesktop.aspx
Now you are able the launch a GUI application from the service, for the current logged in user. You should look in a intervall if the process for the current user is still running, if not just start it again.
See here for current user processes: http://www.codeproject.com/KB/cs/processownersid.aspx

Categories

Resources