Skip to content

Commit

Permalink
added elevated process to copy iisnode-inspector
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith committed Sep 27, 2012
1 parent 42d3f32 commit 8cb774d
Show file tree
Hide file tree
Showing 9 changed files with 232 additions and 42 deletions.
75 changes: 75 additions & 0 deletions NodeElevator/NodeElevator.csproj
@@ -0,0 +1,75 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<Win32Resource>NodeElevator.res</Win32Resource>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<FileUpgradeFlags>
</FileUpgradeFlags>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<OldToolsVersion>2.0</OldToolsVersion>
</PropertyGroup>
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.50727</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{98A6DFBA-7E3C-4C39-94EE-DC67E2A8741A}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>NodeElevator</RootNamespace>
<AssemblyName>NodeElevator</AssemblyName>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\NodePowerTools\bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<UseVSHostingProcess>false</UseVSHostingProcess>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="NodeElevator.exe.manifest">
<SubType>Designer</SubType>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Include="NodeElevator.res" />
</ItemGroup>
<ItemGroup>
<Content Include="iisnode-inspector.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
<PropertyGroup>
<PreBuildEvent>
</PreBuildEvent>
</PropertyGroup>
</Project>
15 changes: 15 additions & 0 deletions NodeElevator/NodeElevator.exe.manifest
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8" ?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity version="1.0.0.0"
processorArchitecture="X86"
name="NodeElevator"
type="win32" />
<description>NodeElevator</description>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="requireAdministrator" />
</requestedPrivileges>
</security>
</trustInfo>
</assembly>
Binary file added NodeElevator/NodeElevator.res
Binary file not shown.
Binary file added NodeElevator/iisnode-inspector.dll
Binary file not shown.
42 changes: 42 additions & 0 deletions NodeElevator/program.cs
@@ -0,0 +1,42 @@
using System;
using System.Text;
using System.IO;

