Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

spawn app so that it's not part of the process tree

Status
Not open for further replies.

ColdPhreze

Programmer
Apr 15, 2002
93
Ok. I'm writing a VB.NET app. One part of the app needs to be able to run another program. This other program must not be a part of the process tree. What I mean by this, is if I go into Task Manager and right click my program and then click "End Process Tree", only my program should end, not the other application I started.

So far I have tried the following, but all of them make the spawned program part of my program's Process Tree:
'Test 1
Dim explorerHwnd = FindWindow("", "Explorer")
Call ShellExecute(explorerHwnd, "Open", strPath + "\" _
+ AppFileName, "", "", SW_RESTORE)

'Test 2
Shell(strPath + "\" + AppFileName)

'Test 3
System.Diagnostics.Process.Start(strPath + "\" + _
AppFileName)


Can anyone help?

Thanks, KyferEz

Check out my DeVry Senior Project: and my CarPC Hardware: and my Spam-Fighter forums:
 
Rick,

That does not work for several reasons:
1) process.start does not start the command window when you try to pass it command line parameters.
2) I don't understand what you were trying to do with ""start " and those 3 quotes at the end, but VB.NET does not like it.

Because of #1 above, I tried it using coded like:
Shell("cmd /C " & ControlChars.Quote & strPath & "\" _
& AppFileName & ControlChars.Quote)

That still does not work for the following 2 reasons:
1) The command window does not close
2) The application I am attempting to start still is connected to my main program. Thus if I do "End Process Tree" on my main program, the application my program loaded is also killed. I assume this is because adding cmd created a branch to the tree, but did not create a new tree: the tree has a branch of my app, a branch off that to cmd, and a branch off cmd to the new app. Close cmd, and the branches still connect from my app to the new app. Grrr.

So after hours of googling, I finally found a solution:

I am now doing the following, and it works perfectly:
Shell(strPath + "\" + "runexe.exe " + strPath + "\" _
+ AppFileName)

KyferEz

Check out my DeVry Senior Project: and my CarPC Hardware: and my Spam-Fighter forums:
 
1) process.start does not start the command window when you try to pass it command line parameters.

It doesn't need to. That code line is from the faq faq796-5569. It allows Windows to determine the launching of an application

2) I don't understand what you were trying to do with ""start " and those 3 quotes at the end, but VB.NET does not like it.

Three quotes (""") will result in a string that contains a single quote (").

so, "cmd /c ""start " & FilePathAndName & """ will create the string: cmd /c "start MyFile.ext"

cmd /c launches the process in a new cmd environment and start tells windows to resolve the application call. Which is just a fancy (and built into windows) way to do what runexe.exe does.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Ok, I thought that might be what the 3 quotes did, but it wasn't liking it when I pasted it in VB.

I looked at your FAQ. I created a new vb project. I pasted the following line into a button onclick event:
System.Diagnostics.Process.Start("cmd /c _
""start
I get an unhandled exception "The System cannot find the file specified"

So I tried it like:
System.Diagnostics.Process.Start("cmd /c _
""start c:\windows\system32\notepad.exe""")

I verified that was the correct path to notepad by copy-paste into run dialog before running the code. The program still threw the same error.

I would prefer to use your method, can't seem to make it work.

I am on VB.NET 2003, WinXP SP2, if that helps. I have noticed some changes in how VB.NET programs handle certain commands from WinXP SP1 to WinXP SP2...

KyferEz

Check out my DeVry Senior Project: and my CarPC Hardware: and my Spam-Fighter forums:
 
Interesting, I'll have to pull up that old program and give that a try again. My box at work is Win XP sp2 with VS.Net 2k2. The quick test works on my home PC (Win XP sp2):

Hit [Windows]-R to open the Windows Run dialog.
Type in cmd /c "start .
Hit [Enter].

If you have your default browser open, it should redirect to google, if you don't have your default browser open, it should open and go to google. Works just as well if you replace with mspaint

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Did you try replacing the double quotes with single quotes?

SWM Programmer Seeking 3d Modeling work. Either for long term commitment or just friendship. Likes long hours in front of a flat screen with heavy doses of Mountain Dew.
 
This is what I use in a .net 2003 app running on WinXPsp2 clients. I can close my application without it affecting the app that was run from the cmd 'str'

Code:
Dim str As String
str = """C:\Program Files\contacts\" & myApp & """ " & myDB & " rcs " & myAppUser & " " & myPwd

Try
  Call Shell(str, AppWinStyle.NormalFocus, False)
Catch ex As Exception
  MsgBox(ex.Message)
  Exit Function
End Try

The myApp, myDb etc are all cmdline arguments.

Hope this helps - I've used the process.start method to launch launch a URL. Can't remember why I chose a different method here - may be significant.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top