-
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 !