LoadUserProfile for another user that is not logged in - winapi

How can i use LoadUserProfile for a user that is not logged in. This code is running within a service and needs to capture a user profile information, but that user may not be logged in when the service executes.

Related

Get restricted user folder when an app requires admin rights and started under admin

There is a Windows app that requires admin rights and this is declared in its manifest. When a restricted user starts it she has to input admin credentials. It's OK and the application works well, but it can't obtain original user folders anymore (ShellAPI returns admin's ones).
Since the application is started under admin initially, there is no point where I can store original user's folder paths to use them later.
Is there a way to get initial restricted user credentials?
Regards,
Because of your manifest, your app is running as an admin user, not the currently logged in restricted user. As David Heffernan mentioned, you should redesign your app to not require the entire app to be run elevated. Delegate your admin tasks to a separate process that runs elevated when needed.
That being said, if you must run your entire app elevated, all is not lost, but you are going to have to do some extra work.
Start by getting the Session ID that your elevated app is running in. You can do that using WTSQuerySessionInformation() with WTS_CURRENT_SESSION, or ProcessIdToSessionId() with GetCurrentProcessId(), or open the current process's token with OpenProcessToken() and then use GetTokenInformation().
Once you have the Session ID, use EnumProcesses(), GetProcessImageFileName() (or equivalent), OpenProcessToken(), and GetTokenInformation() to find the instance of explorer.exe (or whatever the PC's registered shell app is, which you can find in the Registry) that is running in the same Session ID as your app.
When found, you have the user token for that process from OpenProcessToken(). Duplicate it using DuplicateTokenEx() to get its primary token, and then you can use that token with APIs like LoadUserProfile(), SHGetFolderPath() and SHGetKnownFolderPath() as needed.

Is currentUser specific to device

is currentUser on parse specific to devise? When the user is logged in and cached as the currentUser, it is only for that device he is using that he will be automatically logged in, is that correct?
My app sets currentUser in appdelegate, so if a user A logged in on Device A, and he is still cached on parse server, would user B who launched my app on device B be logged in as user A?
1.
Yes, it's specific to device. It is only for that device that the user is logged in, so if User A opens the app on another device, they will have to log in again.
2.
If User A logs in on Device A, it will not affect User B on Device B. Ever.
When one of your users logs in, that session is only cached on that device, so yes, your first statement is correct. I am unsure about the second part because I don't know what you mean by "My app sets currentUser in app delegate". Can you post your code?
Your code to login a user should take from user input, their specific username and password combination. When you login a user, you shouldn't use constants, then the same user will be logged in on every device.
For every device that a user has logged in he will be automatically be logged in when launching the application.

Destroy session of user when disabled by admin?

Imagine you are Admin, now you decide to disable or remove a user.
If that user is logged in and is working with system, must be return to login page in soon (while he send first next request after kick by admin).
What should i do?
In the auth filter, if the user is not a guest - check if he is disabled; if so, log him out.
This will not log him out if he requests a public (non-auth protected) route.. but what would be the point anyway, since it doesnt matter if the user is logged in or not.
http://laravel.com/docs/4.2/routing#route-filters

Check User Session in win32 Service

I'm creating a win32 service ,I want my Service to check if user is not logged in, my service do something How i Can check if user logged in or not?
You can use WTSEnumerateSessions to check the connection state (WTS_CONNECTSTATE_CLASS) of all sessions in the system. If you bother only for the console session you can use WTSGetActiveConsoleSessionId to get its id and then call WTSQuerySessionInformation.
Also a service can receive SERVICE_CONTROL_SESSIONCHANGE to get session change notifications.

How to switch user programmatically in windows

I would like to know if there are any API's available to switch users programmatically in windows.My application when provided with user credentials(account name & password) will try to logout any other user logged on and try to login the present user.
Any help would be greatly appreciated.
The function you are presumably looking for is LogonUser
However, you are probably better off using user impersonation in most cases.
Personally, I suspect you are likely better off user neither method and simply using security context of the running user, providing an privileged function via a windows service you wrote specifically for your application
Why don't you create a service to switch user credentials (by methods mentioned in the other answers), and install and run the service as "Administrator". From the logged in user account, you can invoke this service (Which is already running as admin), and make it switch user accounts without the permissions issue (as the service responsible to switching is already running as admin)

Resources