Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm making a batch file that is going to encrypt information. I made it so when I right click on the object and click on the "test" button it runs the batch file.

In regedit I added

Computer\HKEY_CLASSES_ROOT\*\shell\Test\command

command's data is

C:\Users\%username%\Desktop\encrypt.bat

What do I need to do to the data (in the registry key i added) and what is it stored as in my variable?

share|improve this question
    
The last sentence does not make sense to me. What do you mean by "what do I need to do to the data"? –  user3463 Jun 1 '12 at 22:04
    
I don't know about adding a selection to the right click shell menu, but if you go to Start, Run -> shell:sendto, you can add a shortcut or batch script and it will show up on a right click -> Send To. Also, if you use a batch script, the file name will be in %0, and full name (path + filename) will be in %1. –  Caleb Jares Jun 1 '12 at 23:21
    
Okay were getting there but I need to know what variable would be the text. Thanks for helping –  Jake Inc. Jun 1 '12 at 23:24

1 Answer 1

up vote 0 down vote accepted

You need to associate to the filetype the script you want to launch on that type. On Windows, all this is based on the extension (at least on XP, I don't know about 7, but I doubt it has changed). Say the extension of your files are ".abc", and your app is:

c:\program files\dummy\process.bat

(I dropped the variable for the moment, I'm not sure how this behaves in .reg files)

So just edit a config.reg text file that will hold the following:

Windows Registry Editor Version 5.00

; the extension .abc gets associated with a file type
[HKEY_CLASSES_ROOT\.abc]
@="abc-file"

; the file-type gets a name (that appears in explorer in field "type")
[HKEY_CLASSES_ROOT\abc-file]
@="foo file"

; What will appear in the contextual menu when selecting an .abc file
[HKEY_CLASSES_ROOT\abc-file\shell\cmdname-1]
@="--- Process ! ----"

; What to do with it
; here, %1 is the file given as argument of the script
[HKEY_CLASSES_ROOT\abc-file\shell\cmdname-1\command]
@="\"c:\\program files\\dummy\\process.bat\" \"%1\""

Finally import it. You're done.

Additional comments:

  • All the strange quotes and backslashes are there to allow correct handling of names with spaces. Yes, I now, nobody has spaces in file names.. Or do they ? Anyway, that happens!
  • You can of course have several commands for a file type. Just dupe the last two keys of the .reg (cmdname-1 ==> cmdname-2)
  • You can also associate different file extensions to the same file type. for example, HTML files can have either .htm or .html
  • You can even associate an action to folders. replace the file type by "folder"
  • It can be useful to provide a "uninstall" functionality. Just create another reg file and prefixe the created keys with '-'.
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.