all groups > vb.net upgrade > june 2004 >
You're in the

vb.net upgrade

group:

CreateProcess problems in vb.NET


CreateProcess problems in vb.NET Paul Schenk
6/21/2004 6:47:17 AM
vb.net upgrade:
Hi All :)

Would be grateful of advice please. I have code in VB6
working as follows:

lngReply = CreateProcess(sNull, txtStart, ByVal 0&,
ByVal 0&, 1&, NORMAL_PRIORITY_CLASS, ByVal 0&, sNull,
sInfo, pInfo)

but alas, the 'equivelant' vb.Net code translated as:


lngReply = CreateProcess(sNull, txtStart.Text, sa,
sa, 1, NORMAL_PRIORITY_CLASS, 0, sNull, sInfo, pInfo)


does not execute cleanly. That is, although the
CreateProcess returns 'successfully', and populates the
sInfo structure with valid data, the application (e.g.
c:\windows\notepad.exe) 'fails during initialisation' and
terminates.

The only 'meaningful' difference between the working vb6
and non-working vb.net code, is the substitution of
vb6's 'As Any' Win32API declaration parameterss with 'AS
Securities_Attributes' structures, which I have defined
thus:

Structure SECURITY_ATTRIBUTES
Dim nLength As Integer
Dim lpSecurityDescriptor As Integer
Dim bInheritHandle As Integer
End Structure

and are passed-in called 'sa', as noted above.

Please, can someone offer either a correction for my
error, or a good code example / reference for calling
CreateProcess from vb.net.

NB: I need to use CreateProcess rather than the Process
component that is available in the managed code, as I
need to set some 'lower level' start info parameters
(i.e. the lpDesktop setting), which I can only get at
using the API directly :(

Many Thanks in advance,
Paul.
Re: CreateProcess problems in vb.NET Paul Schenk
6/21/2004 8:11:40 AM
Dear Herfried,

Many thanks for your reply.

I need to get to the lpDesktop parameter of the STARTINFO
class - but this is not exposed in the 'managed
wrappers', so sadly, as I need to launch interactive
processes out of a windows service application, i have to
resort to the sordid business of the api ;-)

My working vb6 code is as follows:

API Declaration:

Private Declare Function CreateProcess Lib "kernel32"
Alias "CreateProcessA"
(ByVal lpApplicationName As String, ByVal lpCommandLine
As String, lpProcessAttributes As Any, lpThreadAttributes
As Any, ByVal bInheritHandles As Long, ByVal
dwCreationFlags As Any, lpEnvironment As Any, ByVal
lpCurrentDriectory As String, lpStartupInfo As
STARTUPINFO, lpProcessInformation As
PROCESS_INFORMATION) As Long

Function Call:
lngReply = CreateProcess(sNull, txtStart, ByVal 0&, ByVal
0&, 1&, NORMAL_PRIORITY_CLASS, ByVal 0&, sNull, sInfo,
pInfo)


This works just as desired, without problem.

The vb.net 'upgrade / migration' wizard converts the code
to as follows:


Private Declare Function CreateProcess Lib "kernel32"
Alias "CreateProcessA" (ByVal lpApplicationName As
String, ByVal lpCommandLine As String, ByRef
lpProcessAttributes As SECURITY_ATTRIBUTES, ByRef
lpThreadAttributes As SECURITY_ATTRIBUTES, ByVal
bInheritHandles As Integer, ByVal dwCreationFlags As
Integer, ByRef lpEnvironment As Object, ByVal
lpCurrentDriectory As String, ByRef lpStartupInfo As
STARTUPINFO, ByRef lpProcessInformation As
PROCESS_INFORMATION) As Integer

NB: The lpEnvironment used to be an 'As Any' parameter, I
have tried it out as an object, as a string and as an
integer - all to no avail.

The function call I use is:

lngReply = CreateProcess(sNull, txtStart.Text, sa, sa, 1,
NORMAL_PRIORITY_CLASS, 0, sNull, sInfo, pInfo)

I know this is cheeky, but unless you can see a directly
observable error in my code, and if you believe that
CreateProcess can work in vb.net, please, all I need is
one simple self contained "hello world" example of vb.net
code that will work in isolation, successfully employing
a call to CreateProcess. I don't need my specific problem
fixing in my context - I am happy to apply the general to
my own specific needs - but as yet THERE HAS BEEN NO
EXAMPLE AT ALL in vb.net where CreateProcess executes
cleanly !

Please know that I appreciate your or anyones valuable
time and effort on my behalf in this instance. I have to
say, a sucesffuly answer though would be a treasure -
simply because as yet one does not seem to exist on the
internet.

Many many thanks in advance,
Paul.




[quoted text, click to view]
Re: CreateProcess problems in vb.NET hirf-spam-me-here NO[at]SPAM gmx.at
6/21/2004 4:18:35 PM
* "Paul Schenk" <pas@rttracking.com> scripsit:
[quoted text, click to view]

Did you have a look at the 'Process' and 'ProcessStartInfo' classes?

Post your declare of 'CreateProcess'.

--
Herfried K. Wagner [MVP]
AddThis Social Bookmark Button