CreateProcessWithLogonW

new topic     » topic index » view thread      » older message » newer message

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 ----

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu