Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  HOME    TRACKER    Visual Basic

ShellExecute And ShellEx?

What is the difference between ShellExecute and ShellEx?

View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
how can i get to "My Computer" using shellexecute (or any method that isnt OLE

thanks.. im sure its simple but i cant (can do other files)

cintel rules

ShellEx Is Not Recognized
ShellEx is not recognized!
It says Sub or Function not defined!

Closing An EXE With ShellEx
Is it possible to use the windows shell exacute command to close an exe?

How Do You View .tifs (shellex) On A Winxp Platform?
shellexecute used to run fine when i'd pull up kodakimg.exe on the older windows versions, but on an xp..nothing comes up.

the .tif file basically contains several scanned documents that a user should be able to browse through, which kodakimg does fine.

i tried using explorer.exe so it'd bring up windows xp's picture viewer, but it doesn't really work well since it can't browse through the individual pages of the document.

help please!

thanks in advance

I have VB6 project with a Myshellexecute function, on my PC the function works fine with all kind of files i need, (.zip, .ppt, .doc, .pfd, .jpg)

but it happen that in some machines the shellexecute ends up doin nothing, no error , nothing...
is it due to some program association?
but l don't think so.. caus efor example using it to launch a jpg on two different computers , one diplays it correctly the other does nothing...

any idea?

i have this call
Call ShellExecute(Me.hwnd, "Open", cmdline, "", "", vbMaximizedFocus)

1 question
it works fine with files whom program i correctly installed on my PC but if i try to open a file that doeasnt' exixt the associated program...
it ends up not doing anything...i wished windows can catch this when u double click on a file ... presenting u a pop up asking for choosing the associated program to open the unrecognized extesion...

2 question. May i catch the exit of the program opened by shell execute? and then do something after the closing of that app?

thank you

Hey All

Im using shellexecute to open an excel file (so it doesnt have any link to my current excel file), and it just freezes excel.. heres my code

Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

ShellExecute hwnd, vbNullString, FileToOpen, vbNullString, "C:", SW_SHOWNORMAL

Note: I dont know if its relavant but when debugging, hwnd is empty.

Thanks guys

I have a file with a .ax extention. When i double click on the file i want to call for my program to start running and process the file. What code do i have to write to achive this??

I know how to open drives, folders, apps etc using the shell, example
ShellExecute hwnd, "open", "C:", vbNullString, vbNullString, SW_SHOWMAXIMIZED

this opens the c drive folder. Question I have is simply how to I close the folder using the shell command, is this possible? If not, how is it done? Let's say that drive C: is open.

I tried

ShellExecute hwnd, "close", "C:", vbNullString, vbNullString, SW_SHOWMAXIMIZED

ShellExecute hwnd, "end", "C:", vbNullString, vbNullString, SW_SHOWMAXIMIZED

Long time ago you said to me to use

But how does it works?

If I do this :

shellexecute ("IEXPLORE.EXE")

It's calling me an error

Thanks for your help in advance

Shellexecute Help
ok ive read quite a few posts on this and i just cant seem to understand it

lets say i want to open a file called kujo.txt in notepad what would the code be for the shellexecute?

if anybody can help it would be great, and if possible could you tell me what is in the main code and what is in a separate module if its needed


Hi all

I am creating a webpage from a recordset.
My problem is i create the page save it to a directory and then
open it up again.Is there any way of creating the page and showing it to the user without saving it first.And if there is'nt is there any way of hiding the address bar in IE so the user wont know what directory the file is stored in.

Here is the code that i am using.(that someone so kindly gave me on this forum).

sHTML = "G:Information TechnologyDevelopmentDevelopShaneoutput.htm"

Set rs = New Recordset

rs.Open SQL, cnAppsLog, adOpenKeyset, adLockReadOnly

If Not rs.EOF Then

Dim fID As Integer
Dim i As Integer

fID = FreeFile
Open sHTML For Output As fID
Print #fID, "<html><body BODY BGCOLOR=483D8B TEXT=FFFFFF>"
Print #fID, "<CENTER><table BORDER="; 1; " CELLSPACING="; 4; " CELLPADDING="; 0; " BORDERCOLOR=FFD700>"
Print #fID, "<CAPTION><B><FONT SIZE = "; 6; ">Results Of Your Query</FONT></B></CAPTION><br>"
' header row
With rs
' header columns
Print #fID, "<tr>"
For i = 0 To .Fields.Count - 1
Print #fID, "<th><FONT SIZE = "; 4; " COLOR = Yellow>" & .Fields(i).Name & "</FONT></th>"
Next i
Print #fID, "</tr>"
If Not .EOF Then
' data
Print #fID, "<tr>"
For i = 0 To .Fields.Count - 1
Print #fID, "<td><CENTER>" & .Fields(i).Value & "</CENTER></td>"
Next i
Print #fID, "</tr>"
Loop Until .EOF
End If
End With
Print #fID, "</table></CENTER>"
Print #fID, "</html>"
Close fID

Dim lRetVal As Long
lRetVal = ShellExecute(0&, vbNullString, sHTML, vbNullString, vbNullString, 3)
Any help appricated
thanx shane

Could you show me an example using ShellExecute?

ShellExecute API
First, thanks Crazed-lunetic, those tips helped me a lot!
Now, please, how do i use the Shellexecute API ? Im trying these: " Call ShellExecute(hwnd, "Open", "d:Powerarc -a -v1380 -jt -c4 d:Teste1*.*", "Null", "d:", SW_SHOWNORMAL) " and nothing is happening. Im trying to get the same action as in this line: "Call Shell("d:Powerarc -a -v1380 -jt -c4 d:Teste1*.*", vbNormalFocus)".
Anyone Heeelp!

Shellexecute Api
I am running the shellexecute api to run a local HTML file on my hard drive. Some people who are running the program are complaining that they get a box asking them if they want to connect to the internet.

How do I stop this message box from popping up if the file is only local???

Thanks folks!


Shellexecute..?please Help
I need to make a button open my richtextbox1 in my default browser......???? how do I set the shellexecute to do all that...??????do I have to put the location of the browser..?? how do I do that... please help me

ShellExecute .lnk
I have posted this question before, but my problem still isn't solved. I have searched all over the internet. But I still can't figure it out why it doesn't work.

I have the Shellexecute API

Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _
ByVal lpParameters As String, ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long

And I call it:

r = ShellExecute(0, "open", "C:Shortcutsshadow.lnk", vbNullString, "C:", WN_SHOWNORMAL)

it keeps returning 31 to r...
and that's the problem...
it's suppose to return a higher number...
and the error is "No such Association" or something like that.

How do I fix it? How do I shell a .lnk file? Is there any other ways to shell a .lnk file?


I was wondering if anyone knows how to determine when a ShellExecute has terminated?

I tried the Shell terminate function from the MSDN library and was not successful.

Any takers?

How do I copy a file using ShellExecute function, and is it possible to copy a file from a server on a LAN house?

For example, I want to copy the file "config.cfg" from \ to D:Games

Is it possible, and what are the available commands to hide this opperation from the main window and overwrite the current files on D:Games folder automatically?



Hello all,

If I use SellExecute to run an app'
how can I find out when the app' stops,
I need to run a two app's but the second
app' have to to run after the first one has "finished".


Is it possible to use the shellexecute command and run a exe as administrator when a user is logged in

this is what iam using now

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

ShellExecute(Me.hwnd, "open", strapp, strxp, "", 1)

strapp & strxp are both string values

Thanks in advance


ShellExecute... PLEASE HELP
Hey all

Im really having problems with shell execute. Ive posted on this subject before with no replies.

I am trying to open an excel file using ShellExecute. I do NOT want to use the excel object. Ive declared ShellExecute and i cant get the syntax right to open a file. Everytime the debugger runs over the code my application freezes.

my code is:

ShellExecute hwnd, "open", ExportFile, vbNullString, vbNullString, 1

note: at the time of execution hwnd is empty, also, i am running this code in excel vba

Please HELP!

I am trying to make a program a la gamespy which launches people into a game...
I have been halted by a problem tho.
i = ShellExecute(Me.hwnd, vbNullString, "RainbowSix.exe", vbNullString, "c:games
ed storm entertainment om clancy's rainbow six", SW_SHOWMAXIMIZED)

worx fine

but the program needs to receive the parameter (is that correct?) -server xxx
[where xxxx is the port]
-client xxxx
[ip port]
whenever i include this in the follwing way:

i = ShellExecute(Me.hwnd, vbNullString, "RainbowSix.exe -server 2346", vbNullString, "c:games
ed storm entertainment om clancy's rainbow six", SW_SHOWMAXIMIZED)

the game fails to launch
the value returned to i = 2

Thank you

Run Exe Using ShellExecute

am trying to run my setup.exe using ShellExecute API in visual basic
it is not woking in windows 98, but it working perfectly in above win200,winxp. but not not in windows 98 and ME

plz solve my problem with very urgent for me

I'm trying to send a mail on the users default mail system using the 'ShellExecute' API, but there doesn't seem to be an 'Operation' argument which sends the mail immediately without opening a mailitem window.

Can this be done?

I was slightly informed about an API called Shellexecute..Does anyone know anything about this API? please help!thanks in advance!

?-=The Bomb=-?
"You all stare, but you'll never see; theres something inside me!"

ShellExecute API
Please, how do i use the Shellexecute API ? Im trying these: " Call ShellExecute(hwnd, "Open", "d:Powerarc -a -v1380 -jt -c4 d:Teste1*.*", "Null", "d:", SW_SHOWNORMAL) " and nothing is happening. Im trying to get the same action as in this line: "Call Shell("d:Powerarc -a -v1380 -jt -c4 d:Teste1*.*", vbNormalFocus)".
Anyone Heeelp!

This question is Real basic. I just need to know how to do a shell command that would launch an application like notepad, and display in notepad (etc) whatever is in my Text1 text box.




ShellExecute HELP !@!@!@!@!@
i need to shell .exe file with ShellExecute,but i am stupid and i dont know how to do it
if some1 can help me and gimme example will be great for me


What is the different between following 2 codes actually .

lngresult = ShellExecute(Me.hwnd, vbNullString, "", vbNullString, vbNullString, SW_SHOWMAXIMIZED)


Set explorer = New InternetExplorer
explorer.Visible = True
explorer.Navigate ""

because bought performs same action. But i had a problem when i using the code #2 in 9x platform.

when i try to execute the code from my system tray popup menu an automation error comes. so i had to replace code #2 using code #1 .

Please explain...

Use ShellExecute In DLL
I am making a DLL (my first one).

Is it possible to use ShellExecute in a DLL without forms?

The problem is the first, hwnd parameter.

Call ShellExecute(hwnd, "Open", App.Path & "somefile.txt", "", "", vbNormalFocus)

From the API guide about ShellExecute-

If the function succeeds, the return value is the instance handle of the application that was run, or the handle of a dynamic data exchange (DDE) server application.

Is there way to get the Window handle from an instance handle. I want to shell a control panel applet, then move the Window using SetWindowPos (which needs the window handle).

Using the shellexecute,
how could i send an email with an attachament?

If a IE window is open and you shellexecute Http://

It will overtake that IE window with the site.

How do I get around this?

I use the following code

VB Code:
ShellExecute Me.hwnd, "open", sFile, sCommand, sWorkDir, 1

It works great, but it closes my VB application, does anyone now how to change this?


Hi Gurus,

Is there a way to display the console window (a C EXE called by ShellExecute) in the centre of the screen?


This shellexecute is indeed a problem. I have this code below and seems to work on some machines and not on others. When it works it returns 42 otherwise 2. Can someone tell me how I van get it work on ALL machines. Many thanks.

Dim PathToExe As String

On Error Resume Next

If Len(Dir(App.Path & "Serverxxx.exe")) = 0 Then
Call WarnUser
PathToExe = GetShortName(App.Path & "Serverxxx.exe")
Retval = ShellExecute(Me.hwnd, "Open", "start.exe ", PathToExe, PathToExe, 1)
End If

ShellExecute &amp; IE

I'm having problems opening a URL in IE6 from VB6. I am using the following command:

ShellExecute(0&, vbNullString, strURL, vbNullString, vbNullString, vbNormalFocus)

where strURL is the, er, URL I want to open!

This successfully opens IE (as the default browser) with the page I want, but the taskbar icon for my VB app disappears, and it is not in the list when I do ALT-TAB. However, the app is running when I look in Task Manager and I can switch to it from there, but that's the only method I can find to get back to it!

I have tried passing the calling form's handle using Me.Hwnd, but this makes no difference. Changing the focus type doesn't seem to help either. I have event tried cutting and pasting code from the MS site which find the file association for HTML and tries to open it:

ShellExecute(Me.hwnd, "open", BrowserExec, strURL, strDummy, vbNormalFocus)

But no joy with this either! In case it matters, we get the same error in Win2K & XP Pro...

Thanks in advance!

I am using the shell execute command to execute a batch file. I am told that there is a way to close the application dos window on error. Here is my code:

ShellExecute Me.hwnd, "Open", "C:FTPGETLOG.BAT", vbNullString, "C:", SW_SHOWNORMAL

Private Sub KillDosWindow()
Dim WHwnd As Long
Const NILL = 0&
Const SC_CLOSE = &HF060&

WHwnd = findwindow(vbNullString, App.Path & "C:WINNTSYSTEM32CMD.EXE")
If WHwnd = 0 Then
WHwnd = findwindow(vbNullString, "CMD.EXE")
If WHwnd = 0 Then
WHwnd = findwindow(vbNullString, "CMD.EXE")
End If
End If

If WHwnd <> 0 Then
Handle = sendmessage(WHwnd, WM_SYSCOMMAND, SC_CLOSE, NILL)
End If
End Sub

I am using the ShellExecute function to open a file from within a VB program, but I need the VB program to wait until the executed program finishes before continuing. Does anyone know how I can do this?


I found this code.. and i want to adapt it to an outlook toolbar button...

userform1 does not have hwnd

What should I do??


VB Code:
Option ExplicitPrivate Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _        (ByVal hwnd As Long, _        ByVal lpOperation As String, _        ByVal lpFile As String, _        ByVal lpParameters As String, _        ByVal lpDirectory As String, _        ByVal nShowCmd As Long) As LongConst SW_SHOWNORMAL = 1 Private Sub cmdRun_Click()     On Error GoTo ErrRun        With cdbRun        .CancelError = True        .DialogTitle = "Choose a file to run"        .ShowOpen    End With        ShellExecute Me.hwnd, vbNullString, cdbRun.FileName, vbNullString, "C:", SW_SHOWNORMAL    ErrRun:End Sub



I am using this to open a program.

VB Code:
ShellExecute Me.hwnd, vbNullString, strPath, vbNullString, "C:", SW_SHOWNORMAL

It works fine. What I would like to happen now is when the ShellExecute statement is called, I would like the rest of the code in the procedure to halt until the program is closed. Kind of like showing a modal form. Is this possible?

I found this code by John Percival, here last night and I'm trying to make it work to as autoplay on a CD. I want to burn it onto a CD and just throw the CD in a drive and have index.html launch. But I just don't have it right any ideas or can it even be done.

Option Explicit

Private Declare Function ShellExecute _
Lib "shell32.dll" Alias "ShellExecuteA" ( _
ByVal hwnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long

Private Sub Form_Load()

Dim sWorkDir As String
Dim sFile As String
Dim sCommand As String

sWorkDir = "C:albums" 'set the working directory
sFile = "C:albumsindex.html" 'set the file to execute
sCommand = vbNullString 'Set the command line parameters

ShellExecute hwnd, "open", sFile, sCommand, sWorkDir, 1
End Sub

****************************************************Thanks Alan

Using ShellExecute

I have written a program that opens a HTML file using the ShellExecuteEx API call, but I need a way of finding out when the internet explorer window is closed, so that I can refresh the pictures on my form.

I have been experimenting with WaitForSingleObject but it doesn't seem to help. Also creating a process and discovering when this is complete is not sufficient since I cannot pass a HTML type file to a process (has to be an executable)!

Any suggestions would be much appreciated.

ShellExecute (not What You Think)
Hi all.

When using ShellExecute, is it possible to open a program using the same window that another program of the same typed used with a prior ShellExecute?

For example, I have 2 command buttons that both open Word documents. If I click the first one to open the document in Word, can the second one that's opened replace the first document in Word? In other words, it will use the instance of Word that's already open instead of opening a new instance of Word.

I hope some one can help.

Thanks in advance.

ShellExecute - Help!!!!!!!
I am using ShellExecute to run a DOS shell disk image program and copy files to the A drive. I need to prompt the user to remove the floppy when it is done, however once the API is called the program continues on. I have tried loops and DoEvents to use drv.IsReady but drv.IsReady is always true. Is there some function or API I can use to tell when the disk drive is no longer running or the DOS window has closed. Help Please!!!

When talking about the shellexecute api function, what is the value of SW_SHOWNORMAL? I know that's what I want, but I don't know what value it is to declare in my app!

Shellexecute End?
I know someone out there knows this, because I've seen it myself somewhere...

How can I detect when a program I've shelled with ShellExecute has finished?

I need something that loops, if possible, so that I can keep it within a single form's sub to ease things along. Something along the lines of:

Do While (StillExecuting)

So that I can put in the code to execute after it's finished immediately after the loop.

Thanks in advance.

ShellExecute API
Hi all,
As I,m not too familiar with API's, I'm having a problem closing Notepad from my app. I can create a new text file, write and save to it, then later open the file in Notepad.
My question do I close Notepad from my app.

I've tried this:

ShellExecute 0&, "Close", "C:ProgramsAccessoriesNotepad"

but its obviously wrong. Can anyone give me the correct code to close Notepad please.


Copyright 2005-08, All rights reserved