Visual Basic

Yo,

Sorry for posting something as mundane as this to the SD forum, but Ive searched everywhere for the answer including the M$DN reference disks, the M$DN website, VB websites and even asked a couple professional VB coders.

How do you launch an external application from a VB app using VB code (including passing arguments to the ext app)? Is that possible or is it blocked for security reasons? I know how to do it easily in VC++ so I could always write a VC++ DLL that launches the ext app and then interface with it in VB but I REALLY dont want to do that.

Also because im asking coder questions, how do you make a VB or VC++ app minimise to the systray? Or even get the Icon there in the first place. Ive looked everywhere for that too. I dont need to know all the details, I know how to capture windows messages in VC++ etc, I just need to know how to get it in the tray.
If the answer to either is to long, please post a link.

TY

-Blah

Doesn’t the “Shell” command do what you want?

Shell “path arg1 arg2”, vbNormalFocus

Shell is probably just a thin wrapper around the ShellExecute function; you could always import that function and use it directly if you need a little more flexibility.

Shell’s the one you’re looking for.

Not sure if this is what you are looking for but try Q176085 or Q177095 or possibly Q162613.

Doh :o

I should have known, ive seen a similar ‘shell’ command in the VC++ reference.

Ill try it, TY.

OpenGrave, ill look into those.

Unfortunatly, though, I need to add the ability to link to an arbitrary DLL at run-time so I will have to mess around with DLLs anyway :frowning: (BTW, I know how to do that) But im about to scrap the whole VB part of it and go pure VC++, which is what I SHOULD have done from the beginning…

Noone knows about the systray thing?

-Blah

I’ve had problems using the Shell command; I was passing it a string argument which was a concatenation of the application to be launched and the parameter to pass to it (which was a filename); I had enormous trouble and I can’t remember how I fixed it, but essentially it was something like:

Shell(“Notepad.exe c: est.txt”)
would work fine, but

strA= “Notepad.exe”
strB= “c: est.txt”
Shell(strA + " " + strB)
would not

Yo Mangetout,

Your trouble is most likely because the + operator is an addition operator, which (I assume) is overloaded with another function to append strings. This ‘function’ is ‘typed’ to String, String, so the ‘function’ could be thought of as Add(StrB as String, StrA as String) as String (I dont feel like opening up MSDN so this is from memory). My guess is one of your strings is either not a string (Carefull with those ‘Variant’ vars they always sneak up on you from behind…)

The & operator should work:

strA= “Notepad.exe”
strB= “c: est.txt”
Shell(strA & " " & strB)

But you may need to cast it back to a string:
Shell(String)(strA & " " & strB)

Im not 100% sure on all this, Ive been coding in C++ all day so im still thinking in C terms…pointers…yuck

And if you REALLY want to talk about trouble, try calling shell from an internet cgi written in C++…I crashed my server everytime I did that…I ended up making a second application that ran in the background to handle all the shell and DataBase stuff, with a socket connection from the cgi to pass parameters. And NO this had nothing to do with a virus, I made an internet driven kiosk for a company where the employees could swipe their card/enter a code to buzz the door open…

-Blah

Sorry, I did mean to type & in the code example, but I do a lot of Delphi development these days* and I hit + instead; the shell problem I encountered happens whichever way you concatenate the strings; I’ll try to find a link to where we discussed it on another board. (it was VBA actually, as it was an Access application).

*(dammit, whenever I try to program in VB now, I keep terminating the lines with a semicolon).

here and here.

lol Mangetout,

I have the same problem but also with C++ peranthesis in VB…and trying to figure out why the compiler wont let me allocate a pointer…

VB like me is kinda like German to me, I think in C++ and tranlsate it to VB, like I think in English and translate to German.

-Blah