?
Solved

Add console application to windows xp context menu

Posted on 2008-01-29
9
Medium Priority
?
550 Views
Last Modified: 2010-04-05
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
0
Comment
Question by:Mark Brady
  • 5
  • 4
9 Comments
 
LVL 9

Expert Comment

by:arioh
ID: 20775369
0
 
LVL 20

Author Comment

by:Mark Brady
ID: 20775390
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
 
LVL 9

Expert Comment

by:arioh
ID: 20775428
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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 20

Author Comment

by:Mark Brady
ID: 20775875
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
 
LVL 20

Author Comment

by:Mark Brady
ID: 20788178
Any more thoughts on my question ?
0
 
LVL 9

Accepted Solution

by:
arioh earned 500 total points
ID: 20820506
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
 
LVL 20

Author Comment

by:Mark Brady
ID: 20820675
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
 
LVL 9

Expert Comment

by:arioh
ID: 20820838
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
 
LVL 20

Author Comment

by:Mark Brady
ID: 20821353
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

Featured Post

2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Issue: Unstable cursor in Windows XP and Windows runs extremely slow in that any click will bring up the Hour glass (sometimes for several seconds before giving you what you want) . Troubleshooting Process and the FINAL FIX: This issue see…
This is an update to some code that someone else posted on Experts Exchange. It is an alternate approach, I think a little easier to use, & makes sure that things like the Task Bar will update.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
How to fix display issue, screen flickering issue when I plug in power cord to the machine. Before I start explaining the solution lets check out once the issue how it looks like after I connect the power cord. most of you also have faced this…

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question