Skip to content

Commit

Permalink
Add Visual Studio 2022 support #6, Fix deven.sln dialog #5
Browse files Browse the repository at this point in the history
  • Loading branch information
Samir Boulema committed Nov 11, 2021
1 parent f76d70b commit 4bbc45b
Show file tree
Hide file tree
Showing 13 changed files with 196 additions and 204 deletions.
89 changes: 89 additions & 0 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: RunAsAdmin

on:
push:
branches:
- main
- 'feature/**'

env:
version: '2.0.${{ github.run_number }}'
repoUrl: ${{ github.server_url }}/${{ github.repository }}

jobs:
build:
name: Build
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Update Assembly Version
uses: dannevesdantas/[email protected]
with:
version: ${{ env.version }}

- name: Update Vsix Version
uses: cezarypiatek/[email protected]
with:
version: ${{ env.version }}
vsix-manifest-file: 'TGit\source.extension.vsixmanifest'

- name: Setup MSBuild
uses: microsoft/[email protected]

- name: NuGet restore
run: nuget restore RunAsAdmin.sln

- name: Build VSIX
run: msbuild RunAsAdmin.sln /t:Rebuild /p:Configuration=Release
env:
DeployExtension: False

- name: Publish Build Artifacts
uses: actions/upload-artifact@v2
with:
name: RunAsAdmin
path: |
**\*.vsix
publish-manifest.json
readme.md
release:
name: Release
needs: build
runs-on: windows-latest
environment: Release
steps:
- name: Download artifact
uses: actions/download-artifact@v2

- name: Tag release
id: tag_release
uses: mathieudutour/[email protected]
with:
custom_tag: '${{ env.version }}'
github_token: ${{ secrets.GITHUB_TOKEN }}

- name: Create a GitHub release
uses: ncipollo/release-action@v1
with:
tag: ${{ steps.tag_release.outputs.new_tag }}
name: ${{ steps.tag_release.outputs.new_tag }}
body: ${{ steps.tag_release.outputs.changelog }}
artifacts: "**/*.vsix"

- name: Publish to Marketplace
uses: cezarypiatek/[email protected]
with:
extension-file: RunAsAdmin/RunAsAdmin/release/RunAsAdmin.vsix
publish-manifest-file: RunAsAdmin/publish-manifest.json
personal-access-code: ${{ secrets.VS_PUBLISHER_ACCESS_TOKEN }}

- name: Publish to Open VSIX Gallery
uses: leandro-hermes/[email protected]
with:
host: 'www.vsixgallery.com'
path: '/api/upload?repo=${{ env.repoUrl }}&issuetracker=${{ env.repoUrl }}/issues'
https: true
filePath: RunAsAdmin/RunAsAdmin/bin/release/RunAsAdmin.vsix
19 changes: 11 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# RunAsAdmin
Visual Studio extension to run Visual Studio as administrator

