473,662 Members | 2,536 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Createprocess in VB.NET

Jai
Please provide sample code for using Createprocess in VB.NET. The code I am
using is given below. But I get "Error 91: Object referrence not set to an
instance of the object" at CreateProcess calling line. Please provide some
input.

CODE
====

Structure STARTUPINFO
Public cb As Long
Public lpReserved As String
Public lpDesktop As String
Public lpTitle As String
Public dwX As Long
Public dwY As Long
Public dwXSize As Long
Public dwYSize As Long
Public dwXCountChars As Long
Public dwYCountChars As Long
Public dwFillAttribute As Long
Public dwFlags As Long
Public wShowWindow As Long
Public cbReserved2 As Long
Public lpReserved2 As Long
Public hStdInput As Long
Public hStdOutput As Long
Public hStdError As Long
End Structure
Structure PROCESS_INFORMA TION
Public hProcess As Long
Public hThread As Long
Public dwProcessId As Long
Public dwThreadID As Long
End Structure

Private Declare Function CreateProcess Lib "kernel32" _
Alias "CreateProcessA " _
(ByVal lpAppName As String, _
ByVal lpCommandLine As String, _
ByVal lpProcessAttrib utes As Long, _
ByVal lpThreadAttribu tes As Long, _
ByVal bInheritHandles As Long, _
ByVal dwCreationFlags As Long, _
ByVal lpEnvironment As Long, _
ByVal lpCurrentDirect ory As Long, _
ByVal lpStartupInfo As STARTUPINFO, _
ByVal lpProcessInform ation As PROCESS_INFORMA TION) As Long
Private Declare Function WaitForSingleOb ject Lib "kernel32" (ByVal
hHandle As Long, ByVal dwMilliseconds As Long) As Long

Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As
Long) As Long

Private Declare Function GetExitCodeProc ess Lib "kernel32" (ByVal
hProcess As Long, ByVal lpExitCode As Long) As Long
Public Function RunProcess(ByVa l cmdline As String) As Long

Dim sNull As String

Dim proc As PROCESS_INFORMA TION
Dim start As STARTUPINFO

Dim ret As Long

start.cb = Len(start)

Dim lngRet As Long

lngRet = CreateProcess(0 &, cmdline, 0&, 0&, 1&, _
CREATE_NO_WINDO W, 0&, 0&, _
start, proc)

'Wait for the application to finish
ret& = WaitForSingleOb ject(proc.hProc ess, INFINITE)
Call GetExitCodeProc ess(proc.hProce ss, ret&)

'Close the handle to the process
Call CloseHandle(pro c.hProcess)

'Close the handle to the thread created
Call CloseHandle(pro c.hThread)
Exit Function

End Function
Jul 4 '06 #1
1 10837
"Jai" <Ja*@discussion s.microsoft.com wrote in message
news:71******** *************** ***********@mic rosoft.com...
Please provide sample code for using Createprocess in VB.NET. The code I
am
using is given below. But I get "Error 91: Object referrence not set to an
instance of the object" at CreateProcess calling line. Please provide some
input.
This is the Visual C++.NET newsgroup, you'll have to look elsewhere for VB
help. Furthermore, that looks like VB6, not VB.NET

For help calling Win32 API functions from .NET, try http://pinvoke.net

For example, here is the CreateProcess page with sample code:
http://pinvoke.net/default.aspx/kern...teProcess.html

>
CODE
====

Structure STARTUPINFO
Public cb As Long
Public lpReserved As String
Public lpDesktop As String
Public lpTitle As String
Public dwX As Long
Public dwY As Long
Public dwXSize As Long
Public dwYSize As Long
Public dwXCountChars As Long
Public dwYCountChars As Long
Public dwFillAttribute As Long
Public dwFlags As Long
Public wShowWindow As Long
Public cbReserved2 As Long
Public lpReserved2 As Long
Public hStdInput As Long
Public hStdOutput As Long
Public hStdError As Long
End Structure
Structure PROCESS_INFORMA TION
Public hProcess As Long
Public hThread As Long
Public dwProcessId As Long
Public dwThreadID As Long
End Structure

