Click here to Skip to main content
15,879,348 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Afternoon All,

Hoping you can shed some light here, i have an application that runs on an RDS 2012 RD Session host, it loops through the the process list from Win32_Process and compiles a list of who is running a specific instance of an process.

Now, what i want to be able to achieve is to run the application as that user if it is not running, it is a requirement for all users to have this running at all times and if they manage to close it for what ever reason i need the app to be able to restart it.

I thought about impersonation, but usually you need the username and password, is there a way of starting the application under the user that is missing the process without needing their username/password?

Would appreciate any guidance here.

Regards
Dev
Posted
Updated 12-Jun-15 4:41am
v2
Comments
Andy Lanng 12-Jun-15 10:52am    
Have you looked into running this app as a service? You have not told us what language or event platform this will run in, but services can be started automatically on logon, with the logged on credentials, and can restart itself if it is stopped for any reason. You can even make it so it can't be stopped.
Another advantage is that it won't be visible to user unless they look at running services.
Andy Lanng 12-Jun-15 10:54am    
Oh, you want to know the user who is logged on via rds? Trickier but doable. The service just has to look for remote connections and start logging at that stage, instead of running as the logged on user
Dev O'Connor 12-Jun-15 10:58am    
Hi, Thanks for coming back to me, as there will be approx 50/60 users on this i dont want 50/60 users running the same EXE at the same time.

I am struggling to find the WMI tables etc required to get this information. If i can get the session id of the users then i can use WTSQueryUserToken or something a long this line but just cant seem to enumerate the users

would appreciate any pointers for WMI table?
Andy Lanng 12-Jun-15 11:06am    
What language?
C# = ManagementObjectSearcher query= new ManagementObjectSearcher("SELECT * FROM Win32_UserProfile WHERE Loaded = True");
Dev O'Connor 15-Jun-15 3:41am    
Hi,

Thanks for the infor thats great, it was VBNET but no problem, i already have the code its the select statement i was struggling with.

Based on the Reply from Dave Krekowiak below, would the application be inhibited from interacting from the desktop (i dont need the user to interact with the application)

What kind of app is this that you're monitoring and trying to relaunch?

If it's an application that puts up any kind of user interface at all your users will not be able to see it, even if you launch the app as that user.

While it is possible to remotely launch an application, it is now IMPOSSIBLE for the user on that machine to interact with it. This is a security restriction imposed by Windows that you can not get around, for obvious reasons.
 
Share this answer
 
Comments
Dev O'Connor 15-Jun-15 3:40am    
It's not a program tht they need to interact with, its an application that that interacts with their desktop with windows api calls sich as GetForegroundWindows().

Will the same restriction be applicable here?
Dave Kreskowiak 15-Jun-15 7:46am    
Yep. You don't get to interact with the user desktop at all.
Dev O'Connor 15-Jun-15 17:29pm    
Hi, so i have managed to achieve this by grabbing the users token and using this to fire the exe, all is working as expected, once i have cleaned up the code from testing i will post an update below.

Due to grabbing the token, which requires the SE_TCB_NAME privelige the service is having to run as Local Service, when i try and grab the windows identity and check WindowsPrincipal.IsInRole, they all return false. Is this becuase the service is running as LocalService? Is there any way i can check if the passed 'SID' / WindowsIdentity to return the users group membership?

they all return false for local groups to the machine and to domain groups - basically i need it not to action this for administrator accounts (elevated access causes a problem with the actual applicaiton being called due to being able to see all of the processes for all users)
Dave Kreskowiak 15-Jun-15 21:06pm    
You might want to see what you actually grabbed. Don't just assume you got the token of the user logged in at the console.
A service can only run on the default desktop. If you need to monitor each users desktop activity then each session will require an exe to be running. There are ways you can hide the exe but they aren't so easy.

This article has a section on hiding apps from the taskbar.
How To Make a Windows Form App Truly Full Screen (and Hide Taskbar) in C#[^]

It is possible, but buggy and difficult, to hide the exe from other monitors such as task manager
 
Share this answer
 
Comments
Dev O'Connor 15-Jun-15 17:29pm    
Hi, so i have managed to achieve this by grabbing the users token and using this to fire the exe, all is working as expected, once i have cleaned up the code from testing i will post an update below.

Due to grabbing the token, which requires the SE_TCB_NAME privelige the service is having to run as Local Service, when i try and grab the windows identity and check WindowsPrincipal.IsInRole, they all return false. Is this becuase the service is running as LocalService? Is there any way i can check if the passed 'SID' / WindowsIdentity to return the users group membership?

they all return false for local groups to the machine and to domain groups - basically i need it not to action this for administrator accounts (elevated access causes a problem with the actual applicaiton being called due to being able to see all of the processes for all users)
Andy Lanng 16-Jun-15 3:53am    
hmm - I think you have exceeded my knowledge on this. I have never looked at user domains or groups via ManagementObjectSearcher. Post a new question and see if you can get any new hits.

Best of luck ^_^
I'll keep an eye out because this interests me also

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900