Question

Hey gyuz! I wrote a little program that runs any other program you want throuh a contextmenustrip.The program adds a notify icon in the tray and you can access the menu through there.All the programs you add are saved in the registry for calling them. I used the AddHandler to create a new ToolStripMenuItem each time i add a new program. But here is my question .. when running a program:

I used : Process.Start(RegistryKey.GetValue(sender.tostring) and

Shell(RegistryKey.GetValue(sender.Tostring),AppWinStyle.NormalFocus,False)

The Process.Start works fine. The Shell throws the File Not Found Exception.

I don't why!

[653 byte] By [de_Stan] at [2007-12-25]
# 1

Are you using the full path to the program?

Jonathan

JonathanAllen at 2007-9-3 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 2
Of course! The Process.Start works or else it wouldn't.
de_Stan at 2007-9-3 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 3
you are best to use the Process class and use the .NET classes :-)
ahmedilyas at 2007-9-3 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 4

Number one, Process.Start may well work without a full path depending on windows environment variables

Number two, Shell can't have spaces in the path unless the path is wrapped in double quotes. Have you quoted your path strings?

Number three, don't use Shell!

rkimble at 2007-9-3 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 5

This is not correct

http://msdn2.microsoft.com/en-us/library/microsoft.visualbasic.interaction.shell.aspx

Shell will only work with an Executable, process.Start will determine the executable based upon a file and its associated application.

Create an file called c:\test.txt

and then try the following two line

Process.Start("C:\Test.txt")

Shell("C:\Test.txt")

You will notice the first statement will display the file contents in notepad - the default application for txt files.

The second will produce a

A first chance exception of type 'System.IO.FileNotFoundException' occurred in Microsoft....

because it is not an executable

I would definately advise on using the process.start as the solution is a .NET managed assembly and not a VB specific method.

spotty at 2007-9-3 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 6

But Spotty - the OP said they are only launching other programs, so Shell should work fine.

Surely the failure is related to there being spaces in the file path...

changing the code to:

Shell(controlchars.quote & RegistryKey.GetValue(sender.Tostring) & controlchars.quote,AppWinStyle.NormalFocus,False)

should fix it...

rkimble at 2007-9-3 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 7

Hmm... in addition to paths with spaces possibly causing problems, there are also some executable types that don't work, such as 16bit apps - and I get the same failure on a windows installer setup.exe.

But calling other .NET programs works if the path is valid.

I guess the lack of support for certain types of programs is another strong reason not to use Shell.

So the OPs problem may be with the types of applications being called more than anything.

rkimble at 2007-9-3 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 8
yup yup yup - this is why I usually say to use the .NET classes than the legacy stuff carried on from one version to the other, it avoids these problems and the .NET classes are specialized and customized highly for a particular task. It resolves alot of issues that we may have been having in the past/old days.
ahmedilyas at 2007-9-3 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 9

Sorry guys i was away for a while! Yes the problem was the double quotes. I used quotes with Sender.toString and the Shell worked fine. Sender.toString was as string without quotes.

Yes i know Shell is for executables. I was going to use only Process.Start but sometimes it would crash the program that was about to run.I don't know why. That's why i wanted to run them with shell.

Anyway the problem is solved now. Thank you very much people. Take care!

de_Stan at 2007-9-3 > top of Msdn Tech,Visual Basic,Visual Basic Language...