Private Declare Function CreateProcess Lib "kernel32" _
Alias "CreateProcessA " _
(ByVal lpAppName As String, _
ByVal lpCommandLine As String, _
ByVal lpProcessAttrib utes As Long, _
ByVal lpThreadAttribu tes As Long, _
ByVal bInheritHandles As Long, _
ByVal dwCreationFlags As Long, _
ByVal lpEnvironment As Long, _
ByVal lpCurrentDirect ory As Long, _
ByVal lpStartupInfo As STARTUPINFO, _
ByVal lpProcessInform ation As PROCESS_INFORMA TION) As Long
Private Declare Function WaitForSingleOb ject Lib "kernel32" (ByVal
hHandle As Long, ByVal dwMilliseconds As Long) As Long

Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As
Long) As Long

Private Declare Function GetExitCodeProc ess Lib "kernel32" (ByVal
hProcess As Long, ByVal lpExitCode As Long) As Long
Public Function RunProcess(ByVa l cmdline As String) As Long

Dim sNull As String

Dim proc As PROCESS_INFORMA TION
Dim start As STARTUPINFO

Dim ret As Long

start.cb = Len(start)

Dim lngRet As Long

lngRet = CreateProcess(0 &, cmdline, 0&, 0&, 1&, _
CREATE_NO_WINDO W, 0&, 0&, _
start, proc)

'Wait for the application to finish
ret& = WaitForSingleOb ject(proc.hProc ess, INFINITE)
Call GetExitCodeProc ess(proc.hProce ss, ret&)

'Close the handle to the process
Call CloseHandle(pro c.hProcess)

'Close the handle to the thread created
Call CloseHandle(pro c.hThread)
Exit Function

End Function


Jul 4 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
4998
by: Achim Domma | last post by:
Hi, I try to start a process on windows using win32process.CreateProcess and want to to redirect the output. I set the STARTF_USESTDHANDLES flag in the STARTUPINFO structure. But I can not figure out, how to get the pipes working. My app either deadlocks or displays the error messag: .... print win32file.ReadFile(readStdOut,10) pywintypes.error: (109, 'ReadFile', 'The pipe has been ended.')
6
9240
by: david.humpherys | last post by:
os:winnt python2.3.2 I have a exe that dumps info to the command line. I want to run this process and capture the stdout into a file. I think i'm close... any help appreciated. dh -------------------------------------------------------------------------- import win32process, win32file, win32security, win32con, win32api,
0
2044
by: ByteSize | last post by:
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)
1
1976
by: DOT NET JIM | last post by:
in VB6 the api declares the createprocess lbEnv var as any. When converted to ..NET is change the type any to Object. The problem is, what kind of object. I can not get the env variables set when excuting a process with createprocess. I dont know if its the fact that VB.NET doesnt support null terminated strings, or if its createprocess that is creating the problem. I need example code, executing an console/dos exe, in its own environment...
3
3462
by: kal | last post by:
Hi, I am trying to write an application that will launch a second application using CreateProcess... SECURITY_ATTRIBUTES sa; STARTUPINFO si; PROCESS_INFORMATION pi; ::ZeroMemory( &sa, sizeof(sa) );
5
7936
by: Stefano Camaiani | last post by:
Hello, please someone have the working code on how to call the CreateProcess API in Vb.Net? I need to call the CreateProcess API directly and i should not use the Vb.Net Process functions like dim MyProcess as new Process - MyProcess.Start This is my code wich i transalated from Vb6 to Vb.Net: <StructLayout(LayoutKind.Explicit, _ charset:=charset.auto)> _ Public Structure STARTUPINFO Public cb As Short
2
2011
by: Paul Schenk | last post by:
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)
1
2675
by: itmanager | last post by:
I am trying to create a process at a particular set of coordinates (for example 1,1) but the CreateProcess api seemingly ignores the settings in the dwX and dwY properties of the STARTUPINFO structure which I have initialized as follows: STARTUPINFO si; ZeroMemory((PVOID)&si, sizeof(si)); si.cb = sizeof(si); si.dwFlags = STARTF_USEPOSITION; si.dwX = 1;
6
4108
by: ss.teo | last post by:
I want to fork a new process and my executable binary is stored inside somewhere. Is there any possible way to fork a process using CreateProcess API without writing to the disk first? Like let's say I want to create a process from an array of bytes or memory stream containing the executable data cause I want to prevent my program executable module from being stolen..
0
8432
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8344
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8857
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8764
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8633
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5654
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4347
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2762
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1752
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.