Windows 7 How to let a WinExplorer context menu run (only as administrator)?

pstein

Extraordinary Member
Joined
Mar 20, 2010
Messages
454
I would like to add a new item for Directories to the WinExplorer context menu.
In former WInXP I simply add the following Registry entry:

[HKEY_CLASSES_ROOT\Directory\shell\OpenCmdPrompt\command]
@="D:\\specialprog\\batchlog \"%1\""

However: This command is not recognized (for normal users) in Win7.

Why?

Furthermore (in der next step!!!) this entry should only be runnable as administrator.
Where EXACTLY should I put this command in Registry so that it cannot be run as normal user but as administrator

Peter
 


Solution
To add a new item to the Windows Explorer context menu for directories and restrict its execution to only be allowed for administrators in Windows 7, you need to make modifications to the Windows Registry. However, there are a few considerations to keep in mind:
  1. Windows Vista and later versions introduced User Account Control (UAC), which restricts administrative privileges. This means that even if a user account is part of the Administrators group, the commands are not automatically run with elevated privileges unless explicitly requested.
  2. Running the context menu entry as an administrator would require UAC elevation.

    Steps to Create a Elevated Context Menu Entry for Directories:​

  3. Navigate to the Registry...
To add a new item to the Windows Explorer context menu for directories and restrict its execution to only be allowed for administrators in Windows 7, you need to make modifications to the Windows Registry. However, there are a few considerations to keep in mind:
  1. Windows Vista and later versions introduced User Account Control (UAC), which restricts administrative privileges. This means that even if a user account is part of the Administrators group, the commands are not automatically run with elevated privileges unless explicitly requested.
  2. Running the context menu entry as an administrator would require UAC elevation.

    Steps to Create a Elevated Context Menu Entry for Directories:​

  3. Navigate to the Registry Editor:
    • Press Win + R to open the "Run" dialog.
    • Type regedit and press Enter to open the Registry Editor.
    []Create a Registry Entry for the Context Menu Item:
    • Navigate to the following Registry key:
      Code:
       HKEY_CLASSES_ROOT\Directory\shell
    • Create a new key under shell. Name it according to your preference, such as OpenCmdPromptAdmin.
    • Inside the newly created key, create a new key named command.
    • Set the default value of the command key to the path of the executable or script you want to run with elevated privileges.
    [
    ]Modify the Registry Entry to Require Elevated Privileges:
    • To enforce running the command with administrative privileges, you can use a tool like runas to elevate the command prompt.
    • Update the default value of the command key to include runas /user:Administrator before the command to ensure it runs as an administrator.

      Example Registry Entry:​

      Here is an example of how the Registry entry for the context menu item might look:
      Code:
      HKEY_CLASSES_ROOT\Directory\shell\OpenCmdPromptAdmin\command @="runas /user:Administrator D:\\specialprog\\batchlog \"%1\""

      Important Note:​

      Always exercise caution when making changes to the Windows Registry, as incorrect modifications can cause system issues. Make sure to back up the Registry before making any changes. After creating this entry, when a regular user tries to access this context menu item, they will be prompted for administrator credentials to run the command with elevated privileges.
 


Solution
Back
Top