Skip to content
This repository has been archived by the owner on Dec 5, 2023. It is now read-only.

Commit

Permalink
Merge pull request #20 from WereDev/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
WereDev committed May 25, 2020
2 parents b42daa1 + 7252f9d commit dcf230c
Show file tree
Hide file tree
Showing 108 changed files with 4,637 additions and 1,912 deletions.
102 changes: 62 additions & 40 deletions AdvancedInstaller/wu10man.aip

Large diffs are not rendered by default.

206 changes: 206 additions & 0 deletions AdvancedInstaller/wu10man.back.aip

Large diffs are not rendered by default.

695 changes: 674 additions & 21 deletions LICENSE

Large diffs are not rendered by default.

Expand Up @@ -4,9 +4,9 @@
using System.Runtime.InteropServices;

// https://stackoverflow.com/questions/1304/how-to-check-for-file-lock#3202085
namespace WereDev.Utils.Wu10Man.Win32Wrappers
namespace WereDev.Utils.Win32Wrappers
{
static public class FileWrapper
public static class FileAccessBridge
{
[StructLayout(LayoutKind.Sequential)]
struct RM_UNIQUE_PROCESS
Expand Down Expand Up @@ -80,22 +80,20 @@ struct RM_PROCESS_INFO
/// http://wyupdate.googlecode.com/svn-history/r401/trunk/frmFilesInUse.cs (no copyright in code at time of viewing)
///
/// </remarks>
static public List<Process> WhoIsLocking(string path)
public static List<Process> WhoIsLocking(string path)
{
uint handle;
string key = Guid.NewGuid().ToString();
List<Process> processes = new List<Process>();

int res = RmStartSession(out handle, 0, key);
int res = RmStartSession(out uint handle, 0, key);

if (res != 0)
throw new Exception("Could not begin restart session. Unable to determine file locker.");

try
{
const int ERROR_MORE_DATA = 234;
uint pnProcInfoNeeded = 0,
pnProcInfo = 0,
uint pnProcInfo = 0,
lpdwRebootReasons = RmRebootReasonNone;

string[] resources = new string[] { path }; // Just checking on one resource.
Expand All @@ -108,7 +106,7 @@ static public List<Process> WhoIsLocking(string path)
//Note: there's a race condition here -- the first call to RmGetList() returns
// the total number of process. However, when we call RmGetList() again to get
// the actual processes this number may have increased.
res = RmGetList(handle, out pnProcInfoNeeded, ref pnProcInfo, null, ref lpdwRebootReasons);
res = RmGetList(handle, out uint pnProcInfoNeeded, ref pnProcInfo, null, ref lpdwRebootReasons);

if (res == ERROR_MORE_DATA)
{
Expand Down
27 changes: 27 additions & 0 deletions WereDev.Utils.Win32Wrappers/Models/ServiceConfigInfo.cs
@@ -0,0 +1,27 @@
using System.Runtime.InteropServices;

namespace WereDev.Utils.Win32Wrappers.Models
{
[StructLayout(LayoutKind.Sequential)]
public class ServiceConfigInfo
{
[MarshalAs(UnmanagedType.U4)]
public uint ServiceType;
[MarshalAs(UnmanagedType.U4)]
public uint StartType;
[MarshalAs(UnmanagedType.U4)]
public uint ErrorControl;
[MarshalAs(UnmanagedType.LPWStr)]
public string BinaryPathName;
[MarshalAs(UnmanagedType.LPWStr)]
public string LoadOrderGroup;
[MarshalAs(UnmanagedType.U4)]
public uint TagID;
[MarshalAs(UnmanagedType.LPWStr)]
public string Dependencies;
[MarshalAs(UnmanagedType.LPWStr)]
public string ServiceStartName;
[MarshalAs(UnmanagedType.LPWStr)]
public string DisplayName;
}
}
35 changes: 35 additions & 0 deletions WereDev.Utils.Win32Wrappers/Properties/AssemblyInfo.cs
@@ -0,0 +1,35 @@
using System.Reflection;
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("WereDev.Utils.Win32Wrappers")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("WereDev")]
[assembly: AssemblyProduct("WereDev.Utils.Win32Wrappers")]
[assembly: AssemblyCopyright("Copyright © 2018-2020")]
[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("11e7c6da-6d2c-4ffd-9b2b-80646fdf9500")]

// 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 Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
50 changes: 50 additions & 0 deletions WereDev.Utils.Win32Wrappers/WereDev.Utils.Win32Wrappers.csproj
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{11E7C6DA-6D2C-4FFD-9B2B-80646FDF9500}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>WereDev.Utils.Win32Wrappers</RootNamespace>
<AssemblyName>WereDev.Utils.Win32Wrappers</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<RunCodeAnalysis>false</RunCodeAnalysis>
<CodeAnalysisRuleSet>SecurityRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<RunCodeAnalysis>false</RunCodeAnalysis>
<CodeAnalysisRuleSet>
</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
</ItemGroup>
<ItemGroup>
<Compile Include="FileAccessBridge.cs" />
<Compile Include="Models\ServiceConfigInfo.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="WindowsApiBridge.cs" />
<Compile Include="WindowsServiceBridge.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
@@ -1,11 +1,12 @@
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Security.Principal;

namespace WereDev.Utils.Wu10Man.Win32Wrappers
{
internal static class WinApiWrapper
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Security.Principal;

// https://stackoverflow.com/questions/17031552/how-do-you-take-file-ownership-with-powershell/17047190#17047190
namespace WereDev.Utils.Win32Wrappers
{
public static class WindowsApiBridge
{
private const uint SE_PRIVILEGE_ENABLED = 2;

Expand All @@ -24,22 +25,22 @@ public static bool ModifyPrivilege(PrivilegeName privilege, bool enable)

using (var identity = WindowsIdentity.GetCurrent(TokenAccessLevels.AdjustPrivileges | TokenAccessLevels.Query))
{
var newPriv = new TokenPrivileges
{
Privileges = new LuidAndAttributes[]
{
new LuidAndAttributes {
Luid = luid,
Attributes = enable ? SE_PRIVILEGE_ENABLED : 0
}
},
PrivilegeCount = 1
var newPriv = new TokenPrivileges
{
Privileges = new LuidAndAttributes[]
{
new LuidAndAttributes {
Luid = luid,
Attributes = enable ? SE_PRIVILEGE_ENABLED : 0
}
},
PrivilegeCount = 1
};

var prevPriv = new TokenPrivileges
{
Privileges = new LuidAndAttributes[1],
PrivilegeCount = 1
var prevPriv = new TokenPrivileges
{
Privileges = new LuidAndAttributes[1],
PrivilegeCount = 1
};

if (!AdjustTokenPrivileges(identity.Token, false, ref newPriv, (uint)Marshal.SizeOf(prevPriv), ref prevPriv, out uint returnedBytes))
Expand Down Expand Up @@ -80,7 +81,7 @@ private struct Luid
}
}

internal enum PrivilegeName
public enum PrivilegeName
{
SeAssignPrimaryTokenPrivilege,
SeAuditPrivilege,
Expand Down Expand Up @@ -117,5 +118,5 @@ internal enum PrivilegeName
SeTrustedCredManAccessPrivilege,
SeUndockPrivilege,
SeUnsolicitedInputPrivilege,
}
}
}
}
@@ -1,33 +1,33 @@
using System;
using System.Runtime.InteropServices;

namespace WereDev.Utils.Wu10Man.Win32Wrappers
{
public static class ServiceWrapper
{
using System;
using System.Runtime.InteropServices;

namespace WereDev.Utils.Win32Wrappers
{
public static class WindowsServiceBridge
{
public const uint SC_MANAGER_ALL_ACCESS = 0x000F003F;
public const uint SC_MANAGER_QUERY_ACESS = 0x10000000;
public const uint SERVICE_NO_CHANGE = 0xffffffff; //this value is found in winsvc.h
public const uint SERVICE_QUERY_CONFIG = 0x00000001;
public const uint SERVICE_CHANGE_CONFIG = 0x00000002;
//public const uint SERVICE_QUERY_STATUS = 0x00000004;
//public const uint SERVICE_ENUMERATE_DEPENDENTS = 0x00000008;
//public const uint SERVICE_START = 0x00000010;
//public const uint SERVICE_STOP = 0x00000020;
//public const uint SERVICE_PAUSE_CONTINUE = 0x00000040;
//public const uint SERVICE_INTERROGATE = 0x00000080;
//public const uint SERVICE_USER_DEFINED_CONTROL = 0x00000100;
//public const uint STANDARD_RIGHTS_REQUIRED = 0x000F0000;
//public const uint SERVICE_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED |
// SERVICE_CHANGE_CONFIG |
// SERVICE_QUERY_STATUS |
// SERVICE_ENUMERATE_DEPENDENTS |
// SERVICE_START |
// SERVICE_STOP |
// SERVICE_PAUSE_CONTINUE |
// SERVICE_INTERROGATE |
// SERVICE_USER_DEFINED_CONTROL);

public const uint SERVICE_QUERY_STATUS = 0x00000004;
public const uint SERVICE_ENUMERATE_DEPENDENTS = 0x00000008;
public const uint SERVICE_START = 0x00000010;
public const uint SERVICE_STOP = 0x00000020;
public const uint SERVICE_PAUSE_CONTINUE = 0x00000040;
public const uint SERVICE_INTERROGATE = 0x00000080;
public const uint SERVICE_USER_DEFINED_CONTROL = 0x00000100;
public const uint STANDARD_RIGHTS_REQUIRED = 0x000F0000;
public const uint SERVICE_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED |
SERVICE_CHANGE_CONFIG |
SERVICE_QUERY_STATUS |
SERVICE_ENUMERATE_DEPENDENTS |
SERVICE_START |
SERVICE_STOP |
SERVICE_PAUSE_CONTINUE |
SERVICE_INTERROGATE |
SERVICE_USER_DEFINED_CONTROL);

[DllImport("advapi32.dll", SetLastError = true, CharSet = CharSet.Auto)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool ChangeServiceConfig(IntPtr hService, UInt32 nServiceType, UInt32 nStartType, UInt32 nErrorControl, String lpBinaryPathName, String lpLoadOrderGroup, IntPtr lpdwTagId, String lpDependencies, String lpServiceStartName, String lpPassword, String lpDisplayName);
Expand All @@ -46,6 +46,6 @@ public static class ServiceWrapper
public static extern bool CloseServiceHandle(IntPtr hSCObject);

[DllImport("advapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern Boolean QueryServiceConfig(IntPtr hService, IntPtr intPtrQueryConfig, UInt32 cbBufSize, out UInt32 pcbBytesNeeded);
}
}
public static extern Boolean QueryServiceConfig(IntPtr hService, IntPtr intPtrQueryConfig, UInt32 cbBufSize, out UInt32 pcbBytesNeeded);
}
}
@@ -1,16 +1,11 @@
using Autofac;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WereDev.Utils.Wu10Man
{
public static class DependencyManager
{
public static IContainer Container { get; set; }

public static T Resolve<T>() => Container.Resolve<T>();
}
}
using Autofac;

namespace WereDev.Utils.Wu10Man.Core
{
public static class DependencyManager
{
public static IContainer Container { get; set; }

public static T Resolve<T>() => Container.Resolve<T>();
}
}
32 changes: 32 additions & 0 deletions WereDev.Utils.Wu10Man.Core/Enums/ServiceStartMode.cs
@@ -0,0 +1,32 @@
namespace WereDev.Utils.Wu10Man.Core.Enums
{
public enum ServiceStartMode
{
// Summary:
// Indicates that the service is a device driver started by the system loader. This
// value is valid only for device drivers.
Boot = 0,

// Summary:
// Indicates that the service is a device driver started by the IOInitSystem function.
// This value is valid only for device drivers.
System = 1,

// Summary:
// Indicates that the service is to be started (or was started) by the operating
// system, at system start-up. If an automatically started service depends on a
// manually started service, the manually started service is also started automatically
// at system startup.
Automatic = 2,

// Summary:
// Indicates that the service is started only manually, by a user (using the Service
// Control Manager) or by an application.
Manual = 3,

// Summary:
// Indicates that the service is disabled, so that it cannot be started by a user
// or application.
Disabled = 4,
}
}

0 comments on commit dcf230c

Please sign in to comment.