Createprocesswithlogonw Failed With Error 5
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the createprocesswithlogonw c# company Business Learn more about hiring developers or posting ads with us Stack Overflow
Createprocesswithlogonw Example C++
Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7
Createprocesswithlogonw Powershell
million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up CreateProcessWithLogon in service returning code 5: access denied up vote 0 down vote favorite I have a windows service with
Create_breakaway_from_job
StartType = stSystem. It executes an application with the CreateProcessWithLogonW. usr := 'myuser'; dmn := 'mydomain'; pwd := 'thepassword'; cmd := 'c:\myapp.exe -calculate'; wdir := 'c:\'; fillchar(si, sizeof(si), 0); si.cb := sizeof(si); if not CreateProcessWithLogon( PWideChar(usr), PWideCharOf(dmn), PWideChar(pwd), LOGON_WITH_PROFILE, nil, PWideChar(cmd), NORMAL_PRIORITY_CLASS or CREATE_NEW_CONSOLE or CREATE_NEW_PROCESS_GROUP, nil, PWideChar(wdir), si, pi ) then RaiseLastOSError; // raises Code 5: Access Denied Running this code outside the service, everything goes fine! Why the CreateProcessWithLogon raises a failed to create process access is denied netbeans system error Code 5: Access Denied ? Can be this the cause? MSDN article on CreateProcessWithLogonW says: Windows XP with SP2 and Windows Server 2003: You cannot call CreateProcessWithLogonW from a process that is running under the LocalSystem account, because the function uses the logon SID in the caller token, and the token for the LocalSystem account does not contain this SID. As an alternative, use the CreateProcessAsUser and LogonUser functions. I'm using Windows 7 PRO x64 delphi winapi windows-services share|improve this question edited Nov 29 '12 at 18:59 Remy Lebeau 230k13140267 asked Nov 29 '12 at 13:09 Beto Neto 81411133 Can you specify which user account the service is running as? It could be LocalSystem, NetworkService, a named user, etc. –Charlie Nov 29 '12 at 13:44 the service is running as LocalSystem –Beto Neto Nov 29 '12 at 13:53 2 What's the question? –Ondrej Kelle Nov 29 '12 at 14:09 What happens if you don't use LOGON_WITH_PROFILE? –iPath ツ Nov 29 '12 at 16:06 3 you are running the service under the LocalSystem account, and as the documentation says: "You cannot call CreateProcessWithLogonW from a process that is running under the LocalSystem account". So either change the user account that the service runs under, or switch to Cr
Campos MagencioDecember 20, 200711 0 0 0 Hi, welcome back, Sometimes.NET‘s System.Diagnostics.Process class and its Start method are not enough for c# createprocessasuser service our purposes and we need to call Win32 API directly createprocesswithlogonw access denied from .NET (P/Invoke mechanism) to be able to create a process the way we need. Here createprocessasuser error 5 you have a sample you might find useful. It includes P/Invoke declarations and usage samples of some very famous API: LogonUser, CreateProcessAsUser and CreateProcessWithLogonW. http://stackoverflow.com/questions/13626571/createprocesswithlogon-in-service-returning-code-5-access-denied
service Visual Studio Languages , Windows Desktop Development > C++ Standards, Extensions, and Interop Question 0 Sign in to https://social.msdn.microsoft.com/Forums/vstudio/en-US/35c93ce5-6867-4f00-ab70-e8fc4097e406/erroraccessdenied-in-createprocesswithlogonw-on-a-windows-service?forum=vclanguage vote Hi, I'm writing a service that needs to open a http://www.pcreview.co.uk/threads/createprocesswithlogonw-and-runas.1315166/ new process (in a different console). One of the arguments of the new process is a remote file that it needs to read. I have to use LocalSystem user because the "interact with desktop" option and the new process' console must be seen too. error 5 I don't knowunder which userthe service is going to run so I use NetworkSystem user. This is my code - It fails on CreateProcessWithLogonW with error 5 (ERROR_ACCESS_DENIED). int error = 0; PROCESS_INFORMATION pi = {0}; STARTUPINFO si = {0}; LPVOID lpvEnv = {0}; WCHAR szUserProfile[256] = L""; if (CreateProcessWithLogonW(L"NETWORK SERVICE", L"", L"", LOGON_WITH_PROFILE, createprocesswithlogonw failed with MY_EXE_FULE_PATH, MY_EXE_ARGUMENTS, CREATE_UNICODE_ENVIRONMENT, lpvEnv, szUserProfile, &si, &pi) != 0) { WriteToLog("V"); } else { error = GetLastError(); // returns 5 WriteToLog("X"); } Thanks in advance! Monday, August 06, 2012 1:16 PM Reply | Quote Answers 0 Sign in to vote Use WTSGetActiveConsoleSessionId() to obtain the session ID of the currently logged-on user. Use this ID in a call to WTSQueryUserToken() to obtain the user's token. With the obtained token, start the new process using CreateProcessAsUser().Jose R. MCP Code Samples Marked as answer by Damon ZhengMicrosoft contingent staff, Moderator Sunday, August 12, 2012 8:11 AM Monday, August 06, 2012 2:47 PM Reply | Quote 0 Sign in to vote WTSQueryUserToken() can only be used from a Windows service running under SYSTEM. So make sure this is true. As for WTSGetActiveConsoleSessionId(), it returns -1 if there's no console session, but according to the documentation, no other value is a special value. It also doesn't say that GetLastError() is a viable thing to do
Hi, Was wondering if anybody could help.. I'm try to launch an application as an administrator from with inside my application. At first this appeared to be working, until I tried launching a different application.. I am launching the application using the following command.. app = "test.exe"; CreateProcessWithLogonW( "Administrator",".", "password", LOGON_WITH_PROFILE, app, null, 0, IntPtr.Zero, CurrentDirectory, ref si, out pi) ; The problem is that if run the same application via the command prompt with runas.exe it works!!!! Can see what I'm missing!! Anybody got any ideas? Are there any hidden flags for the LOGON flags.. Thanks Wayne Gibson Wayne Gibson, Oct 16, 2003 #1 Advertisements Stoyan Damov Guest Hi, Is "test.exe" in your executable's path. Here's (part of) the documentation of the lpApplicationName parameter: "The string can specify the full path and file name of the module to execute or it can specify a partial name. In the case of a partial name, the function uses the current drive and current directory to complete the specification. The function will not use the search path." Also, why don't you get the last error, or just throw "$ERR,hr" in the watch window to see what's wrong? HTH, Stoyan Damov "Wayne Gibson" <> wrote in message news:bmltev$87t$1$... > Hi, > Was wondering if anybody could help.. > > I'm try to launch an application as an administrator from with inside my > application. > At first this appeared to be working, until I tried launching a different > application.. > > I am launching the application using the following command.. > > app = "test.exe"; > CreateProcessWithLogonW( "Administrator",".", "password", > LOGON_WITH_PROFILE, app, null, 0, IntPtr.Zero, CurrentDirectory, ref si, out > pi) ; > > The problem is that if run the same application via the command prompt with > runas.exe it works!!!! > Can see what I'm missing!! > Anybody got any ideas? > Are there any hidden flags for the LOGON flags.. > > Thanks > > Wayne Gibson > > Stoyan Damov, Oct 16, 2003 #2 Advertisements Ying-Shen Yu[MSFT] Guest Hi Wayne, I agree with Stoyan, you should give the full path to your application if it isn't in the current directory of your program. CurrentDirectory is not for that purpose, This feature is provided primarily for shells that need to start an application and specify its initial drive and working directory. I tested the API on my system using the following statement , and it works fine. Also it seems you are using This API .NET via PInvoke, I'm not sur