CreateProcessWithLogonW

B

Bilal Dinc

Hey, I have a question concerning the CreateProcessWithLogonW function
imported from the advapi32 dll. For some reason I cant get the appName
and cmdLine paramters to work together. For example, I'm trying to use
the Perforce command line utility (p4.exe) to download some files to the
local computer. So I set appName="p4.exe" and cmdLine="print -o
\"c:\\file.txt\" -q \"//depot/files/file.txt\"". So then I call
CreateProcessWithLogonW(username, domain, password,
LogonFlags.LOGON_WITH_PROFILE, appName, cmdLine,
CreationFlags.CREATE_DEFAULT_ERROR_MODE, IntPtr.Zero, null, ref si, out
pi), which runs fine (return non 0) but the file never downloads. The
only workaround I have been able to find so far is to create a console
app and use the process class as:
Process.Start("p4.exe", "print -o \"c:\\file.txt\" -q
\"//depot/files/file.txt\""). Then passing the path of the executable
that gets created to the CreateProcessWithLogonW function as the appName
paramter with cmdLine=null:
CreateProcessWithLogonW(username, domain, password,
LogonFlags.LOGON_WITH_PROFILE, ConsoleExePath, null,
CreationFlags.CREATE_DEFAULT_ERROR_MODE, IntPtr.Zero, null, ref si, out
pi), which works. But this is obviously not a desirable solution since I
would have to create a console app everytime i wanted to download a file
from Perforce from a web app. Any ideas on what I'm doing wrong with the
appName and cmdLine paramters, or anyone know what functions get called
in CreateProcessWithLogonW or how it works so I can possibly try to
duplicate it? Thanks in advance for any help...
 
W

Willy Denoyette [MVP]

Think of this: Who established the network credentials for the network share
("//depot/files)?

- When using a console application, p4.exe runs in the security context of
the interactive logon user (I assume the one that established the network
credentials for "//depot/files"). The result is that p4.exe can access the
file on the share.
- When using CreateProcessWithLogonW you effectively created a new logon
session, this one has no access to the share, even if the same credentials
are used as the interactive logon user.
The result is that p4.exe cannot access the file on the share.

Your only option to solve this, is to establish a network connection for the
new logon session.

Willy.
 
J

Jeffrey Tan[MSFT]

Hi Bilal,

I think Willy's reply makes some sense to you. Is your problem resolved?
If you still have anything unclear, please feel free to tell me. I will
work with you.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
G

Guest

Hello Willy

I came across some of your code on a different site, and I had one question about the marshalling. In C# implementation of the CreateProcessWithLogonW code, the "out" parameter is used, I'm thinking because we want to retrieve a handle to the process from the unmanaged side. Is there an equivalent in VB.NET? Would that just be ByRef? My VB.net code seems to be failing when I use byref

Result = CreateProcessWithLogonW(
lpUsername,
lpdomainname,
lpPassword,
LOGON_NETCREDENTIALS_ONLY,
vbNullString,
CommandLine,
NORMAL_PRIORITY_CLASS Or CREATE_UNICODE_ENVIRONMENT,
IntPtr.Zero,
vbNullString,
pStartInfo, pProcessInfo

The Win32 error returned is file not found. Any ideas?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top