[![Beerpay](https://img.shields.io/beerpay/sboulema/RunAsAdmin.svg?style=flat)](https://beerpay.io/sboulema/RunAsAdmin)
[![Build Status](https://github.com/sboulema/RunAsAdmin/actions/workflows/workflow.yml/badge.svg)](https://github.com/sboulema/RunAsAdmin/actions/workflows/workflow.yml)
[![Sponsor](https://img.shields.io/badge/-Sponsor-fafbfc?logo=GitHub%20Sponsors)](https://github.com/sponsors/sboulema)

## Installing
[Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=SamirBoulema.RunAsAdmin) ![Visual Studio Marketplace](http://vsmarketplacebadge.apphb.com/version-short/SamirBoulema.RunAsAdmin.svg)
Expand All @@ -10,8 +11,6 @@ Visual Studio extension to run Visual Studio as administrator

[Open VSIX Gallery](http://vsixgallery.com/extension/dda2a29d-8fd9-4131-adc5-afcf6ef36b25/)

[AppVeyor](https://ci.appveyor.com/project/sboulema/runasadmin) [![Build status](https://ci.appveyor.com/api/projects/status/swx1byhk0tuxsbog?svg=true)](https://ci.appveyor.com/project/sboulema/runasadmin)

## Run Visual Studio as administrator
1. Install the [RunAsAdmin](https://marketplace.visualstudio.com/items?itemName=SamirBoulema.RunAsAdmin) extension
2. Go to Tools -> Options -> RunAsAdmin
Expand All @@ -24,16 +23,20 @@ Visual Studio extension to run Visual Studio as administrator
3. Restart Visual Studio

## Uninstalling the extension
When uninstalling the extension the current elevation mode will be preserved. If you have the extension Enabled in the options and uninstall it, Visual Studio will remain running as administrator. You have to use the RunAsAdmin options setting to enable or disable.
When uninstalling the extension the current elevation mode will be preserved.
If you have the extension Enabled in the options and uninstall it,
Visual Studio will remain running as administrator.
You have to use the RunAsAdmin options setting to enable or disable.

## Disabling the extension
When disabling the extension from within the Visual Studio extensions dialog nothing will happen like with uninstalling the extension. You have to use the RunAsAdmin options setting to enable or disable.
When disabling the extension from within the Visual Studio extensions dialog nothing will happen like with uninstalling the extension.
You have to use the RunAsAdmin options setting to enable or disable.

### Under the hood
The extension adds a registry entry at the following location: `HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers\`

Where the "Name" will be the path to Visual Studio and the value will be "RUNASADMIN" or "RUNASNORMAL"

---

![VS2017 Partner](http://i.imgur.com/wlgwRF1.png)
## Thanks
Cazzulino - [How to get Visual Studio 2017 installation path](https://www.cazzulino.com/how-to-get-vsinstallroot.html)
Rick van den Bosch - [Running Visual Studio as an administrator causes ‘Save changes to devenv.sln’ when double clicking solutions](https://www.rickvandenbosch.net/blog/running-visual-studio-as-an-administrator-causes-save-changes-to-devenv-sln-when-double-clicking-solutions/)
9 changes: 6 additions & 3 deletions RunAsAdmin.sln
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.28210.120
# Visual Studio Version 17
VisualStudioVersion = 17.1.31903.286
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{34FFEFE9-DE5F-45DF-A277-B92ED6A1C66F}"
ProjectSection(SolutionItems) = preProject
azure-pipelines.yml = azure-pipelines.yml
publish-manifest.json = publish-manifest.json
README.md = README.md
.github\workflows\workflow.yml = .github\workflows\workflow.yml
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RunAsAdmin", "RunAsAdmin\RunAsAdmin.csproj", "{62B3201D-A451-4A9E-B956-E44AD7152787}"
Expand All @@ -26,4 +26,7 @@ Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {DB591417-1FC2-47CF-BF21-7B186833A479}
EndGlobalSection
EndGlobal
9 changes: 0 additions & 9 deletions RunAsAdmin/DteHelper.cs

This file was deleted.

11 changes: 0 additions & 11 deletions RunAsAdmin/GlobalSuppressions.cs

This file was deleted.

Binary file removed RunAsAdmin/Key.snk
Binary file not shown.
55 changes: 55 additions & 0 deletions RunAsAdmin/Options/General.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using Community.VisualStudio.Toolkit;
using Microsoft.VisualStudio.Setup.Configuration;
using Microsoft.Win32;
using System;
using System.ComponentModel;
using System.IO;

namespace SamirBoulema.RunAsAdmin
{
internal partial class OptionsProvider
{
public class GeneralOptions : BaseOptionPage<General> { }
}

public class General : BaseOptionModel<General>
{
private const string RegistryFolder =
@"HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers\";
private const string VSLauncherInstallationPath = @"C:\Program Files (x86)\Common Files\Microsoft Shared\MSEnv\VSLauncher.exe";
private readonly string _installationPath = GetVisualStudioInstallationPath();

[Category("RunAsAdmin")]
[DisplayName(@"Enabled")]
[Description("Run Visual Studio as administrator. Restart Visual Studio for the applied changes to take effect")]
public bool Enabled
{
get => IsAdminEnabled();
set => RunAsAdmin(value);
}

private void RunAsAdmin(bool enable)
{
Registry.SetValue(RegistryFolder, _installationPath, enable ? "RUNASADMIN" : "RUNASNORMAL");
Registry.SetValue(RegistryFolder, VSLauncherInstallationPath, enable ? "RUNASADMIN" : "RUNASNORMAL");
}

private bool IsAdminEnabled()
{
var runAsAdminKeyDevEnv = Registry.GetValue(RegistryFolder, _installationPath, null) as string;

return runAsAdminKeyDevEnv?.Equals("RUNASADMIN") == true;
}

private static string GetVisualStudioInstallationPath()
{
var config = (ISetupConfiguration2)
Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("177F0C4A-1CD3-4DE7-A32C-71DBBB9FA36D")));
var instance = config.GetInstanceForCurrentProcess();

var installationFolder = instance.GetInstallationPath();

return Path.Combine(installationFolder, @"Common7\IDE\devenv.exe");
}
}
}
26 changes: 4 additions & 22 deletions RunAsAdmin/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,36 +1,18 @@
using System;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("RunAsAdmin")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Funda Real Estate B.V.")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("RunAsAdmin")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: CLSCompliant(false)]
[assembly: NeutralResourcesLanguage("en-US")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:

[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]



[assembly: AssemblyFileVersion("1.0.0.0")]
2 changes: 1 addition & 1 deletion RunAsAdmin/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4bbc45b

Please sign in to comment.