Skip to content

Commit

Permalink
register app for local user, does not require admin rights
Browse files Browse the repository at this point in the history
  • Loading branch information
galich committed Jul 13, 2017
1 parent b5a1e3b commit 8b6d7cf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
23 changes: 14 additions & 9 deletions PasteAsFile/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ public static void UnRegisterApp()
{
try
{
var key = Registry.ClassesRoot.OpenSubKey("Directory").OpenSubKey("Background").OpenSubKey("shell",true);
key.DeleteSubKeyTree("Paste As File");
var key = OpenDirectoryKey().OpenSubKey(@"Background\shell", true);
key.DeleteSubKeyTree("Paste As File");

key = Registry.ClassesRoot.OpenSubKey("Directory").OpenSubKey("shell", true);
key.DeleteSubKeyTree("Paste As File");
key = OpenDirectoryKey().OpenSubKey("shell", true);
key.DeleteSubKeyTree("Paste As File");

MessageBox.Show("Application has been Unregistered from your system", "Paste As File", MessageBoxButtons.OK, MessageBoxIcon.Information);

Expand All @@ -63,12 +63,12 @@ public static void RegisterApp()
{
try
{
var key = Registry.ClassesRoot.OpenSubKey("Directory").OpenSubKey("Background").OpenSubKey("shell",true).CreateSubKey("Paste As File");
key = key.CreateSubKey("command");
var key = OpenDirectoryKey().CreateSubKey(@"Background\shell").CreateSubKey("Paste As File");
key = key.CreateSubKey("command");
key.SetValue("", Application.ExecutablePath + " \"%V\"");

key = Registry.ClassesRoot.OpenSubKey("Directory").OpenSubKey("shell",true).CreateSubKey("Paste As File");
key = key.CreateSubKey("command");
key = OpenDirectoryKey().CreateSubKey("shell").CreateSubKey("Paste As File");
key = key.CreateSubKey("command");
key.SetValue("", Application.ExecutablePath + " \"%1\"");
MessageBox.Show("Application has been registered with your system", "Paste As File", MessageBoxButtons.OK, MessageBoxIcon.Information);

Expand Down Expand Up @@ -100,5 +100,10 @@ public static void RestartApp()
}
Application.Exit();
}
}

static RegistryKey OpenDirectoryKey()
{
return Registry.CurrentUser.CreateSubKey(@"Software\Classes\Directory");
}
}
}
4 changes: 2 additions & 2 deletions PasteAsFile/frmMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ private void frmMain_Load(object sender, EventArgs e)
txtFilename.Text = DateTime.Now.ToString("dd-MM-yyyy HH-mm-ss");
txtCurrentLocation.Text = CurrentLocation ?? @"C:\";

if (Registry.GetValue(@"HKEY_CLASSES_ROOT\Directory\Background\shell\Paste As File\command", "", null) == null)
{
if (Registry.GetValue(@"HKEY_CURRENT_USER\Software\Classes\Directory\Background\shell\Paste As File\command", "", null) == null)
{
if (MessageBox.Show("Seems that you are running this application for the first time,\nDo you want to Register it with your system Context Menu ?", "Paste As File", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
Program.RegisterApp();
Expand Down

0 comments on commit 8b6d7cf

Please sign in to comment.