-
Add application to files context menu and send selected files as parameters
Hi,
I would like to add my application to the context menu of the files (so that when someone right click on any file, he will get the option to open my application) ... And when he click to open my application, my application get as parameters the name of the file(s), that the user selected when he made the right click to open my application.....
To make it simple, the user select some files, he right click them, and tells my application that here are the selected files
If my question is not clear, i want to make exactly like winzip, for expl, we select files, we right click them , then we select Winzip, AddtoWinzip and files are received by Winzip application , that's exactly what i want to do for my application
Thanks a lot in advance for your support hoping to get an answer
-
Re: Add application to files context menu and send selected files as parameters
This thread talks about that and may answer your question.
-
Re: Add application to files context menu and send selected files as parameters
thanks a lot for your reply, i will check the thread you mentionned and i will let you know if it's what i need or not !
ps: i may not be able to tell you directly if it worked or not, cuz i am working on many projects on the same time and i have due date for work, so please keep an eye on this thread from now till the week end to try to help me in case the thread you passed doesn't have the answer
thanks a lot again
-
Re: Add application to files context menu and send selected files as parameters
thanks for your reply , i checked the link http://www.vbforums.com/showthread.php?t=323437 !
Yes they talk about exactly what i need but am not understanding anything in fact i got confused cuz there are many solutions and each of them give answer not clear, for expl the post #13 of baja_yu, talks about a link he posted, i never found the link he talks about, also in the above posts they confused me ... Do you have any other thread that talks about but where it is less confusing ?
The thread you passed is exactly what i need but once again it's not so clear
-
Re: Add application to files context menu and send selected files as parameters
-
Re: Add application to files context menu and send selected files as parameters
thanks vb5prgrmr, i will read again the article, but i don't want to mess with the registry, can you confirm me that the link you gave me is not to associate a specific type but all types of files to my application ? because in the top of your article it says that it's to associate a specific type !
-
1 Attachment(s)
Re: Add application to files context menu and send selected files as parameters
for any file type to automatically open in your program, you do need to mess with the registry, either manually or in your programs installation script
for your program top be added to the context menu of all files you need to modify the registry key for all files (*)
i have a program called copy path, you can see the registry entry for that in the image
the full entry is "C:\Documents and Settings\pete\My Documents\basic\exes\copy path.exe" %1
this program is only designed to work with a single file, the name of the file is passed to your program as the %1 parameter
and read as the command variable
mutiple files can also be passed, but will open mutiple instances of your program unless you handle that with app.previnstance, so you can pass additional files to the same instance of your program
i was going to post the copy path program as an example, but i never saved it, mainly because this is the full code of the program
vb Code:
Sub main()
Clipboard.Clear
Clipboard.SetText Command
End Sub
this progam is not required for vista as it has a built in option to perform the same task
-
Re: Add application to files context menu and send selected files as parameters
westconn1 thanks...I would like that you confirm that i understood your post
So if i want it to run for any kind of files and folders i have to add the entry same as you did for your program ?
you said
Quote:
mutiple files can also be passed, but will open mutiple instances of your program unless you handle that with app.previnstance, so you can pass additional files to the same instance of your program
Can you explain more about this ? if i want it for multiple files and folders, should i replace the %1 by something else ?
IF YES , what should i put instead of %1?
Can you explain me more about app.previnstance and how to get all files ?
should i have something like
Code:
Public Sub Main()
If app.previnstance = true Then
end
End If
End Sub
In this case this guarantee that my application wo'nt be loaded many times, but how to get all files than ?
-
Re: Add application to files context menu and send selected files as parameters
Yes, it is for a specific type of file and NOT all files.
Good Luck
-
Re: Add application to files context menu and send selected files as parameters
Quote:
Originally Posted by
vb5prgrmr
Yes, it is for a specific type of file and NOT all files.
Good Luck
Yes, but what i want is for multiple files and folders ! That's what i had been repeating !!!
-
Re: Add application to files context menu and send selected files as parameters
That is what I initially missed or misunderstood....
http://www.a1vbcode.com/vbforums/Topic28436-3-1.aspx
Good Luck
-
Re: Add application to files context menu and send selected files as parameters
Quote:
Can you explain more about this ? if i want it for multiple files and folders, should i replace the %1 by something else ?
IF YES , what should i put instead of %1?
no %1 stays the same, you have to handle it from your vb program
when your program opens it must check if there is a previous instance, if there is it must pass the command parameter to the previous instance using dde then close
it must also be able to accept the incoming dde then process it in addition to what it already has, depending what your program does it may open another child window or create a new instance of a form
here is a similar thread where i posted a sample project
http://www.vbforums.com/showthread.p...t=instance+dde
-
Re: Add application to files context menu and send selected files as parameters
thanks a lot westconn1, very helpfull, now i understand the idea of what i should do, what i need is to know technically how, so i will read what you posted and will come back later by the week end for more information in case i couldn't make it
-
Re: Add application to files context menu and send selected files as parameters
westconn1, thanks a lot for your help, i added the context menu for the files now i wanna do the same for folders then i will work on the 1 instance and getting selected files by param....but i have already some questions !
suppose i added : HKEY_CLASSES_ROOT\*\Shell\Open With MyProg
1) if the user has a german or french OS, he will see the same Open With MyProg !!
how can i make the Open With become Ouvrir Avec for french OS, and same for german etc...i mean translate my key depending on the operating system ?
2) How can i add an Icon next to the Open With My Prog
3) How can i make SubMenu ? instead of getting Directly Open With My Prog
i get a Menu Called My Prog , and Inside it there are some submenus like Open With , Add to etc....
I hope anyone can answer me
-
Re: Add application to files context menu and send selected files as parameters
this is a lot more complex, they use context menu handlers in registry, pointing to clsid
check out registry entries for other programs that do some of those things, eg winzip or winrar, then search on the clsid to find more informatation
so, looks like, you would need to make a class to do what you are asking, but i have never made a class to do that
google context menu class, but most results seem to be for .net, so you will have to go through them to find something relevent, or search smarter
-
Re: Add application to files context menu and send selected files as parameters
Thanks for your fast reply ! I have a very important question !
If i am adding to the registry my application, i am adding it with the full path ! but if the user copied the application to another place , the key that i added on the context menu once clicked it will show an error and it won't open the application which is normal cuz it moved !
Is there anyway to make the command apply to my application wherever it's copied ?
dunno if you understand me, i hope so
-
Re: Add application to files context menu and send selected files as parameters
use app.path to return the correct location to your exe, but registry keys like that are normally added by the installer, so are correct when installed, though often with some option within the program to change later
check the correct key exists when your program opens
-
Re: Add application to files context menu and send selected files as parameters
In fact, am trying to make my application a stand alone exe without any setup,that's why am only using API, no OCX in it till now i am resisting lol :)
But if i will be obliged to make a setup i can make it later on
Anyway, if i understand what you say then i have each time my application is launched on form load i check if the command value in the registry is the one of running application, if not then i add it right ?
the only problem in the case is that when the user delete my application he has to delete manually the registry key or that i must make an uninstaller for it
Except if there is a way to detect if the programme clicked on my application and Delete, that i call my application before it's deleted and make it delete the registry key ! Any api for that ? or a place in which i can add my application to detecte once the user want to delete it ?
-
Re: Add application to files context menu and send selected files as parameters
you should have uninstaller for your program, so user does not delete
also if the use moves the exe it would not update the path in registry unless, the exe is opened by running the exe, context menu will not open the program, by file association, until the registry has been updated
users seldom move files once they have been installed, as it is common for most programs not to work, once moved
because of how your program works it should have installer of some sort, including uninstaller
-
Re: Add application to files context menu and send selected files as parameters
Once again thanks a lot for your support...
To avoid that the user move my application, so what i can do as you said a sort on installer ? If i understand you well i got an idea, let me know what do you thing ?
The first time the user launch my application(from his deskptop or download folder or anyplace) , it copy itself using FileCopy somewhere in c:\windows...so even if he moved the one he put in his desktop or elsewhere , in reality each time he tries to open an instance of my application i close the instance and open instead the one saved in the c:\windows ... and my resgitry key will point for the one saved in c:\windows ...
then if the user wants to go and delete manually the one in c:\windows, it's his problem at the end, i can't do more, like any application if we delete it's original .exe it won't work properly !
What do you think about this idea ?
I have another question, if i want to Add 2 keys in the registry that point for my application, how can i detect from wich key the application is launched ?
the %1 is enough ? or i need other parameters ? if yes what the parameter that i need ? Is there any site that describe for expl %1 means what ? they told me %L= for folders etc....i am not finding a site listing all parameters...logically it has to be a parameters specifiying the name of the key that made the call !
By the way, you told me to make a key with 2 subkeys like options it's harder ?
Thanks again for all your support
-
Re: Add application to files context menu and send selected files as parameters
You should not put files in the Windows folder, because that is for files that are part of Windows itself. Depending on which version of Windows is being used and what anti-virus etc software is being used, and files you put there (and the program that puts them there) might be treated as malicious - and be automatically deleted, and/or warnings given to the user.
Instead you should use the Program Files folder, preferably with a sub-folder for your program.
You will not be able to detect if the user deletes your program (and they would be foolish to do that anyway), so you need to have some other way for them to remove it and the registry settings - such as a proper uninstaller, which you would have if you had a proper installation.
While it seems like a good idea to not have a setup process, it is not wise (which is why almost all programs have one). One reason for this is that you cannot be sure if even the basic VB runtimes are already installed, and they are mandatory - your program wont even start without them.
-
Re: Add application to files context menu and send selected files as parameters
thanks si_the_geek for your reply,
1) So is it a good idea in this case to add my application then to ProgramFiles and the reference in the registry will be for this instance and each time the user try to launch my application from any different location, i close the instance and launch the one in ProgramFiles ?
2) Any api that return the place of program files or i use Environ("ProgramFiles") ?
3) if i want to Add 2 keys in the registry that point for my application, how can i detect from wich key the application is launched ?
the %1 is enough ? or i need other parameters ? if yes what the parameter that i need ? Is there any site that describe for expl %1 means what ? they told me %L= for folders instead of %1 for files ....i am not finding a site listing all parameters and their signification...logically it has to be a parameters specifiying the name of the key that made the call !
4) Is it hard to make a Menu with subMenu ? Like the menu "Send to" once clicked we have many options (to desktop, to compressed file ...) I mean in contect windows i get a Menu MyApplication, inside it
5) thanks a lot to all of you :)
-
Re: Add application to files context menu and send selected files as parameters
Quote:
3) if i want to Add 2 keys in the registry that point for my application, how can i detect from wich key the application is launched ?
the %1 is enough ? or i need other parameters ? if yes what the parameter that i need ? Is there any site that describe for expl %1 means what ? they told me %L= for folders instead of %1 for files ....i am not finding a site listing all parameters and their signification...logically it has to be a parameters specifiying the name of the key that made the call !
why not do some testing and find what problems you get?
Quote:
4) Is it hard to make a Menu with subMenu ? Like the menu "Send to" once clicked we have many options (to desktop, to compressed file ...) I mean in contect windows i get a Menu MyApplication, inside it
see http://www.vbforums.com/showpost.php...7&postcount=15
Quote:
2) Any api that return the place of program files or i use Environ("ProgramFiles") ?
getspecialfolders API, but environ should work fine
Quote:
1) So is it a good idea in this case to add my application then to ProgramFiles and the reference in the registry will be for this instance and each time the user try to launch my application from any different location, i close the instance and launch the one in ProgramFiles ?
your program will not launch from context menu to call another instance, if the user is dumb enough to delete (or move) your program, too bad, they will need to reinstall
-
Re: Add application to files context menu and send selected files as parameters
Thanks again for the reply but there is 2 things i didn't understand well :
Quote:
Quote:
if i want to Add 2 keys in the registry that point for my application, how can i detect from wich key the application is launched ?
the %1 is enough ? or i need other parameters ? if yes what the parameter that i need ? Is there any site that describe for expl %1 means what ? they told me %L= for folders instead of %1 for files ....i am not finding a site listing all parameters and their signification...logically it has to be a parameters specifiying the name of the key that made the call !
Quote:
why not do some testing and find what problems you get?
Maybe you didn't understand me it's not a question of testing , i tested the%1 it worked to get file name, i tested the %L it worked to get folder name, but where can i find each ones mean what ? how you knew that %1= file name, %L folder name ? any site for that ?
Also the most important that i would like to know, is there a way to get the context menu that launched my application and how ?
Quote:
Quote:
1) So is it a good idea in this case to add my application then to ProgramFiles and the reference in the registry will be for this instance and each time the user try to launch my application from any different location, i close the instance and launch the one in ProgramFiles ?
Quote:
your program will not launch from context menu to call another instance, if the user is dumb enough to delete (or move) your program, too bad, they will need to reinstall
I didn't understand your answer, you mean my idea is good or better i make with another way ? and why ?how ?
Sorry again if i am asking too many questions and thanks for your support
-
Re: Add application to files context menu and send selected files as parameters
1) It is basically a good idea, but I don't see why you are concerned about them opening the program from other locations - it should only be in one place (in Program Files).
2) I recommend not using Environ if you can help it (users/programs can modify the values easily). There is a good example of SHGetFolderPath (with constants for several folders) here
3) I have never known any built-in parameters other than %1, and have never found a need for any others. In this case you should simply make up your own hard-coded parameters (such as /A ), the important thing is that your code knows what they mean.
-
Re: Add application to files context menu and send selected files as parameters
Quote:
1) It is basically a good idea, but I don't see why you are concerned about them opening the program from other locations - it should only be in one place (in Program Files).
1) It's because i am trying to make my application 1 exe only, so it's easy to move it by user....what i wanted was to prevent if he moves the application how it should react, i mean trying to simulate bad behaviors from user...but you are right, it's not my problem if the user want to mess and play with the application and move it to another location, if the application didn't work well it's his problem not mine
Quote:
2) I recommend not using Environ if you can help it (users/programs can modify the values easily). There is a good example of SHGetFolderPath (with constants for several folders)
here
thanks a lot, i will check it
Quote:
3) I have never known any built-in parameters other than %1, and have never found a need for any others. In this case you should simply make up your own hard-coded parameters (such as /A ), the important thing is that your code knows what they mean.
What i want is that my program send by command the file name and this is happening by the %1 param, but also, the name of the context menu, because i want to add 2 context menu for my application and i want to detect which one was clicked
-
Re: Add application to files context menu and send selected files as parameters
To send the name of the Key, what i did is that i added after the %1 another parameters
it become something like
"D:\Documents and Settings\User\Desktop\Testing.exe" %1%::::::::::NameOfKey
i choosed the ":::::::::" as delimiter between both parameters because ':' won't ever be a part of a folder or file name ...i said that such delimiter is better to avoid any confusion...
then to get the name of the key, i did this, on form load event
VB Code:
Dim sCommandLine() As String
sCommandLine = Split(Command$, "::::::::::")
For I = 0 To UBound(sCommandLine)
MsgBox sCommandLine(I)
Next I
Thus, am getting an array of 2 arguments 1st one containing the file and second one the name of the key !
Is this a proper solution or there is better ?
I got inspired from the post in which westconn1 said make tests and si_the_geek talked about /A param :)
I hope i got what you mean guys ....
By the way, what the % stands for ? i tried to give as parameter :::::::: without adding % and it worked so am not understanding what the % rule :)
-
Re: Add application to files context menu and send selected files as parameters
forward slash is a normal parameter separator, in windows or dos, but no reason you can't use any you want
if you do not use the % with the 1 the sent parameter will be "1" not the name of the file, that you want to get, you do not need it for other parameters, or following the 1
-
Re: Add application to files context menu and send selected files as parameters
Quote:
Originally Posted by
westconn1
forward slash is a normal parameter separator, in windows or dos, but no reason you can't use any you want
if you do not use the % with the 1 the sent parameter will be "1" not the name of the file, that you want to get, you do not need it for other parameters, or following the 1
Thanks for your post,
I will use the forward slash if it's the standard instead of :::::::::, but the way i did is the way we do ? or there is a better way ?
Please can you tell me where i can find details of each parameters ? i mean where to find that %1 will return the path file ? and that the %L will return the folder path .... I mean where you got the information from ? any site ?
i am not finding a site listing the meaning of each parameter, even if it's working now after your help, but i would like to learn all possible parameters
-
Re: Add application to files context menu and send selected files as parameters
Quote:
Originally Posted by
justgreat
... but the way i did is the way we do ? or there is a better way ?
That is the way it is done.
If you have any programs installed that are on the context menu (perhaps a virus scanner), check what they use - I would be surprised if they don't use this method (except if they only have one menu item).
Quote:
Please can you tell me where i can find details of each parameters ? i mean where to find that %1 will return the path file ? and that the %L will return the folder path .... I mean where you got the information from ? any site ?
i am not finding a site listing the meaning of each parameter, even if it's working now after your help, but i would like to learn all possible parameters
There is no reason for any more Windows-created parameters to exist - those two tell you everything that you need to know about the item that was selected (based on that you can write code to work out anything else you need to know about them).
For everything else (such as the current situation), you create your own parameters.
Quote:
Originally Posted by
justgreat
1) It's because i am trying to make my application 1 exe only, so it's easy to move it by user....
I used to think like that, but it is rather pointless... you are causing yourself lots of extra work (and dramatically increasing the chances of errors) to save the user a few seconds of installing.
The un-installing (which is definitely required in this case) will be harder, and if you have any code to cope with potential moves etc then your program will be slower, and your program will not even start at all unless they already have the VB runtimes installed from elsewhere.
Users expect programs to have an installation, so very few (if any) would be annoyed about having one.
-
Re: Add application to files context menu and send selected files as parameters
thanks for your reply, i agree with what you said you are right, the idea behind 1 exe is to help people that have bad connection to download the less possible thing (in many countries there is no DSL nor ADSL ) ! So i said i make 2 versions, one with installer(i use the one offered with vb) and one stand alone exe ... the user choose whatever he wants ....
Quote:
There is no reason for any more Windows-created parameters to exist - those two tell you everything that you need to know about the item that was selected (based on that you can write code to work out anything else you need to know about them).
Again i understand and agree with you, but am asking because till now i am not finding a site telling that %1 return file name, %L return folder, i am wondering why am not finding this information through google !! In addition, i said i lose nothing if someone passed me a link where all that is explained, i will get more information, nothing to lose, i like to learn the max possible things, maybe i won't use them in this application, but who knows in the coming one, that's why i always try to get the max possible information to learn ... i like to improve always
Here is how i am doing to ADD remove from the registry, dunno what do you think about , i tested on win xp it worked, don't have another OS to test can you confirm me that it works for Vista / 7 :
VB Code:
Private Const HKEY_CLASSES_ROOT As Long = &H80000000
Private Const REG_SZ As Long = &H1
Private Const KEY_ALL_ACCESS As Long = &HF003F
Private Const REG_OPTION_NON_VOLATILE As Long = 0
Private Declare Function RegCreateKeyEx Lib "advapi32" _
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, _
ByVal lpSecurityAttributes As Long, _
phkResult As Long, _
lpdwDisposition As Long) As Long
Private Declare Function RegOpenKeyEx Lib "advapi32" _
Alias "RegOpenKeyExA" _
(ByVal hKey As Long, _
ByVal lpSubKey As String, _
ByVal ulOptions As Long, _
ByVal samDesired As Long, _
phkResult As Long) As Long
Private Declare Function RegSetValueEx Lib "advapi32" _
Alias "RegSetValueExA" _
(ByVal hKey As Long, _
ByVal lpValueName As String, _
ByVal Reserved As Long, _
ByVal dwType As Long, _
lpValue As Any, _
ByVal cbData As Long) As Long
Private Declare Function RegDeleteKey Lib "advapi32.dll" _
Alias "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String) As Long
Private Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" _
(ByVal hKey As Long, ByVal lpValueName As String) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" _
(ByVal hKey As Long) As Long
Dim hKey As Long
Dim result As Long
Dim sPath As String
Dim sValue As String
Dim ret As Long
To Add :
VB Code:
Call RegCreateKeyEx(HKEY_CLASSES_ROOT, _
"*\Shell\Open With Toto\command", 0&, _
vbNullString, _
REG_OPTION_NON_VOLATILE, _
KEY_ALL_ACCESS, 0&, hKey, result)
sPath = """D:\Documents and Settings\User\Desktop\TOTO.exe""" & " " & """%1"""
sValue = sPath & Chr$(0)
Call RegSetValueEx(hKey, _
"", _
0&, _
REG_SZ, _
ByVal sValue, _
Len(sValue))
Call RegCloseKey(hKey)
To Delete :
VB Code:
Call RegOpenKeyEx(HKEY_CLASSES_ROOT, _
"*\Shell\Open With Toto\command", 0, _
KEY_ALL_ACCESS, hKey)
Call RegDeleteValue(hKey, "")
ret = RegDeleteKey(HKEY_CLASSES_ROOT, "*\Shell\Open With Toto\command")
ret = RegDeleteKey(HKEY_CLASSES_ROOT, "*\Shell\Open With Toto")
-
Re: Add application to files context menu and send selected files as parameters
Quote:
Originally Posted by
justgreat
thanks for your reply, i agree with what you said you are right, the idea behind 1 exe is to help people that have bad connection to download the less possible thing (in many countries there is no DSL nor ADSL ) ! So i said i make 2 versions, one with installer(i use the one offered with vb) and one stand alone exe ... the user choose whatever he wants ....
That is OK as long as you explain to them what circumstances an installation is needed, and when it might not be - otherwise they could download the small version and find it fails, so they need to download the large version too.
In terms of the installer, I hope you don't mean Package+Deployment Wizard, because that has lots of problems (and they get worse over time).
My personal preference is the official replacement, Visual Studio Installer. There are links to downloads and documentation in our Application Deployment FAQ.
Quote:
Again i understand and agree with you, but am asking because till now i am not finding a site telling that %1 return file name, %L return folder, i am wondering why am not finding this information through google !! ...
You aren't finding it because it isn't needed, you already have all of the information that could be useful.
I did a few quick searches, and the only relevant thing was this tiny snippet:
Quote:
%1 - the file/folder name (short)
%L - the file/folder name (long)
(the 'Long' "C:\Program Files\" would be the same as the 'Short' "C:\Progra~1\". Both are equally valid in VB code).
It is a complete waste of time to try to find more detail than that (you wont use it in this program or any you write in future). If really you want to know more then keep searching.
Quote:
Here is how i am doing to ADD remove from the registry, dunno what do you think about , i tested on win xp it worked, don't have another OS to test can you confirm me that it works for Vista / 7 :
...
You obviously didn't test well enough, because it is guaranteed to fail on XP under certain well-known circumstances. Even without re-booting this computer into XP, I know that it will fail for me - simply because I do not log in as an Admin.
You should go in to Control Panel and create a new 'limited' account, then test your program with that.
In Vista/7 it will always fail (unless you put in extra effort for UAC or similar), because you can't log in as an Admin.
That is another reason for using an installation package - because Windows will force the install/uninstall to run as Admin. If you get your installer/uninstaller to do the Admin tasks, you don't need to put large amounts of extra effort in to working-around the issues in your program.
-
Re: Add application to files context menu and send selected files as parameters
thanks a lot for your post, it was very interesting ...
Yes i was talking about the PDW .. But i will try the Visual Studio Installer i never used it before i hope it's free to use with visual studio applications...
You are right i just tested my PC under my account which is Admin ... So what you mean is that if the user doesn't have Admin rights, i won't be able to WRITE into the registry and my program will fail !! but with installer, the installer already won't work except if the user is admin....hummm i got you ...
Any other problem with what i wrote except the admin rights ? i mean if user has admin rights my program will work on vista and 7 ?
By the way before i add to registry i think i should check with IsUserAnAdmin Lib "shell32" () As Long if user is admin or not ...
thanks again to all of you for all these interesting information you are offering
-
Re: Add application to files context menu and send selected files as parameters
VSI is free.
The code in post #31 is fine apart from the Admin issue, which is caused by your use of HKEY_CLASSES_ROOT. Non-admin users can only write to HKEY_CURRENT_USER, which you can probably use for this - you just need to find the right location.
I probably wouldn't bother with IsUserAnAdmin, because even if you do it correctly it will only protect you against one potential issue with the code - instead just add a message to the error handler saying that admin rights are needed.
-
Re: Add application to files context menu and send selected files as parameters
thanks again,
I am trying to look for HKEY_CURRENT_USER equivalent of what i used but still not finding i will keep googleing it ... But if you know it please post it to make sure am making the right thing
when i said about IsUserAnAdmin, it was to check if he is not admin, i make a messagebox telling him that he needs the admin rights, and if he is an admin i don't say anything to avoid bothering with messages that make no sens.
-
Re: Add application to files context menu and send selected files as parameters
I knew what you meant about IsUserAnAdmin, and my comments were based on that - because the error handler will only run if there is an error (which might be due to no Admin rights, or something else).
-
Re: Add application to files context menu and send selected files as parameters
thanks again ,
I see, You mean that if i use error handler i will tell the user that the problem is due to admin rights or something else, but with IsUserAnAdmin, the user won't know about except the admin rights ...
I am trying to find the equivalent i couldn't on google, i tried myself some tests, and i succeded to make it with this , but i am worried about it because i am not sure of it, i mean it's not a solution that i read in a forum or book or elsewhere, it's me who tried to add keys , till i found adding that way will work, what do u think ?
To add context menu for files
HKEY_CURRENT_USER\Software\Classes\*\Shell\test Files
To add context menu for folders
HKEY_CURRENT_USER\Software\Classes\Folder\Shell\Test Folders
-
Re: Add application to files context menu and send selected files as parameters
If you don't have an error handler (and this applies to every part of your program) and an error occurs, the user will know about it... because they will see an error message (which might not make sense to them), then your program will simply exit.
With an error handler you can choose whether or not a message is shown, what the message contains (including the Admin text if you like), and what happens afterwards.
It generally isn't a good idea to deal with known issues with an error handler (using pre-emptive checks is normally the right way), but things like IsUserAnAdmin can have unexpected behaviour - I think somebody found recently that it returns True in some cases where it shouldn't have.
Those registry keys look right to me, but I haven't checked.
-
Re: Add application to files context menu and send selected files as parameters
thanks for your explication, i got you and will make it as you suggested.
Quote:
Those registry keys look right to me, but I haven't checked.
Please in case you or someone can confirm to me that it's good,let me know... i prefere to get a confirmation before i do it because i don't like to mess with users computer if am not sure at 100% from the registry am using
-
Re: Add application to files context menu and send selected files as parameters
I need your help again !
1st i finished the part that Add and delete from the registry the keys
Then i made the DDE part but I am getting an error and am unable to find why ! This error doesn't occur all the time...
What am doing is that am selecting files in windows explorer, i right click them and hit, the context menu that i Added (open with my application)
i noticed that if i right click on few files the error doesn't occur, but when i select more than 10 files, sometimes even less (not a specific number) here comes the following error :
---------------------------
Programme061209
---------------------------
Run-time error '285':
Foreign application won't perform DDE method or operation
---------------------------
OK
---------------------------
What happens is that some files are added to the listbox as expected and then i get the error for all the rest of instance ... of course i get the error messages N times (where N = total number of selected files or instances - number of files added to the list)
here is the code i am using :
vb Code:
Private Sub Form_LinkExecute(CmdStr As String, Cancel As Integer)
'if the command contain as second parameter f then it's coming from files context menu
'if it contains a d, it's coming from folders context menu
Dim sCmdStr() As String
sCmdStr = Split(CmdStr$, "::::::::::")
If sCmdStr(1) = "f" Then
'Addin a file
If Not ExistantElement(lstFiles, sCmdStr(0)) Then
lstFiles.AddItem (sCmdStr(0))
LstShortFilesNames.AddItem (GetDirOrShortFileName(sCmdStr(0), "file"))
End If
Else
'Adding Files from folder
If sCmdStr(1) = "d" Then
Dim FolderFiles() As String
If frmOptions.chkSelSubFolders.Value = 1 Then
FolderFiles = ListFiles(sCmdStr(0), True)
Else
FolderFiles = ListFiles(sCmdStr(0), False)
End If
For i = 0 To UBound(FolderFiles)
If Not ExistantElement(lstFiles, FolderFiles(i)) And FolderFiles(i) <> "" Then
lstFiles.AddItem (FolderFiles(i))
LstShortFilesNames.AddItem (GetDirOrShortFileName(FolderFiles(i), "file"))
End If
Next i
End If
End If
'adding scrollbars to the listboxes
Call AddScrollBars("lstFiles")
Call AddScrollBars("LstShortFilesNames")
Cancel = 0
End Sub
vb Code:
Private Sub Form_Load()
If App.PrevInstance Then
'Previous instance of App found
If Command$ <> vbNullString Then
'New commandLine parameters to send
HiddenText.Text = Command$
HiddenText.LinkMode = vbLinkNone
HiddenText.LinkTopic = "Programme061209|DDELink"
'Set the link topic
HiddenText.LinkMode = vbLinkManual
'Initiate the DDE link
HiddenText.LinkExecute HiddenText.Text
'Send data
HiddenText.LinkMode = vbLinkNone
'Close Link
End If
Unload Me
'Close the copy of the app
Exit Sub
End If
'DDE FOR FIRST INSTANCE START
If Command$ <> vbNullString Then
Dim sCommandLine() As String
sCommandLine = Split(Command$, "::::::::::")
If sCommandLine(1) = "f" Then
'on ajoute un fichier
If Not ExistantElement(lstFiles, sCommandLine(0)) Then
lstFiles.AddItem (sCommandLine(0))
LstShortFilesNames.AddItem (GetDirOrShortFileName(sCommandLine(0), "file"))
End If
Else '
'ADD FOLDER
If sCommandLine(1) = "d" Then
Dim FolderFiles() As String
If frmOptions.chkSelSubFolders.Value = 1 Then
FolderFiles = ListFiles(sCommandLine(0), True)
Else '
FolderFiles = ListFiles(sCommandLine(0), False)
End If '
For i = 0 To UBound(FolderFiles)
If Not ExistantElement(lstFiles, FolderFiles(i)) And FolderFiles(i) <> "" Then
lstFiles.AddItem (FolderFiles(i))
LstShortFilesNames.AddItem (GetDirOrShortFileName(FolderFiles(i), "file"))
End If
Next i
End If '
End If '
Call AddScrollBars("lstFiles")
Call AddScrollBars("LstShortFilesNames")
End If '
End Sub
Code:
'these 3 functions work normally i used them at many places in the program and never got a problem with them
' GetDirOrShortFileName == > function that returns the file name or the folder name, when we pass to it a full path
' ExistantElement == > Function checking if the element exists or not in the listbox
'ListFiles == > function that returns all the files included in a folder
Please help because if i can't send the files that the user selected my application won't make sens !
-
Re: Add application to files context menu and send selected files as parameters
sounds like your app is just not handling too many requests
try putting doevents into the formload before linkexecute
-
Re: Add application to files context menu and send selected files as parameters
Thanks for your reply , i tried but it didn't work unfortunatly..I tried to put it at different places, before linkexecute and after it and in the event linkexecute, always i am getting the same result !!
What is weird is that i took the example posted here but even this application gave the same result ! So it's not from my application, or there is something missing in the code, a property must be set ? Linkinvoke ? other ...Or that DDE is so slow so the computer can't support too many on same time and that's why i am getting the error !
Please do you know any other way than DEE where i can do what i want ? i think there is OLE or COM way, but am not finding any article about, i found about OLE how to add OCX to use them with word and excel but am not finding a tutoriel for OLE to handle multiple instances...in case you have let me know and in case you have any other idea than the doevents please let me know, cuz now am blocked, can't go forward in my application :(
-
Re: Add application to files context menu and send selected files as parameters
in the example i was working with, i am sure i used the change event of the hidden textbox, (when a link was poked to the textbox the change event would fire), to add the item to the list box, or what ever, i never noticed any restriction on the number of files it could handle, i am not sure now how many files i tried with, but it was quite a few, i was actually opening all the passed files, not just adding to a list
-
Re: Add application to files context menu and send selected files as parameters
Quote:
Originally Posted by justgreat(Via Mail
Dear sir,
I saw your article about DDE, and it's very usefull for beginners with DEE! Great job! unfortunatly i am trying to do the same and am getting an error even with your own code and i will explain to you the problem, maybe you can help to solve it...
I made an application that add to the registry the key HKEY_CLASSES_ROOT\*\Shell\Open With My Application\command...Once a user right click any file and hit the menu that i created "Open With My Application\", the file name is transfered to my application and my application will work on it...I tried to use your DEE example, so that when the user right click files in windows explorer and Open with my application, the new instance send to the old one the name of the file...The problem is that this is working when i select few number of files, but once i select lots of files (above 20 OR 50), i get the following Error :
Foreign application won't perform DDE method or operation
Do you have any idea to solve it ?
Thanks for listing all the details in the Mail..
Well the simple answer is .. the new instance will keep prompting the original instance of the application with DDE requests, however as the original app starts proccessing the requests, the reply time for each successive DDE request will increase. until eventualy it times out.
Two things to do..
Slow down the rate of sending the DDE requests. (perhaps add a timer and send a request at a rate of ~ 100- 200 ms..
Or.
Wait until all DDE Requests have been sent the start the proccess of opening all the files.
If at all Posible sending me the VB6 Source so that i can look over. You can get hold of me on GremlinSA
Gremmy....
-
Re: Add application to files context menu and send selected files as parameters
Thanks a lot for this explication, now i can understand where the problem comes from, but to solve it, i don't know how to apply the 2 suggestions that you proposed, because the requests come from the windows context menu almost, except if you mean that on form load i add a timer that hide my form from user , hold on some time, send the request, then unload the instance ... instead of directly sending the request.
Anyway, i will send you the source code it's gonna be better so that you see exactly what is going on....Can you send me in private your email in wich i can send you the source code ?
thanks a lot again for your reply
-
Re: Add application to files context menu and send selected files as parameters
Ok
I've viewed the project you sent through to me...
The number one thing i noticed is that you using recursive subs to parse all files from all sub directory's.. depending on how deep the directory's run, this can take quite some time..
AND .. VB6 is single threaded.. (and before anyone bites me for it, Multi-threading is accomplished by incorporating API Calls)
so while your application is 'Processing' the first DDE call, the rest wait until its finished, forming a long que, eventually the last ones will time out...
Looking at your code i have two possible solutions..
1) .. let the second instance of the application do all the hard work (Parse all the sub directory's) and DDE over the resulting CSV file list.
2) .. When the First DDE request comes in, Add it to a list, start a 1 second timer (or even possibly less) .. Any further DDE requests are added to the list, and the timer is reset. when the time has expired then start parsing the files one request at a time...
My personal opinion would be to use option 1..
Gremmy....
-
Re: Add application to files context menu and send selected files as parameters
Thanks for your reply !
But the problem is happening in all cases even when entering the if related to files only not folders ...
Just as reminder : i added 2 keys to the windows context menu, one that shows when user right click any file and the second one shows when user right click any folder..
So the error occurs in both case, even if user just right clicked on files only (not any folder selected), as i said above when the number of files is important (more than 20-30 for expl) the error occurs.....
here is the part for example , in wich the dde is not working and am not using anything recursive, i am adding the file name to the listbox called lstfiles and adding the short file name, to the listbox called LstShortFilesNames ...
maybe the function ExistantElement () is considered as slow because it searchs if the file exists or not in the listbox before adding it (But no recursion at all in this part)
The folder part that you are talking about is in the "else" (where i may use the recursion).....but in the files part i make almost nothing just checking if item exists, if not, adding short and long file name to 2 different listboxes and it's not working !
vb Code:
If sCmdStr(1) = "f" Then
'Addin a file
If Not ExistantElement(lstFiles, sCmdStr(0)) Then
lstFiles.AddItem (sCmdStr(0))
LstShortFilesNames.AddItem (GetDirOrShortFileName(sCmdStr(0), "file"))
End If
'here is the folder part you are talking about that may include recursion,
'but not all the times depends on the chkSelSubFolders.value !
Else
'Adding Files from folder
If sCmdStr(1) = "d" Then
Dim FolderFiles() As String
If frmOptions.chkSelSubFolders.Value = 1 Then
FolderFiles = ListFiles(sCmdStr(0), True)
Else
FolderFiles = ListFiles(sCmdStr(0), False)
End If
For i = 0 To UBound(FolderFiles)
If Not ExistantElement(lstFiles, FolderFiles(i)) And FolderFiles(i) <> "" Then
lstFiles.AddItem (FolderFiles(i))
LstShortFilesNames.AddItem (GetDirOrShortFileName(FolderFiles(i), "file"))
End If
Next i
End If
End If
After reading your comments, i think that even this part is too slow when you have a big number of files.
vb Code:
lstFiles.AddItem (sCmdStr(0))
LstShortFilesNames.AddItem (GetDirOrShortFileName(sCmdStr(0), "file"))
'GetDirOrShortFileName(sCmdStr(0), "file") is taking a path and returning the
'file short name !
So please can you check again and let me know do you suggest to solve it ? and in case you can give me details where should i start the timer and where to stop it in the code, in case the solution is the timers and in case the solution is the other one, than where to let the instance make the hard job ?at what even and where exactly in the code ?
NB: the recursion is only when i have thanks again
-
Re: Add application to files context menu and send selected files as parameters
I made tests after a question from vb5prgrmr and here is what i could notice !
CASE 1 : APPLICATION IS NOT RUNNING
I right clicked 50 files and made Open with my application,All is good, they were added to the listbox
I right clicked 450 files and made Open with my application, After the file 286, i started getting the error message for all the rest of files (Lots of error messages to close lol)
I right clicked after it 300 files and made Open with my application, the files were added without any error
I right clicked 345 files,same thing, no problem files were added
I right clicked 356 files and tried to add them, so 28 files were added to the listbox, and got error for all the rest
I right clicked 350 files and tried to add them, so 96 files were added to the listbox, and got error for all the rest
I right clicked 346 files and tried to add them, so 83 files were added to the listbox, and got error for all the rest
I right clicked 345 files again and tried to add them, so 83 files were added to the listbox, and got error for all the rest
I right clicked 344 files again and tried to add them, so also 83 files were added to the listbox, and got error for all the rest
I MADE AGAIN After a half Hour tried to right click 50 files to open with my application, and this time only 4 were added to the listbox and got error message for all the rest !
CASE 2 : APPLICATION ALREADY RUNNING
I made also many tests, i could sometimes add 6 files on times with no error, sometimes even at 5 files i get the error, sometimes at 8, sometimes adding 10 files cause the error ...what is sure is that i never got it when i add <= 3 Files
-
Re: Add application to files context menu and send selected files as parameters
I am trying to think about the solutions that you proposed but am not understanding well
Quote:
Originally Posted by
SAGremlin
1) .. let the second instance of the application do all the hard work (Parse all the sub directory's) and DDE over the resulting CSV file list.
So instead of making the work on link_execute i make it on form_load when a new instance is opened ?
But i don't think this will solve the problem cuz as i said, the problem is not only when i have folders, but even if i am simply adding files !
And it happened also with a bigger number of files, when i test it with the code of your tutorial so the problem is not the code but the speed !I mean the main program is getting lots of link_execute on time and unable to make them!
[B]Is there a way, to tell each new instance Wait Untill previous one finish it's work than you start your job ?[/B]
Quote:
Originally Posted by
SAGremlin
2) .. When the First DDE request comes in, Add it to a list, start a 1 second timer (or even possibly less) .. Any further DDE requests are added to the list, and the timer is reset. when the time has expired then start parsing the files one request at a time...
So let us say i added a timer of 1 second at the beginning of link_execute, and at the end i reset it, then what should i do ? i didn't understand well the solution ? how to detect that i finished getting commands from all instances and that now i can start processing ?
-
Re: Add application to files context menu and send selected files as parameters
The reply in this thread wasn't bad, please can you check my 2 questions to avoid that i repeat them here, maybe you can help, i am still facing these 2 problems
http://www.vbforums.com/showpost.php...42&postcount=9
http://www.vbforums.com/showpost.php...6&postcount=10
I hope you can help and thanks for your support again
-
Re: Add application to files context menu and send selected files as parameters
Please anyone has an answer to these 2 questions ? Maybe i had to keep them in this thread so that people can see and reply, so i will copy them again , please if anyone has an answer or any hint ?
1) i would like to know if there is a way to detect that all files names are transfered (all instances finished from transfering the files name) - very important for me because i need to know that the listbox received all the files names, before i start working on the files
2) if the user closed the windows explorer from which he right click on the files to send to my application, even if the program.exe(main instance) is still showing (not closed), the transfer of files name stop, do you have an idea how to solve this ? Programs like winzip, if the user closed the windows explorer, show a dialog box like if the files continues beeing transfer
-
Re: Add application to files context menu and send selected files as parameters
The only last thought that I have is that when you recieve these files from the DDE link in the existing program, is that you just make a list of those files and wait until you are no longer recieving those DDE links before you take action on those files.
Good Luck
-
Re: Add application to files context menu and send selected files as parameters
Quote:
Originally Posted by
vb5prgrmr
The only last thought that I have is that when you recieve these files from the DDE link in the existing program, is that you just make a list of those files and wait until you are no longer recieving those DDE links before you take action on those files.
Good Luck
thanks man, that's exactly what i want, but my question was how to detect that am not receiving anything anymore ? If i know how, i wouldn't post the question lol :)
By the way, i am no longer using DDE i found that using send message API is better , but the idea is the same, how to detect that am not recieving anymore the files and that the list is complete ?
If you can tell me how in DDE , even if it's not the same way as for SendMessage api
thanks again
-
Re: Add application to files context menu and send selected files as parameters
Well how are you doing it with sendmessage? Using a hidden textbox? Change event>Disable/enable timer (1000) set variable with GetTickCount API, add file to list/string/array>timer event>Check to see if last file sent is > GetTickCount API - 1000 (one second ago or greater last file was recieved).
I believe something like this if done efficiently might solve your problem...
Just a thought...
Good Luck
-
Re: Add application to files context menu and send selected files as parameters
Thank you,
Nope i am not using a hidden textbox.
At the beginning i was using the SendMessage with WM_COPYDATA based on the Code provided by Xiphias3 Here that shows how to pass a string from an application to it's primary instance. This code works good
Then LaVolpe passed me in this thread a usefull link that shows how to use WM_COPYDATA to pass an array of strings instead of simple strings ... Didn't try it yet, but it's so similar to first one, so it has to work and That's why i am going to do today, because with this way, i will be able to make more work in the instance before it passes the file name to the primary instance, so that the primary instance get the less possible job to do wich is good because it will receive many Send message if the user selects many files.
Now all that the primary instance has to do, is to check if the file exists in the list or not, if not than it adds it...Once all files are added, here the primary instance start processing them....
So To go back to my question, you suggest me to use timers ? How to manage them ? i mean what is the part that i have to do inside the timer ? when to set it's value to 1000 and when to turn it off 0 ?(i didn't understand well your previous post about timers)
Thanks Again to all of you for your support
-
Re: Add application to files context menu and send selected files as parameters
When you recieve the data is when you get the current time (GetTickCount API if you wish). This is also when you enable your timer or other non resource using timer (SetWaitableTimer). You would also store the information into whatever method you have decided upon.
Then when the timer goes off, you check the time to see if 1 second has pass since the last time you recieve information. If so, then turn off the timer and do your thing. If not, wait for the timer to go off again.
Good Luck
-
Re: Add application to files context menu and send selected files as parameters
Quote:
Originally Posted by
vb5prgrmr
When you recieve the data is when you get the current time (GetTickCount API if you wish). This is also when you enable your timer or other non resource using timer (SetWaitableTimer). You would also store the information into whatever method you have decided upon.
Then when the timer goes off, you check the time to see if 1 second has pass since the last time you recieve information. If so, then turn off the timer and do your thing. If not, wait for the timer to go off again.
Good Luck
Thanks for your reply, sorry but i am a bit confused...i am not understanding why i need the timer if i am already using the GetTickCount API ?
Let us say i receive the data in the Public Function WndProc
here i should get the time with GetTickCount ?
Then you said i enable the timer for 1 second ?
then i continue working inside the Function WndProc
if after 1 second the timer finished i check again the time with GetTickCount to see if 1 second has pass ? why ? if the timer is set to 1 second and it fires that means the 1 second pass already so why to check again with the GetTickCount ?
Please can you explain again because it seems i ddin't understand your algorithm !
-
Re: Add application to files context menu and send selected files as parameters
If your Timers Interval is set to 1000, you don't need GetTickCount - that would only be useful to get extra accuracy (which isn't important in this case).
However, rather than just Enable the timer, you will need to Disable it and then Enable it (so that the Interval restarts).
-
Re: Add application to files context menu and send selected files as parameters
Si's got it right...
My thought was the first message is recieved and the timer starts waiting upon its event to fire all the while you are processing those messages and setting the value of a variable with get the GetTickCount API. It was really in the hopes for program responsiveness because when the event fires you could test the difference between the message recieved GetTickCount and the timers GetTickCount and if the interval was large enough (100, 150, 250 milliseconds), then you could start processing. The thought was, was that you would have recieved all the file names by the time 1 second was up but just in case if the threshold was to low as in you might still be recieving messages, then you would continue to wait. But then again I really did not explain it well previously.
Now, back to Si's version. Perhaps to make the program more responsive you might want to play with the timer settings and reduce the interval of the timer.
Good Luck
-
Re: Add application to files context menu and send selected files as parameters
Thanks man, please confirm me if i got you ,
What you say is that, each time i enter the part in wich i receive the data, i disabled the timer, i make what i have to do, once finished i enable it with 1 seconds value...
if the timer fires this means i spent 1 second without getting any message from my application and that i can start processing the files (the timer will include the call to the procedure that will process the passed files) .
did i get it well ?
If yes please tell me, do i use the timers or the API, if api is better i am ready to use it, i need the better solution, because i didn't make this part yet, so i can do it as it should once for all instead of starting something and discovering that i had a better choice late...
waiting your suggestion