03-21-2014 06:04 PM
If I lauch Excel from a Windows service (created by LabVIEW), does Excel run as current user? Does Excel visible to the current user? Has anyone does this before?
TIA.
OS: WinXP.
03-21-2014 07:16 PM - edited 03-21-2014 07:23 PM
That depends on a lot of things. You can configure a service to be started in a certain account. Typically services are started under the LocalSystem account and do not allow any desktop interactions. But you can install the service to run under a different account and also allow it to have desktop interaction (but only if it is started under LocalSystem and only before Windows Vista).
Any executable started by a LabVIEW application through System Exe will simply inherit the account settings and permissions of the LabVIEW application. For anything else you'll have to dig into CreateProcess() and setup your own access permissions values to be passed to CreateProcess() or you can use CreateProcessAsUser() but it still requires the according user handle that you somehow have to determine and open.
03-21-2014 08:17 PM
> But you can install the service to run under a different account and also allow it to have desktop interaction
> (but only if it is started under LocalSystem and only before Windows Vista).
Don't understand. I need to show a dialog window to user. So should I use the LocalSystem or a different account?
> Any executable started by a LabVIEW application through System Exe will simply inherit the account settings and
> permissions of the LabVIEW application.
That's what I thought.
> For anything else you'll have to dig into CreateProcess() and setup your own access permissions values to be passed
> to CreateProcess() or you can use CreateProcessAsUser() but it still requires the according user handle that you somehow
> have to determine and open.
The problem is that the "current user" has no password.
BTW, the "current user" has admin privilege.
03-22-2014 04:37 AM - edited 03-22-2014 04:40 AM
Only services logged in as LocalSystem can be set to interact with the desktop. For others it is ignored. The MSDN documentation is also not completely consistent as they say at some point that interaction under Vista and later is not possible anymore, but later describe how a registry setting does disable that option by default in XP and earlier and is set to enable it by default in Windows 7 and later. Go figure.
If you want to gain access rights for a specific user you have to do impersonation. For that you need either a connection like a pipe that is connected to an application running under that user and can then temporarely gain the access right of that user or you need all the authentification credentials to do an LogonUser() and use the returned handle to do an ImpersonateLoggedOnUser(). However if a message bos is all that you need, you may try WTSSendMessage().
Take a look here about the topic and decide yourself if the information is consistent: http://msdn.microsoft.com/en-us/library/windows/desktop/ms683502%28v=vs.85%29.aspx
One thing you should be aware of, is that there might and often is no user logged in on a machine, especially if it is a server oriented machine and then you can not display a message box at all since there is no active desktop to do so.