1. CreateProcessWithLogonW
- Posted by Markus Schaller <markus.schaller at web.de> Feb 27, 2004
- 712 views
Hello I'm trying to wrap the function CreateProcessWithLogonW. This program should start a task with the rights of another user (W2K & XP). Somehow this doesn't work. Unfortunately I'm not good in programming such things. GetLastError() says ERROR_INVALID_PARAMETER. I can't figure out my mistake :( Does anybody know why the following code doesn't work? Thanks in advance Markus Schaller ---- begin code ---- include dll.e include machine.e include w32engin.ew ------------------------------------------------------------------------------- constant xadvapi32 = open_dll("advapi32") constant xCreateProcessWithLogonW = define_c_func(xadvapi32, "CreateProcessWithLogonW", ONG,C_POINTER,C_POINTER,C_LONG,C_POINTER,C_POINTER,C_POINTER,C_POINTER}, C_LONG) constant LOGON_WITH_PROFILE = #1, CREATE_NEW_PROCESS_GROUP = #200 function CreateProcessWithLogon(sequence Username, sequence Domain, sequence Password, sequence ApplicationName) atom lpUsername, lpDomain, lpPassword, lpApplicationName, lpCommandLine, lpEnvironment, lpCurrentDirectory atom dwLogonFlags, dwCreationFlags atom lpStartupInfo, lpProcessInfo atom r sequence CommandLine, CurrentDirectory CommandLine="" CurrentDirectory="" lpUsername=allocate_string(Username) lpDomain=allocate_string(Domain) lpPassword=allocate_string(Password) dwLogonFlags=allocate(4) poke4(dwLogonFlags,LOGON_WITH_PROFILE) lpApplicationName=allocate_string(ApplicationName) lpCommandLine=allocate_string(CommandLine) dwCreationFlags=allocate(4) poke4(dwCreationFlags,CREATE_NEW_PROCESS_GROUP) lpEnvironment=allocate(4) poke4(lpEnvironment,0) lpCurrentDirectory=allocate_string(CurrentDirectory) lpStartupInfo=struc("STARTUPINFO") lpProcessInfo=struc("PROCESS_INFORMATION") r=c_func(xCreateProcessWithLogonW,{lpUsername,lpDomain,lpPassword, dwLogonFlags,lpApplicationName,lpCommandLine, dwCreationFlags,lpEnvironment,lpCurrentDirectory, lpStartupInfo,lpProcessInfo}) free(lpUsername) free(lpDomain) free(lpPassword) free(dwLogonFlags) free(lpApplicationName) free(lpCommandLine) free(dwCreationFlags) free(lpEnvironment) free(lpCurrentDirectory) free_mem(lpStartupInfo) free_mem(lpProcessInfo) return r end function ?CreateProcessWithLogon("admin",".","admin123","C:\\WINNT\\NOTEPAD.EXE") ?GetLastError() ---- end code ----
2. Re: CreateProcessWithLogonW
- Posted by "Derek Parnell" <ddparnell at bigpond.com> Feb 27, 2004
- 685 views
----- Original Message ----- From: "Markus Schaller" <markus.schaller at web.de> To: <EUforum at topica.com> Subject: CreateProcessWithLogonW > > > Hello > > I'm trying to wrap the function CreateProcessWithLogonW. This is the WIDE character version of the routine. Try wrapping "CreateProcessWithLogonA" instead. -- Derek
3. Re: CreateProcessWithLogonW
- Posted by "Bernard W. Ryan" <xotron at bluefrognet.net> Feb 29, 2004
- 687 views
-- Marcus: -- I have added the CreateProcessWithLogonW and constants to the -- w32engin.ew version 6.40 which can be downloaded here: http://www.rapideuphoria.com/w32engin.zip -- I'am using Win98 and advapi32.DLL does not export the -- CreateProcessWithLogonW function so I can't test the following code. -- If you are running windows 2000 or XP. -- Maybe the DLL on a 2000 or XP system does export this function. -- If the function is not exported from your DLL then it maybe that -- this function can only be used by static linking and you would -- have to use the "C" translator to link with the advapi32.lib -- -- Below is all you need to use my win32 engine to test your code to -- see if you can use the DLL, because I added the function to the -- win32 engine. -- -- Bernie -- ---- begin code ---- include w32engin.ew ---------------------------------------------------------------------------- --- function Logon(sequence Username, sequence Domain, sequence Password, sequence ApplicationName) -- atom lpUsername,lpDomain,lpPassword,dwLogonFlags, lpApplicationName,lpCommandLine,dwCreationFlags,lpEnvironment, lpCurrentDirectory,lpStartupInfo,lpProcessInformation, r -- lpUsername = szW(Username) -- szW creates a Unicode temporary string lpDomain = szW(Domain) lpPassword = szW(Password) dwLogonFlags = LOGON_WITH_PROFILE lpApplicationName = szW(ApplicationName) lpCommandLine = szW("") dwCreationFlags = CREATE_NEW_PROCESS_GROUP lpEnvironment = NULL lpCurrentDirectory = szW("") lpStartupInfo = struc("STARTUPINFO") lpProcessInformation = struc("PROCESS_INFORMATION") -- call create process r = CreateProcessWithLogonW({lpUsername,lpDomain,lpPassword, dwLogonFlags,lpApplicationName,lpCommandLine, dwCreationFlags,lpEnvironment,lpCurrentDirectory, lpStartupInfo,lpProcessInformation}) -- free the resources szfree() -- frees the unicode strings free_mem({lpStartupInfo,lpProcessInformation}) -- frees the structures return r end function -- ? Logon("admin",".","admin123","C:\\WINNT\\NOTEPAD.EXE") ? GetLastError() ---- end code ----
4. Re: CreateProcessWithLogonW
- Posted by "Derek Parnell" <ddparnell at bigpond.com> Mar 01, 2004
- 689 views
----- Original Message ----- From: "Markus Schaller" <markus.schaller at web.de> To: <EUforum at topica.com> Subject: RE: CreateProcessWithLogonW > > > > -- I have added the CreateProcessWithLogonW and constants to the > > -- w32engin.ew version 6.40 which can be downloaded here: > > http://www.rapideuphoria.com/w32engin.zip > > Thanks for adding this to your w32engin. > > > -- If you are running windows 2000 or XP. > > Yes, I'm using Windows 2000; CreateProcessWithLogonW is accessible > > And thank you for the example. > Unfortunately the function call fails and GetLastError() still returns > ERROR_INVALID_PARAMETER. > Do you have any idea? > Yes. I've already told you this is a Wide character (unicode) version of the function. So unless you are going to send it unicode strings, use CreateProcessWithLogonA instead. -- Derek
5. Re: CreateProcessWithLogonW
- Posted by "Derek Parnell" <ddparnell at bigpond.com> Mar 01, 2004
- 681 views
----- Original Message ----- From: "Derek Parnell" <ddparnell at bigpond.com> To: <EUforum at topica.com> Subject: Re: CreateProcessWithLogonW > > > ----- Original Message ----- > From: "Markus Schaller" <markus.schaller at web.de> > To: <EUforum at topica.com> > Subject: RE: CreateProcessWithLogonW > > > > > -- I have added the CreateProcessWithLogonW and constants to the > > > -- w32engin.ew version 6.40 which can be downloaded here: > > > http://www.rapideuphoria.com/w32engin.zip > > > > Thanks for adding this to your w32engin. > > > > > -- If you are running windows 2000 or XP. > > > > Yes, I'm using Windows 2000; CreateProcessWithLogonW is accessible > > > > And thank you for the example. > > Unfortunately the function call fails and GetLastError() still returns > > ERROR_INVALID_PARAMETER. > > Do you have any idea? > > > > Yes. I've already told you this is a Wide character (unicode) version of the > function. So unless you are going to send it unicode strings, use > CreateProcessWithLogonA instead. > > Sorry. That's what I get for reading my emails out of order. -- Derek