473,574 Members | 17,993 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Attach process

Hi there,

I am trying to develop a small menu application to run on an RF network, we
are using a wavelink server to communicate with our rf scanners and run
VB.NET applications on our server that repond to the scanner requests. I
would like to know if there is a way that I can spawn a process on the
server and attach it to the current thread (allow it to take control of the
server requests)? Once this spawned app exits it will return control back to
the exe (menu) that fired it.

Example:

Scanner connect to Server on port xxxx
Wavelink server fires ...\MenuApp.exe on connection to handle the requests.

MenuApp responds with some options to the RF screen.
1) App 1, ...\App1.exe
2) App 2, ...\App2.exe

App 1 selected by user.
Menu app fires App1.exe on the server and tells it to receive and respond to
future requests.
App1 exits.
MenuApp takes control again and gives the user options 1) and 2)

Any help would be appreciated.

Thanks
Devron
Nov 20 '05 #1
7 5068
Hi Devron,

Thanks for posting in the community.

First of all, I would like to confirm my understanding of your issue.
Since I am not farmilar with RF network, here I reword your senario as
below.

You have an VB.NET app which is waiting for connection form an client, once
the a client sent a request to the VB.NET application, you hope the VB.NET
application will spawn a new process to attach to the current thread. Is
the attach you mean here to run current thread in the new spawned process?

Have I fully understood you? If there is anything I misunderstood, please
feel free to let me know.

Based on knowledge, we can not attach another process to current thread.
In this senario, I think you may try to spawn a new process and pass the
necessary arguments to the process. I suggest you create a new thread to
handle the connection, this will prevent the IPC.

Threading Tutorial
http://msdn.microsoft.com/library/de...us/csref/html/
vcwlkthreadingt utorial.asp

MultiThread Port Scanner
http://www.gotdotnet.com/Community/U...mpleGuid=02c6e
0e2-c596-46e6-8aad-716161dda8e6

If you have any concern on this issue, please post here.
Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 20 '05 #2
Yes you are on the right track. The new spawned process should handle all
future requests until it exits. I have read that this can be done somehow by
the new spawned process inheriting the handles of the existing process but
have been unable to find any examples on this.

Any more help would be appreciated.

Thanks
Devron

"Peter Huang" <v-******@online.m icrosoft.com> wrote in message
news:R3******** ******@cpmsftng xa07.phx.gbl...
Hi Devron,

Thanks for posting in the community.

First of all, I would like to confirm my understanding of your issue.
Since I am not farmilar with RF network, here I reword your senario as
below.

You have an VB.NET app which is waiting for connection form an client, once the a client sent a request to the VB.NET application, you hope the VB.NET
application will spawn a new process to attach to the current thread. Is
the attach you mean here to run current thread in the new spawned process?
Have I fully understood you? If there is anything I misunderstood, please
feel free to let me know.

Based on knowledge, we can not attach another process to current thread.
In this senario, I think you may try to spawn a new process and pass the
necessary arguments to the process. I suggest you create a new thread to
handle the connection, this will prevent the IPC.

Threading Tutorial
http://msdn.microsoft.com/library/de...us/csref/html/ vcwlkthreadingt utorial.asp

MultiThread Port Scanner
http://www.gotdotnet.com/Community/U...mpleGuid=02c6e 0e2-c596-46e6-8aad-716161dda8e6

If you have any concern on this issue, please post here.
Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 20 '05 #3
I think the inheriting of the handle is somehow done via the CreateProcess
API.

Thanks
Devron

"Devron Blatchford" <de****@auspine .com.au> wrote in message
news:O$******** ******@TK2MSFTN GP12.phx.gbl...
Yes you are on the right track. The new spawned process should handle all
future requests until it exits. I have read that this can be done somehow by the new spawned process inheriting the handles of the existing process but
have been unable to find any examples on this.

Any more help would be appreciated.

Thanks
Devron

