Add console application to windows xp context menu

I have a small forms application that I want to convert to a console app.  What I need it to do is when the user right clicks on a file (any file) I want the context menu to say eg: 'RunmyApp' .   A small form would open up and allow the user to input something then the file is resaved.

In a nutshell, here is what my current forms program does.
1: Reads a file into a memory stream, reads it into another stream backwards (so from end)
2: Adds a line of text at the front of the stream and saves it back to disk.

Of course it does the same in reverse.

What I need is knowledge on how to make it console only so it only runs when selected from context menu.

Eg:   User right clicks on 'MyFile.jpg'
On the context menu it has an option 'Reverse File'
Once clicked, it should then open a form and execute my code and resave it (my code already does that)
The saved file is saved with and added extention so the context menu needs to also recognise if a file has been altered with my code and resaved, so it will then say, 'UnReverse File'

I would then need to have the program run on startup I guess ?

Any help would be appreciated.

Elvin
LVL 20
Mark BradyPrincipal Data EngineerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mark BradyPrincipal Data EngineerAuthor Commented:
That may be what I need but I will need it explained a little better.  Does this code go inside my application ?  How is it run etc.....   I really need all of the above answered.  I know it is not difficult to do (by anyone other than me right now).  I just need a small example using my instructions above.  Thanks anyway.

0
ariohCommented:
Put this code in your app and check for registry settings every startup. If there are no such keys and values, then invoke the code with "Adding" set to true. If you need to remove your app from context menu, then invoke the code with "Adding" set to false.
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

Mark BradyPrincipal Data EngineerAuthor Commented:
Arioh

I'm sorry but I still don't understand.  I need an example application or a full explanation of what I asked in my question.  I don't know how to make my forms application a console app.  Please show me an example of a console application and how it would run when windows starts.

Elvin
0
Mark BradyPrincipal Data EngineerAuthor Commented:
Any more thoughts on my question ?
0
ariohCommented:
sorry, was too busy
here is working example below
program ConsApp;
 
{$APPTYPE CONSOLE}
 
uses
  Windows, Registry;
 
const
  DirExtensionKey = 'Directory\shell\encrypt';
  FileExtensionKey = '*\shell\';
  SubKey = '\command';
  ContextName= 'MyAppContext';
 
function AlreadyAdded : boolean;
var
  reg: TRegistry;
begin
  Result := false;
  try
    reg := TRegistry.Create;
  except
    Exit;
  end;
  with reg do
    begin
      RootKey := HKEY_CLASSES_ROOT;
      Result := KeyExists( FileExtensionKey + ContextName + SubKey );
    end;
  reg.Free;
end;
 
procedure AddEntryToExplMenu( Adding:boolean );
var 
  reg: TRegistry; 
begin 
  try 
    reg := TRegistry.Create; 
  except 
    Exit; 
  end; 
  if Adding then 
    with reg do 
      begin 
        RootKey := HKEY_CLASSES_ROOT; 
        OpenKey( FileExtensionKey, Adding ); 
        WriteString( '', ContextName ); 
        CloseKey; 
        OpenKey( FileExtensionKey + ContextName + SubKey, Adding );
        WriteString( '', ParamStr(0) + ' "%1"' ); 
        CloseKey; 
      end 
    else 
      with reg do 
        begin 
          RootKey := HKEY_CLASSES_ROOT; 
          DeleteKey( FileExtensionKey + ContextName ); 
          CloseKey; 
        end; 
  reg.Free; 
end;
 
begin
  if ( not AlreadyAdded ) then
    AddEntryToExplMenu( true );
  WriteLn( 'My context app launched' );
  WriteLn( 'Press enter...' );
  ReadLn;
end.

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mark BradyPrincipal Data EngineerAuthor Commented:
Thanks Arioh

Do you have any ideas on the rest of the question ?  Once an item has been changed with my program, to change the item in the context menu ?  
Eg:

right click on 'my.jpg'    on the context menu click 'Reverse'
program reverses the file and renames it my.jpg.loc'

If right click on ''my.jpg.loc' then should have an option on context menu that says 'Unreverse'

Any idea on how to achieve this ?

Elvin
0
ariohCommented:
I have 2 suggestions
1. add a context menu element for "loc" extension
2. add 2 elements to context menu: "Reverse" and "Unreverse" and let the user to decide what to do
0
Mark BradyPrincipal Data EngineerAuthor Commented:
I thought of that but if I have an application that doesn't add the second entry (unreverse) until a file with the 'loc extention is clicked on.

At the end of the day, I have it working with one context entry called 'Lock/Unlock' and I program code to act accordingly depending on the file extention  but I would still like to know how to achive what I have seen done.

Seems like no one else is going to help out in this question so I'll give you the points.  Thanks buddy
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.