PDA

Click to See Complete Forum and Search --> : shell()


smileyface5
Feb 17th, 2005, 10:41 AM
can you call any command at the dos prompt using shell() or is it only certain commands?

RobDog888
Feb 17th, 2005, 10:50 AM
There are no restrictions with shell and a dos command window.
:)

smileyface5
Feb 17th, 2005, 10:57 AM
Thank you.

One more question regarding shell().
How do you get the DOS prompt to stay open once opened by vba?
I know there is some property but i cant remember what it is

RobDog888
Feb 17th, 2005, 11:03 AM
If you pass the /C after the CMD.exe it will close the window and /K will keep it open.
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 Const SW_SHOWNORMAL As Long = 1
Private Const SW_SHOWMINIMIZED As Long = 2
Private Const SW_SHOWMAXIMIZED As Long = 3

Private Sub Command1_Click()
ShellExecute Me.hwnd, "Open", "C:\Windows\System32\CMD.exe", " /K Dir C:\", App.Path, SW_SHOWNORMAL
End Sub