namespace PrivilegedExe
{
class Program
{
static int Main(string[] args)
{
int retVal = 1;

try
{

var programfiles = Environment.GetEnvironmentVariable("ProgramFiles(x86)");
var path = programfiles + @"\iisnode-dev\release\x86\iisnode-inspector.dll";
if (!File.Exists(path))
{
File.Copy("iisnode-inspector.dll", programfiles + @"\iisnode-dev\release\x86\iisnode-inspector.dll");
}

retVal = 0;
}
catch (System.Security.SecurityException secEx)
{
retVal = 1;
}
catch (UnauthorizedAccessException authEx)
{
retVal = 2;
}
catch (Exception ex)
{
retVal = 3;
}
Console.WriteLine("NodeElevator completed with return code: {0}", retVal.ToString());

return (retVal);
}
}
}
33 changes: 33 additions & 0 deletions NodeElevator/properties/assemblyinfo.cs
@@ -0,0 +1,33 @@
using System.Reflection;
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("PrivilegedExe")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("PrivilegedExe")]
[assembly: AssemblyCopyright("Copyright © 2006")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("0683a9e2-6d29-4bea-a806-a10181eeaa3f")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
12 changes: 9 additions & 3 deletions NodePowerTools.sln
@@ -1,6 +1,6 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 11
# Visual Studio 2012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NodePowerTools", "NodePowerTools\NodePowerTools.csproj", "{0AD95D26-46AE-416F-8C3F-B0C18E437C48}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{801D5147-DDE0-4558-BCBD-66A5243E1823}"
Expand All @@ -9,6 +9,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
readme.md = readme.md
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NodeElevator", "NodeElevator\NodeElevator.csproj", "{98A6DFBA-7E3C-4C39-94EE-DC67E2A8741A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -17,8 +19,12 @@ Global
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{0AD95D26-46AE-416F-8C3F-B0C18E437C48}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0AD95D26-46AE-416F-8C3F-B0C18E437C48}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0AD95D26-46AE-416F-8C3F-B0C18E437C48}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0AD95D26-46AE-416F-8C3F-B0C18E437C48}.Release|Any CPU.Build.0 = Release|Any CPU
{0AD95D26-46AE-416F-8C3F-B0C18E437C48}.Release|Any CPU.ActiveCfg = Debug|Any CPU
{0AD95D26-46AE-416F-8C3F-B0C18E437C48}.Release|Any CPU.Build.0 = Debug|Any CPU
{98A6DFBA-7E3C-4C39-94EE-DC67E2A8741A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{98A6DFBA-7E3C-4C39-94EE-DC67E2A8741A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{98A6DFBA-7E3C-4C39-94EE-DC67E2A8741A}.Release|Any CPU.ActiveCfg = Debug|Any CPU
{98A6DFBA-7E3C-4C39-94EE-DC67E2A8741A}.Release|Any CPU.Build.0 = Debug|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
1 change: 1 addition & 0 deletions NodePowerTools/NodePowerTools.csproj
Expand Up @@ -31,6 +31,7 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.VisualBasic" />
<Reference Include="Microsoft.WebMatrix.Extensibility">
<HintPath>C:\Program Files (x86)\Microsoft WebMatrix\Microsoft.WebMatrix.Extensibility.dll</HintPath>
</Reference>
Expand Down
96 changes: 57 additions & 39 deletions NodePowerTools/WebMatrixExtension.cs
Expand Up @@ -11,6 +11,8 @@
using Microsoft.WebMatrix.Extensibility.Editor;
using System.Collections.Generic;
using System.ComponentModel;
using System.Security.Principal;
using System.Reflection;

namespace NodePowerTools
{
Expand All @@ -19,7 +21,7 @@ namespace NodePowerTools
/// </summary>
[Export(typeof(Extension))]
public class WebMatrixExtension : Extension
{
{

//--------------------------------------------------------------------------
//
Expand Down Expand Up @@ -60,23 +62,23 @@ public class WebMatrixExtension : Extension
protected IWebMatrixHost _host;


private static readonly Guid _outputTaskPanelId = new Guid("2f09fa84-888f-47c9-b333-b3501a0055b4");
private IEditorTaskPanelService _editorTaskPanel;
private ISiteFileWatcherService _siteFileWatcher;
private OutputWindow _outputWindow;
private string _mainScriptPath;
[Import(ThemeKeys.DefaultTheme, typeof(ITheme))]
private ITheme DefaultTheme { get; set; }
[Import(typeof(IEditorTaskPanelService))]
private IEditorTaskPanelService EditorTaskPanelService
{
get
{
return _editorTaskPanel;
}
set
private static readonly Guid _outputTaskPanelId = new Guid("2f09fa84-888f-47c9-b333-b3501a0055b4");
private IEditorTaskPanelService _editorTaskPanel;
private ISiteFileWatcherService _siteFileWatcher;
private OutputWindow _outputWindow;
private string _mainScriptPath;

[Import(ThemeKeys.DefaultTheme, typeof(ITheme))]
private ITheme DefaultTheme { get; set; }

[Import(typeof(IEditorTaskPanelService))]
private IEditorTaskPanelService EditorTaskPanelService
{
get
{
return _editorTaskPanel;
}
set
{
_editorTaskPanel = value;
}
Expand Down Expand Up @@ -113,29 +115,21 @@ public WebMatrixExtension()
{
_launchDebuggerCommand = new DelegateCommand(p =>
{
// check if google chrome is installed
if (!IsChromeInstalled())
try
{
_mainScriptPath = this.GetMainFileName();
var nodeInspectorUrl = string.Format("{0}/{1}/debug", _host.WebSite.Uri.ToString(), _mainScriptPath);
Process.Start("chrome", nodeInspectorUrl);
}
catch (Win32Exception ex)
{
_host.ShowNotification("Chrome is not installed! Node Inspector requires Chrome.");
}
else
catch (Exception ex)
{
try
{
_mainScriptPath = this.GetMainFileName();
var nodeInspectorUrl = string.Format("{0}/{1}/debug", _host.WebSite.Uri.ToString(), _mainScriptPath);
Process.Start("chrome", nodeInspectorUrl);
}
catch (Win32Exception ex)
{
_host.ShowNotification("Chrome is not installed! Node Inspector requires Chrome.");
}
catch (Exception ex)
{
_host.ShowExceptionMessage("Node Power Tools", "There was a problem launching chrome. Are you sure it's installed?", ex);
}
//Process.Start("chrome", _host.WebSite.Uri.ToString());
_host.ShowExceptionMessage("Node Power Tools", "There was a problem launching chrome. Are you sure it's installed?", ex);
}
//Process.Start("chrome", _host.WebSite.Uri.ToString());
});
}
#endregion
Expand Down Expand Up @@ -187,7 +181,10 @@ protected override void Initialize(IWebMatrixHost host, ExtensionInitData data)
_ribbonGroup.IsVisible = _host.Workspace is IEditorWorkspace && _isNodeSite;
InitializeLogTab(this, EventArgs.Empty);
}
}

InstallNodeInspector();

}
}
#endregion

Expand Down Expand Up @@ -273,7 +270,7 @@ protected void host_ContextMenuOpening(object sender, ContextMenuOpeningEventArg
e.AddMenuItem(menuItem);
}
}

#endregion

//--------------------------------------------------------------------------
Expand Down Expand Up @@ -311,7 +308,7 @@ protected bool IsChromeInstalled()
{
using (RegistryKey tkey = key.OpenSubKey(name))
{
if (tkey != null && tkey.GetValue("name") != null && tkey.GetValue("name").ToString() == "Google Chrome")
if (tkey != null && tkey.GetValue("name") != null && tkey.GetValue("name").ToString() == "Google Chrome")
return true;
}
}
Expand Down Expand Up @@ -405,5 +402,26 @@ protected void OpenCMD(object e)
}

#endregion

#region InstallNodeInspector
/// <summary>
/// launch NodeElevator process to elevate up and copy iisnode-inspector to the right path
/// </summary>
protected void InstallNodeInspector()
{
var pathToExe = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "NodeElevator.exe");

var psi = new ProcessStartInfo()
{
FileName = pathToExe,
CreateNoWindow = true,
WindowStyle = ProcessWindowStyle.Hidden
};

var process = Process.Start(psi);
process.WaitForExit();
}

#endregion
}
}

0 comments on commit 8cb774d

Please sign in to comment.