"Peter Huang" <v-******@online.m icrosoft.com> wrote in message
news:R3******** ******@cpmsftng xa07.phx.gbl...
Hi Devron,

Thanks for posting in the community.

First of all, I would like to confirm my understanding of your issue.
Since I am not farmilar with RF network, here I reword your senario as
below.

You have an VB.NET app which is waiting for connection form an client,

once
the a client sent a request to the VB.NET application, you hope the VB.NET application will spawn a new process to attach to the current thread. Is
the attach you mean here to run current thread in the new spawned

process?

Have I fully understood you? If there is anything I misunderstood, please feel free to let me know.

Based on knowledge, we can not attach another process to current thread.
In this senario, I think you may try to spawn a new process and pass the
necessary arguments to the process. I suggest you create a new thread to
handle the connection, this will prevent the IPC.

Threading Tutorial

http://msdn.microsoft.com/library/de...us/csref/html/
vcwlkthreadingt utorial.asp

MultiThread Port Scanner

http://www.gotdotnet.com/Community/U...mpleGuid=02c6e
0e2-c596-46e6-8aad-716161dda8e6

If you have any concern on this issue, please post here.
Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no

rights.


Nov 20 '05 #4
Here is a snapshot of an example I have found in C++, can someone please
help me port this to VB.NET?

secAttribs.nLen gth = sizeof (SECURITY_ATTRI BUTES);
secAttribs.lpSe curityDescripto r = NULL;
secAttribs.bInh eritHandle = TRUE;

//Set up application arguments
memset(szBuffer , 0, sizeof(szBuffer ));
argStrm << (char*)appIface->Path ();
argStrm << " ";
argStrm << (char*)appIface->Args ();

memset((void*)& sisInfo, 0, sizeof(STARTUPI NFO));
sisInfo.cb = sizeof(STARTUPI NFO);

std::string newDirectory = appIface->Path ();
int slashNdex = newDirectory.fi nd_last_of ('\\');

//Change current directory if needed.
if(slashNdex >= 0)
{
newDirectory = newDirectory.su bstr (0, slashNdex);
SetCurrentDirec tory(newDirecto ry.data());
}//end if(slashNdex >= 0)

//Spawn child process.
process = CreateProcess(a ppIface->Path (), szBuffer, &secAttribs,
&secAttribs, TRUE, DETACHED_PROCES S,
NULL, NULL, &sisInfo, &piPInfo);

//Display an error if CreateProcess fails
if(!process)
{
errState->ClearError ();
errState->SetErrorLine ("Error Starting App");
errState->SetNextState (MENU);
}//end if(!process)

//Loop while spawned process is executing.
while (GetExitCodePro cess (piPInfo.hProce ss , &dwResult) && (dwResult ==
STILL_ACTIVE))
Sleep(1000);

//Delete __WLPM__ menu
mnuIface->DeleteMenu ("__WLPM__") ;

//After process exits return to MenuSt8.
return nextState;
}

void CMenuSt8::SetEr rorState ()
{
CErrorSt8* errState = (CErrorSt8*)par entMachine->ParseStateLi st
(ERRORSTATE);

errState->ClearError ();
errState->SetErrorLine (" User has no ");
errState->SetErrorLine (" applications ");
errState->SetNextState (SIGNON);
exitState = true;
nextState = ERRORSTATE;
}


"Devron Blatchford" <de****@auspine .com.au> wrote in message
news:Om******** ******@TK2MSFTN GP10.phx.gbl...
I think the inheriting of the handle is somehow done via the CreateProcess
API.

Thanks
Devron

"Devron Blatchford" <de****@auspine .com.au> wrote in message
news:O$******** ******@TK2MSFTN GP12.phx.gbl...
Yes you are on the right track. The new spawned process should handle all
future requests until it exits. I have read that this can be done somehow
by
the new spawned process inheriting the handles of the existing process

but have been unable to find any examples on this.

Any more help would be appreciated.

