but these code don't accepts parameters, so I modified it to accept params

Code: Select all
Procedure Runas2(Username.s, Domain.s, Password.s, program.s, parameters.s)
program = program + " " + Chr(34) + parameters + Chr(34)
*lpUserName = AllocateMemory(1000)
*lpDomainName = AllocateMemory(1000)
*lpPassword = AllocateMemory(1000)
*lpApplication = AllocateMemory(1000)
*lpCommandLine = AllocateMemory(1000)
lpProcessInfo.PROCESS_INFORMATION
lpStartUpInfo.STARTUPINFO
;convert ansi strings to unicode
MultiByteToWideChar_(#CP_ACP, 0, Username, -1, *lpUserName, 1000)
MultiByteToWideChar_(#CP_ACP, 0, Domain, -1, *lpDomainName, 1000)
MultiByteToWideChar_(#CP_ACP, 0, Password, -1, *lpPassword, 1000)
MultiByteToWideChar_(#CP_ACP, 0, program, -1, *lpApplication, 1000)
If OpenLibrary(0, "ADVAPI32.DLL")
*F = GetFunction(0, "CreateProcessWithLogonW")
If *F
If CallFunctionFast(*F, *lpUserName, *lpDomainName, *lpPassword, 0, 0,*lpApplication,0,0,0,@lpStartUpInfo,@lpProcessInfo) = 0
Buffer.s = Space(200)
LastError.l = GetLastError_()
FormatMessage_(#FORMAT_MESSAGE_FROM_SYSTEM, 0, LastError, #LANG_NEUTRAL, @Buffer, 200, 0)
MessageRequester("Error",Str(LastError)+" "+Buffer,0)
EndIf
Else
MessageRequester("","Sorry - This function is not available.",0)
EndIf
CloseLibrary(0)
EndIf
EndProcedure
;Example
username.s = "zikitrake"
domain.s = "." ; . for local user
pwd.s = "tarari"
Runas2(username, domain, pwd, "YourProgram.EXE" , "param1 param2 param3")