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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Windows "Run" menu

Status
Not open for further replies.

jmb0730

Programmer
May 23, 2005
3
US
Is there a way to access the Windows "Run" menu that is located in the start menu with code??
 
Take a look at the Shell() command

Everybody body is somebodys Nutter.
 
You can use the SHRunDialog function which is officially undocumented and exported only with an ordinal number.

Place a command button on your form and try the following code.
___
[tt]
Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As Long
Private Declare Function SHRunDialog Lib "shell32" Alias "#61" (ByVal hOwner As Long, ByVal hIcon As Long, ByVal szPath As Long, ByVal szTitle As Any, ByVal szPrompt As Any, ByVal uFlags As Long) As Long
Private Type OSVERSIONINFO
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String * 128
End Type
Const VER_PLATFORM_WIN32_NT = 2
Const SHRD_NOBROWSE = 1 'hide the Browse button
Const SHRD_NOMRU = 2 'don't show the last filename

Private Sub Command1_Click()
ShowRunDialog hWnd, Me.Icon, "Your title here", "You messge here", SHRD_NOMRU 'Or SHRD_NOBROWSE
End Sub

Public Sub ShowRunDialog(Optional hWnd As Long, Optional hIcon As Long, Optional ByVal Title As String, Optional ByVal Prompt As String, Optional Flags As Long)
Dim osvi As OSVERSIONINFO, Flag As Long
osvi.dwOSVersionInfoSize = Len(osvi)
GetVersionEx osvi
If osvi.dwPlatformId = VER_PLATFORM_WIN32_NT Then
SHRunDialog hWnd, hIcon, 0, StrPtr(Title), StrPtr(Prompt), Flags
Else
SHRunDialog hWnd, hIcon, 0, Title, Prompt, Flags
End If
End Sub[/tt]
___

Note that all of the function arguments are optional. If you skip an argument, the default option is used.
 
Hypetia said:
You can use the SHRunDialog function which is officially undocumented and exported only with an ordinal number.

Now it is unofficially documented ;-)

Visit My Site
PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
You can try this.

Code:
Sub Test()
Dim temp,tmp
Tmp = "c:\autoexec.bat"
temp = Shell("notepad.exe " + tmp, vbNormalFocus)
End Sub
 
It may not be documented but it is wrapped by the
Microsoft Shell Controls and Automation library. Which means that, as long as you don't need any of the extra configuration capability that you gain from directly using the API as illustrated by Hypetia, you can pop up the run dialog like this:

CreateObject("shell.application").FileRun
 
Strongm
When I tried your suggestion i got the error:
ActiveX component can't create object

I ran the code as:
Code:
Dim oCmd

Set oCmd = CreateObject("shell.application").FileRun
Where did I go wrong?

Everybody body is somebodys Nutter.
 
1) What OS?

2) FileRun does not return any sort of object; it merely opens the Windows "Run" dialog
 
Os = NT
I just get the error message

Everybody body is somebodys Nutter.
 
NT4? Ah, the trick only works with version 4.71 or later of Shell32.dll. NT4 ships with version 4.0, and the only time this would be updated to 4.71 is if you installed Internet Explorer 4 with active desktop at some point. As far as I am aware, nothing else updates Shell32.dll on NT4
 
Just to add to my previous post... I did not use the third argument, szPath in my code. This is used to initialize the current or default directory for the Run dialog. Specifying the default path has two advantages.

1. When the user clicks the Browse button, the File Open dialog browses directly from the default folder.

2. When the user types a program or filename without path, the Run dialog searches the default folder as well for that file.

To use this argument, change the szPath argument to Any and pass the argument to the function the same way the other two string arguments are passed. (Once with string pointer, and the other time, straight).
 
strongm was clear enough in his (2) above, you can't set an object reference to a method.

His earlier code fragment was showing a call of a method of a temporary instance of the Shell.Application object. There is no reason to store a reference to something you only need momentarily.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top