Thanks
Devron

"Peter Huang" <v-******@online.m icrosoft.com> wrote in message
news:R3******** ******@cpmsftng xa07.phx.gbl...
Hi Devron,

Thanks for posting in the community.

First of all, I would like to confirm my understanding of your issue.
Since I am not farmilar with RF network, here I reword your senario as
below.

You have an VB.NET app which is waiting for connection form an client,

once
the a client sent a request to the VB.NET application, you hope the

VB.NET application will spawn a new process to attach to the current thread. Is the attach you mean here to run current thread in the new spawned

process?

Have I fully understood you? If there is anything I misunderstood, please feel free to let me know.

Based on knowledge, we can not attach another process to current thread. In this senario, I think you may try to spawn a new process and pass the necessary arguments to the process. I suggest you create a new thread to handle the connection, this will prevent the IPC.

Threading Tutorial

http://msdn.microsoft.com/library/de...us/csref/html/
vcwlkthreadingt utorial.asp

MultiThread Port Scanner

http://www.gotdotnet.com/Community/U...mpleGuid=02c6e
0e2-c596-46e6-8aad-716161dda8e6

If you have any concern on this issue, please post here.
Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no

rights.



Nov 20 '05 #5
In article <u9************ **@tk2msftngp13 .phx.gbl>, Devron Blatchford wrote:
Hi there,

I am trying to develop a small menu application to run on an RF network, we
are using a wavelink server to communicate with our rf scanners and run
VB.NET applications on our server that repond to the scanner requests. I
would like to know if there is a way that I can spawn a process on the
server and attach it to the current thread (allow it to take control of the
server requests)? Once this spawned app exits it will return control back to
the exe (menu) that fired it.

Example:

Scanner connect to Server on port xxxx
Wavelink server fires ...\MenuApp.exe on connection to handle the requests.

MenuApp responds with some options to the RF screen.
1) App 1, ...\App1.exe
2) App 2, ...\App2.exe

App 1 selected by user.
Menu app fires App1.exe on the server and tells it to receive and respond to
future requests.
App1 exits.
MenuApp takes control again and gives the user options 1) and 2)

Any help would be appreciated.

Thanks
Devron


Devron,

I've been reading through this a little and I'm having a hard time
understanding why the apps have to be a separate process?

I think the best way to do this is using threads. You could implement
the various options as dll's (like plugins) that implement a simple
interface. The menu option just sets what dll to use to process
requests.

That way, you would have the ability to expand the implementation, and
not incure the problems/performance drawbacks of doing this using
interprocess communication.

If for some reason, you feel this must be done as separate applications,
then I would consider making them console apps. Then you could use the
System.Diagnost ics.Process class to spawn the process, and redirect the
console programs stdin and stdout. Then, the server would just read and
write to the console application which would process the requests.

--
Tom Shelton [MVP]
OS Name: Microsoft Windows XP Professional
OS Version: 5.1.2600 Service Pack 1 Build 2600
System Up Time: 0 Days, 14 Hours, 23 Minutes, 25 Seconds
Nov 20 '05 #6
Hi Devron,

Thanks for your quickly reply!

Here I write an interop code to call CreateProcess in VB.NET.

