By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,903 Members | 1,670 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,903 IT Pros & Developers. It's quick & easy.

CreateProcessWithLogonW

P: n/a
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...

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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.

"Bilal Dinc" <bd***@factset.com> wrote in message
news:ek**************@TK2MSFTNGP10.phx.gbl...
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...

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 15 '05 #2

P: n/a
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?
Nov 15 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.