RE: CreateProcessWithLogonW
- Posted by Markus Schaller <markus.schaller at web.de> Mar 01, 2004
- 629 views
Hi Some time ago I wrote that this code doesn't work (GetLastError() returns 87). Now I found the problem. Against the documentation at http://msdn.microsoft.com/ CurrentDirectory must not be "". Just giving it a valid value, like lpCurrentDirectory = szW("C:\\WINNT") fixes the program. Now it works fine Greetings Markus Schaller > -- > ---- 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 ----