<StructLayout(L ayoutKind.Seque ntial)> Public Structure
SECURITY_ATTRIB UTES
Public nLength As Integer
Public lpSecurityDescr iptor As Integer
Public bInheritHandle As Integer
End Structure
<StructLayout(L ayoutKind.Seque ntial)> Public Structure STARTUPINFO
Public cb As Integer
Public lpReserved As String
Public lpDesktop As String
Public lpTitle As String
Public dwX As Integer
Public dwY As Integer
Public dwXSize As Integer
Public dwYSize As Integer
Public dwXCountChars As Integer
Public dwYCountChars As Integer
Public dwFillAttribute As Integer
Public dwFlags As Integer
Public wShowWindow As Integer
Public cbReserved2 As Integer
Public lpReserved2 As Integer
Public hStdInput As Integer
Public hStdOutput As Integer
Public hStdError As Integer
End Structure
<StructLayout(L ayoutKind.Seque ntial)> Public Structure
PROCESS_INFORMA TION
Public hProcess As Integer
Public hThread As Integer
Public dwProcessId As Integer
Public dwThreadId As Integer
End Structure
Public Declare Function CreateProcess Lib "kernel32" Alias
"CreateProcessA " (ByVal lpApplicationNa me As String, ByVal lpCommandLine As
String, <MarshalAs(Unma nagedType.Struc t)> ByRef lpProcessAttrib utes As
SECURITY_ATTRIB UTES, <MarshalAs(Unma nagedType.Struc t)> ByRef
lpThreadAttribu tes As SECURITY_ATTRIB UTES, ByVal bInheritHandles As
Integer, ByVal dwCreationFlags As Integer, ByVal lpEnvironment As Integer,
ByVal lpCurrentDriect ory As String, <MarshalAs(Unma nagedType.Struc t)> ByRef
lpStartupInfo As STARTUPINFO, <MarshalAs(Unma nagedType.Struc t)> ByRef
lpProcessInform ation As PROCESS_INFORMA TION) As Integer
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim saProcess As SECURITY_ATTRIB UTES
Dim saThread As SECURITY_ATTRIB UTES
saProcess.bInhe ritHandle = True
saProcess.lpSec urityDescriptor = 0
saProcess.nLeng th = Marshal.SizeOf( saProcess)
saThread.bInher itHandle = True
saThread.lpSecu rityDescriptor = 0
saThread.nLengt h = Marshal.SizeOf( saThread)
Dim pi As PROCESS_INFORMA TION
Dim si As STARTUPINFO
CreateProcess(" C:\WINDOWS\syst em32\notepad.ex e", " C:\test.txt",
saProcess, saThread, True, 0, Nothing, vbNullString, si, pi)
End Sub

I agree with Tom's suggestion.
From you code snipper, it seems that when you create a new child process,
the parent process will wait. That is to say the programming modal is
synchronized, so did you have any concern why you do need to create a new
process but not a thread or just do the thing in the same process.
As Tom said, in .NET you can redirect an process's stdin and stdout to do
the IPC stuff which will help you avoid the P/Invoke stuff.

In ASP.NET, as a webserver, the server application will get the request and
write the request to a named pipe and the spawned child process will read
the request from the named pipe and write the response to the parent
process by the named pipe too. But this will cause many IPC operation. So I
strongly recomment you deal with the request in the current thread, since
it seems that you do not need multiple thread function. If you wants to
separate the code that handles the request by create a new classlibrary.
Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 20 '05 #7
Thanks for your responses,

I like the idea of creating the applications as classes/dll's and
registering them. I have tried this and got the desired result.

Thanks again for you suggestions and help.

Devron
"Tom Shelton" <to*@mtogden.co m> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
In article <u9************ **@tk2msftngp13 .phx.gbl>, Devron Blatchford

wrote:
Hi there,

I am trying to develop a small menu application to run on an RF network, we are using a wavelink server to communicate with our rf scanners and run
VB.NET applications on our server that repond to the scanner requests. I
would like to know if there is a way that I can spawn a process on the
server and attach it to the current thread (allow it to take control of the server requests)? Once this spawned app exits it will return control back to the exe (menu) that fired it.

Example:

Scanner connect to Server on port xxxx
Wavelink server fires ...\MenuApp.exe on connection to handle the requests.
MenuApp responds with some options to the RF screen.
1) App 1, ...\App1.exe
2) App 2, ...\App2.exe

App 1 selected by user.
Menu app fires App1.exe on the server and tells it to receive and respond to future requests.
App1 exits.
MenuApp takes control again and gives the user options 1) and 2)

Any help would be appreciated.

