Note that there are some explanatory texts on larger screens.

plurals
  1. POadd shortcut to my program when right click
    primarykey
    data
    text
    <p>Im not sure what the exact term should i called. I want to add shortcut to my C# program when i right click in windows.</p> <p>From my findings, it got something to do with configure the "regedit". I have this example, but it was made for IE. can anyone point me to any references that can solve my problems?</p> <p>references:</p> <p><em><a href="http://blog.voidnish.com/?p=17" rel="nofollow noreferrer">http://blog.voidnish.com/?p=17</a></em> <em><a href="http://www.codeguru.com/cpp/misc/misc/internetexplorer/article.php/c11007/" rel="nofollow noreferrer">http://www.codeguru.com/cpp/misc/misc/internetexplorer/article.php/c11007/</a></em></p> <p>thank you very much.</p> <p><strong>UPDATED today..</strong></p> <p>Based on response from Factor Mystic, i add this code to the original. I have 2 solutions. One, It was created in registry <strong>HKEY_ CLASSES_ ROOT</strong>, but i cannot see the result when i right click the doc files. </p> <pre><code>private const string ProgName = "Software\\Classes\\Word.Document\\shell"; private const string MenuName = "Software\\Classes\\Word.Document\\shell\\NewTesting"; public const string Command =Software\\Classes\\Word.Document\\shell\\NewTesting\\command"; private void Form1_Load(object sender, EventArgs e) { txtProgram.Text = "Word.Document.8"; txtName.Text = "Testing"; txtPath.Text = "C:\\temp\\encriptTest.exe"; check(); addItem() } public void check() { RegistryKey regmenu = null; RegistryKey regcmd = null; try { //this.CheckSecurity(); regmenu = Registry.ClassesRoot.OpenSubKey(MenuName, false); } catch (ArgumentException ex) { // RegistryPermissionAccess.AllAccess can not be used as a parameter for GetPathList. MessageBox.Show(this, "An ArgumentException occured as a result of using AllAccess. " + "AllAccess cannot be used as a parameter in GetPathList because it represents more than one " + "type of registry variable access : \n" + ex); } catch (SecurityException ex) { // RegistryPermissionAccess.AllAccess can not be used as a parameter for GetPathList. MessageBox.Show(this, "An ArgumentException occured as a result of using AllAccess. " + ex); this.btnAddMenu.Enabled = false; //this.btnRemoveMenu.Enabled = false; } catch (Exception ex) { MessageBox.Show(this, ex.ToString()); } finally { if (regmenu != null) regmenu.Close(); if (regcmd != null) regcmd.Close(); } } private void CheckSecurity() { //check registry permissions RegistryPermission regPerm; regPerm = new RegistryPermission(RegistryPermissionAccess.Write, "HKEY_CLASSES_ROOT\\" + ProgName); regPerm.AddPathList(RegistryPermissionAccess.Write, "HKEY_CLASSES_ROOT\\" + MenuName); regPerm.AddPathList(RegistryPermissionAccess.Write, "HKEY_CLASSES_ROOT\\" + Command); regPerm.Demand(); } private void addItem() { RegistryKey regmenu = null; RegistryKey regcmd = null; RegistryKey regprog = null; try { regprog = Registry.ClassesRoot.CreateSubKey(ProgName); if (regmenu != null) regmenu.SetValue("", this.txtProgram.Text); regmenu = Registry.ClassesRoot.CreateSubKey(MenuName); if (regmenu != null) regmenu.SetValue("", this.txtName.Text); regcmd = Registry.ClassesRoot.CreateSubKey(Command); if (regcmd != null) regcmd.SetValue("", this.txtPath.Text); } catch (Exception ex) { MessageBox.Show(this, ex.ToString()); } finally { if (regprog != null) regprog.Close(); if (regmenu != null) regmenu.Close(); if (regcmd != null) regcmd.Close(); } } </code></pre> <p><strong>Second, create in HKEY_ LOCAL_ MACHINE.</strong></p> <pre><code>private bool Add_Item(string Extension,string MenuName, string MenuDescription, string MenuCommand) { //receive .doc,OpenTest,Open with Opentest,path: C:\\temp\\encriptTest.exe %1 bool ret = false; RegistryKey rkey = //receive .doc extension (word.Document.8) Registry.ClassesRoot.OpenSubKey(Extension); //set HKEY_LOCAL_MACHINE\software\classes\word.Document.8 if (rkey != null) { string extstring = rkey.GetValue("").ToString(); rkey.Close(); if (extstring != null) { if (extstring.Length &gt; 0) { rkey = Registry.ClassesRoot.OpenSubKey(extstring, true); if (rkey != null) //with extension file receive OpenTest as shell { string strkey = "shell\\" + MenuName + "\\command"; //..\shell\OpenTest\command RegistryKey subky = rkey.CreateSubKey(strkey); if (subky != null) { subky.SetValue("", MenuCommand); // path: C:\\temp\\encriptTest.exe %1 subky.Close(); subky = rkey.OpenSubKey("shell\\" + MenuName, true); //..\shell\OpenTest if (subky != null) { subky.SetValue("", MenuDescription); // name displayed: Open with &amp;OpenTest subky.Close(); } ret = true; } rkey.Close(); } } } } return ret; } } </code></pre> <p>My concerned, which Main Key should i use?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload