.NETGURU
CreateProcess problems in vb.NET
Messages   Related Types
This message was discovered on microsoft.public.dotnet.languages.vb.upgrade.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
Post a new message to this list...

Paul Schenk
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.

Reply to this message...
 
    
Herfried K. Wagner [MVP] (VIP)
* "Paul Schenk" <Click here to reveal e-mail address> scripsit:
[Original message clipped]

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

Post your declare of 'CreateProcess'.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Reply to this message...
 
    
Paul Schenk
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.

[Original message clipped]

Reply to this message...
 
 
System.Diagnostics.ProcessStartInfo




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification