PDA

Click to See Complete Forum and Search --> : run your app from the run prompt


ZanM
Jan 20th, 2000, 09:11 AM
does anyone know of a way to associate your program so that it can be run from the run prompt (from the start bar rum option) and if so can you capture that event in some way like you can when you have file associations?


------------------
SomeTimes Coffee Just Isn't Enough.
Zan Magi

Aaron Young
Jan 21st, 2000, 01:44 AM
I'm not sure you're being very clear..

You can run your app from the Run Section of the Start Menu, by typing..

C:\MyFolder\MyApp.exe

If you mean you want to type something like:

C:\SomeFile.xyz

And have it launch your App with SomeFile.xyz passed to it, then you just need to associate you App with the Extension.

Here's some code I wrote and posted a while ago to do just that:

Private Declare Function RegCreateKeyEx Lib "advapi32.dll" Alias "RegCreateKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal Reserved As Long, ByVal lpClass As String, ByVal dwOptions As Long, ByVal samDesired As Long, lpSecurityAttributes As Any, phkResult As Long, lpdwDisposition As Long) As Long
Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long

Private Const HKEY_CLASSES_ROOT = &H80000000
Private Const REG_CREATED_NEW_KEY = &H1
Private Const REG_OPENED_EXISTING_KEY = &H2
Private Const REG_SZ = 1

Private Const STANDARD_RIGHTS_ALL = &H1F0000
Private Const KEY_QUERY_VALUE = &H1
Private Const KEY_SET_VALUE = &H2
Private Const KEY_CREATE_SUB_KEY = &H4
Private Const KEY_ENUMERATE_SUB_KEYS = &H8
Private Const KEY_NOTIFY = &H10
Private Const KEY_CREATE_LINK = &H20
Private Const SYNCHRONIZE = &H100000

Private Const KEY_ALL_ACCESS = ((STANDARD_RIGHTS_ALL Or KEY_QUERY_VALUE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY Or KEY_CREATE_LINK) And (Not SYNCHRONIZE))

Private Sub Command1_Click()
Dim lRegKey As Long
Dim lResult As Long
Const sApp = "Notepad.exe %1" 'Application to Launch
Const sExt = ".xyz" 'Extension to Associate
Const sExtDesc = "XYZ File" 'Extension Description
Const sIcon = "C:\MyApp.exe,0" 'Icon Resource for Extension

'Create the Extension Entry
Call RegCreateKeyEx(HKEY_CLASSES_ROOT, sExt & "\", 0&, "", 0&, KEY_ALL_ACCESS, ByVal 0&, lRegKey, lResult)
If lResult = REG_CREATED_NEW_KEY Or lResult = REG_OPENED_EXISTING_KEY Then
'Reg Opened/Created Successfully, set Reference to the Application Key
lResult = RegSetValueEx(lRegKey, "", 0&, REG_SZ, ByVal sExtDesc, Len(sExtDesc))
Call RegCloseKey(lRegKey)
If lResult = 0 Then
'Value set successfully, Assign Extension Icon
Call RegCreateKeyEx(HKEY_CLASSES_ROOT, sExtDesc & "\DefaultIcon\", 0&, "", 0&, KEY_ALL_ACCESS, ByVal 0&, lRegKey, lResult)
If lResult = REG_CREATED_NEW_KEY Or lResult = REG_OPENED_EXISTING_KEY Then
'Key Created, Set Icon Resource
lResult = RegSetValueEx(lRegKey, "", 0&, REG_SZ, ByVal sIcon, Len(sIcon))
Call RegCloseKey(lRegKey)
End If
'Create Associated App Key
Call RegCreateKeyEx(HKEY_CLASSES_ROOT, sExtDesc & "\Shell\Open\Command\", 0&, "", 0&, KEY_ALL_ACCESS, ByVal 0&, lRegKey, lResult)
If lResult = REG_CREATED_NEW_KEY Or lResult = REG_OPENED_EXISTING_KEY Then
'Reg Opened/Created Successfully..
lResult = RegSetValueEx(lRegKey, "", 0&, REG_SZ, ByVal sApp, Len(sApp))
If lResult = 0 Then
MsgBox "Extension Associated"
Else
MsgBox "Failed to Associate Extension"
End If
End If
End If
End If
Call RegCloseKey(lRegKey)

End Sub



------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
ajyoung@pressenter.com

Cmathis
Jan 21st, 2000, 02:30 AM
I am not sure if I am answering your question, but if you are wanting to run something from the "Run" menu the same way that you can type in "winmine" or "calc" then all you have to do is put the file you would like to run in the Windows directory. You could also create a "*.bat" file or something that would load the program and then place it in the Windows directory instead of the original file. Whatever you name the file will be what you type in the "Run" menu, minus the extension of the file. I hope that helps.

[This message has been edited by Cmathis (edited 01-21-2000).]

ZanM
Jan 22nd, 2000, 11:21 AM
ok i'll try to be more clear what i'm doing is creating a program to tell the amount of time a pc spends online but it is for a lawyers office and the pc user can't know its there

I wanted to be able to type a command in the run prompt and diplaay a log of connections and times i can already determine if theres a connection and time it i just need a way for the administrater to access it with out the user knowing the office will have a network soon so i may just make two programs one for the timed pc's and one for admin to access some type of log file by but i would still like to know if there is some way to determine if your program was ran from the run promt and may it take a special action

and i already knew how to do the file assocations i was using them as an example of the kind of control i wanted thew the command feature in vb or something simular


------------------
SomeTimes Coffee Just Isn't Enough.
Zan Magi