Thanks
Devron


Devron,

I've been reading through this a little and I'm having a hard time
understanding why the apps have to be a separate process?

I think the best way to do this is using threads. You could implement
the various options as dll's (like plugins) that implement a simple
interface. The menu option just sets what dll to use to process
requests.

That way, you would have the ability to expand the implementation, and
not incure the problems/performance drawbacks of doing this using
interprocess communication.

If for some reason, you feel this must be done as separate applications,
then I would consider making them console apps. Then you could use the
System.Diagnost ics.Process class to spawn the process, and redirect the
console programs stdin and stdout. Then, the server would just read and
write to the console application which would process the requests.

--
Tom Shelton [MVP]
OS Name: Microsoft Windows XP Professional
OS Version: 5.1.2600 Service Pack 1 Build 2600
System Up Time: 0 Days, 14 Hours, 23 Minutes, 25 Seconds

Nov 20 '05 #8

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

Similar topics

4
1739
by: donall | last post by:
i have a DLL which implements a HTTP handler, written in C#, and have deployed it on IIS 5.0, on XP service pack 2. six months ago, i was able to debug it by attaching CLR to the process (aspnet_wp.exe). now i can't attach to the process any more. when i select the process from the list, and then select to attach the CLR, i just get a dialog...
9
6933
by: ME | last post by:
I have a application that someone else has wrote that runs in a console window. It does not take parameters, but when running it asks three questions and then exits. I would like to write a small utility to attach to the console app, send the necessary answers (typically typing the letter "y" and enter) and then leave. Is this a possiblity...
1
2093
by: Martin Simard | last post by:
Hi all, In VS 2003, when I attach to a remote process for debugging, I can see the list of modules loaded by the process before attaching to it. This list is not there anymore in VS 2005. Instead, I just have a warning for security reasons and 2 buttons (Attach | Don't attach). Let me explain a bit... I have several web applications...
1
2137
by: SenthilVel | last post by:
Hi I have a question when debugging dotnet code when attaching vb6.exe code to this process. i get an error like : unable to attach the process. there is no managed code running in the process. INorder to attach a process with the .NET Debugger, managed code must be running in the process before attaching.
5
2246
by: Kees de Winter | last post by:
Is it possible to attach the VS2005 debugger to an already running, and published website? If I choose "Attach to process" from the menu and then select the right process, set breakpoints, run the code, nothing happens. Thanks for your help. -- Kees
0
1336
by: Samuel R. Neff | last post by:
How can I attach the active debugger to a newly launched process? For example, what goes in the if statement in the following code: Process process = new Process(); process.StartInfo.FileName = path; process.StartInfo.WorkingDirectory = Path.GetDirectoryName(path); process.StartInfo.RedirectStandardInput = true;...
3
5419
by: =?Utf-8?B?QW5kcmV3?= | last post by:
Hello, friends, I am using .net 2005 to develope a web service based application. When accessing web services from client side, I always attach aspnet process to have a step by step debugging. However, for some unknown reason, this process disappeared in Available Processes list of Attach to Process window. Any ideas? How to make it...
0
3132
by: DR | last post by:
Unable to start TSQL Debugging. Could not attach to SQL Server Process on 'srvname'. The RPC server is unavailable. I get this error when I try to run a SQL Server Project with a CLR stored Procedure in it. The target DB is SQL Server 2005 and im using VS 2005. I simply create a new SQL Server Project which creates a Test.sql, i then simply...
6
3217
by: GaryDean | last post by:
I see some references on debugging by attaching to a process. There are MSDN articles that show how to attach to a process for debugging. However, I can find no info on how exactly to get the debugging to work. I have a wizard page in the anonymous section of my website. If I run it as the startup page in VS it runs fine. But if I link...
0
7738
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...
0
8081
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. ...
0
8258
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...
1
7835
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8121
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...
0
6486
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5635
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
1
2255
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
1
1360
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.