Click to See Complete Forum and Search --> : CreateProcessAsUser() from service


sri_codeguru
July 7th, 2010, 06:07 AM
Hi All,
When I try to create a process using CreateProcessAsuser() from a service, I am getting GetLastError() as 1813. (The specified resource type cannot be found in the image file. ERROR_RESOURCE_TYPE_NOT_FOUND "). But the return code is coming a True and process also initiated. But why GetLastError() is coming as 1813.

Please let me know if anyone have idea about this error even the API call returning success.
Regards
Sreeni

Igor Vartanov
July 7th, 2010, 06:10 AM
Try SetLastError (http://msdn.microsoft.com/en-us/library/ms680627(VS.85).aspx)(0) prior to calling CreateProcesXxx and see if 1813 remains.

Igor Vartanov
July 7th, 2010, 06:18 AM
GetLastError (http://msdn.microsoft.com/en-us/library/ms679360%28VS.85%29.aspx)
Return Value

The return value is the calling thread's last-error code.

The Return Value section of the documentation for each function that sets the last-error code notes the conditions under which the function sets the last-error code. Most functions that set the thread's last-error code set it when they fail. However, some functions also set the last-error code when they succeed. If the function is not documented to set the last-error code, the value returned by this function is simply the most recent last-error code to have been set; some functions set the last-error code to 0 on success and others do not.

sri_codeguru
July 8th, 2010, 01:34 AM
Thank you for your response.
Even after setting error code to 0 SetLastError(0); before calling CreateProcessAsUser(), I am still getting the last error-code as 1813, But the process initiated without any issues.

Now I am coming to the real problem I am facing.

Actually we are working on a remote application, where we run the host process with CreateProcessAsUser(). Later from our application if we pass Ctrl+Alt+Del command we are getting UAC screen where we can LogOff the desktop. But on clicking LogOff the system getting crashed(blue screen). But this is not happening if I Log off the remote machine from Start menu of Windows(Start->Logoff) This is happening in Vista/Windows7.

Could you please throw some light on the issue?


Regards
Sreeni

Igor Vartanov
July 8th, 2010, 03:48 AM
Never had such a task, and would like to have some background info for what you do: what is the effect you expect from that? You hope to logoff interactive user been running totally different account?

Krishnaa
July 8th, 2010, 05:19 AM
If CreateProcessAsuser returns non-zero value that means you do not need to check for last error, the function has succeeded, some internal API call resulted in the last error but the internal code logic took care of that and succeeded.

So with Win32 APIs, always check the API's return value first, if that shows failure then go look at LastError.

sri_codeguru
July 12th, 2010, 05:41 AM
Hi,
We have a remote application(like TightVNC) to connect to remote desktops. The server will be running on remote desktop, as I said this server is running from windows service. We have our own video driver. On Windows7 and Vista machine we are starting this server in winlogon session using CreateProcessAsUser(). And in STARTUP information we assigned the desktop(STARTUPINFO. lpDesktop) with "winsta0\\default". After session established between Client desktop and Remote sesktop, we are sending Ctrl+Alt+Del command, this is showing up with UAC screen. Then on clicking Logoff the blue screen is appearing(system crash). But it is not creating any dump file to analyse the issue.

The following url gives the sample code which we used to launch the host application in winlogon session.

http://www.codeproject.com/KB/vista-security/VistaSessions.aspx?msg=3198293


Please let me know if any details required.

Regards
Sreeni

Igor Vartanov
July 12th, 2010, 06:03 AM
Please let me know if any details required.I've asked the question, see my previous message.

sri_codeguru
July 12th, 2010, 07:48 AM
My expectation is it should behave same as how LogOff works. coming back to the user accounts screen where we can login again. But it is crashing with blue screen.


Regards
Sreeni

Igor Vartanov
July 12th, 2010, 03:06 PM
So, bottom line is: you want to log off interactive user. Then you need to emit that Ctrl+Alt+Del in the context of the interactive session but not in the context of your remote application.