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

Commit dcf230c

Browse files
authored
Merge pull request #20 from WereDev/develop
Develop
2 parents b42daa1 + 7252f9d commit dcf230c

108 files changed

Lines changed: 4637 additions & 1912 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

AdvancedInstaller/wu10man.aip

Lines changed: 62 additions & 40 deletions
Large diffs are not rendered by default.

AdvancedInstaller/wu10man.back.aip

Lines changed: 206 additions & 0 deletions
Large diffs are not rendered by default.

LICENSE

Lines changed: 674 additions & 21 deletions
Large diffs are not rendered by default.

Wu10Man/Win32Wrappers/FileWrapper.cs renamed to WereDev.Utils.Win32Wrappers/FileAccessBridge.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
using System.Runtime.InteropServices;
55

66
// https://stackoverflow.com/questions/1304/how-to-check-for-file-lock#3202085
7-
namespace WereDev.Utils.Wu10Man.Win32Wrappers
7+
namespace WereDev.Utils.Win32Wrappers
88
{
9-
static public class FileWrapper
9+
public static class FileAccessBridge
1010
{
1111
[StructLayout(LayoutKind.Sequential)]
1212
struct RM_UNIQUE_PROCESS
@@ -80,22 +80,20 @@ static extern int RmGetList(uint dwSessionHandle,
8080
/// http://wyupdate.googlecode.com/svn-history/r401/trunk/frmFilesInUse.cs (no copyright in code at time of viewing)
8181
///
8282
/// </remarks>
83-
static public List<Process> WhoIsLocking(string path)
83+
public static List<Process> WhoIsLocking(string path)
8484
{
85-
uint handle;
8685
string key = Guid.NewGuid().ToString();
8786
List<Process> processes = new List<Process>();
8887

89-
int res = RmStartSession(out handle, 0, key);
88+
int res = RmStartSession(out uint handle, 0, key);
9089

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

9493
try
9594
{
9695
const int ERROR_MORE_DATA = 234;
97-
uint pnProcInfoNeeded = 0,
98-
pnProcInfo = 0,
96+
uint pnProcInfo = 0,
9997
lpdwRebootReasons = RmRebootReasonNone;
10098

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

113111
if (res == ERROR_MORE_DATA)
114112
{
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System.Runtime.InteropServices;
2+
3+
namespace WereDev.Utils.Win32Wrappers.Models
4+
{
5+
[StructLayout(LayoutKind.Sequential)]
6+
public class ServiceConfigInfo
7+
{
8+
[MarshalAs(UnmanagedType.U4)]
9+
public uint ServiceType;
10+
[MarshalAs(UnmanagedType.U4)]
11+
public uint StartType;
12+
[MarshalAs(UnmanagedType.U4)]
13+
public uint ErrorControl;
14+
[MarshalAs(UnmanagedType.LPWStr)]
15+
public string BinaryPathName;
16+
[MarshalAs(UnmanagedType.LPWStr)]
17+
public string LoadOrderGroup;
18+
[MarshalAs(UnmanagedType.U4)]
19+
public uint TagID;
20+
[MarshalAs(UnmanagedType.LPWStr)]
21+
public string Dependencies;
22+
[MarshalAs(UnmanagedType.LPWStr)]
23+
public string ServiceStartName;
24+
[MarshalAs(UnmanagedType.LPWStr)]
25+
public string DisplayName;
26+
}
27+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System.Reflection;
2+
using System.Runtime.InteropServices;
3+
4+
// General Information about an assembly is controlled through the following
5+
// set of attributes. Change these attribute values to modify the information
6+
// associated with an assembly.
7+
[assembly: AssemblyTitle("WereDev.Utils.Win32Wrappers")]
8+
[assembly: AssemblyDescription("")]
9+
[assembly: AssemblyConfiguration("")]
10+
[assembly: AssemblyCompany("WereDev")]
11+
[assembly: AssemblyProduct("WereDev.Utils.Win32Wrappers")]
12+
[assembly: AssemblyCopyright("Copyright © 2018-2020")]
13+
[assembly: AssemblyTrademark("")]
14+
[assembly: AssemblyCulture("")]
15+
16+
// Setting ComVisible to false makes the types in this assembly not visible
17+
// to COM components. If you need to access a type in this assembly from
18+
// COM, set the ComVisible attribute to true on that type.
19+
[assembly: ComVisible(false)]
20+
21+
// The following GUID is for the ID of the typelib if this project is exposed to COM
22+
[assembly: Guid("11e7c6da-6d2c-4ffd-9b2b-80646fdf9500")]
23+
24+
// Version information for an assembly consists of the following four values:
25+
//
26+
// Major Version
27+
// Minor Version
28+
// Build Number
29+
// Revision
30+
//
31+
// You can specify all the values or you can default the Build and Revision Numbers
32+
// by using the '*' as shown below:
33+
// [assembly: AssemblyVersion("1.0.*")]
34+
[assembly: AssemblyVersion("1.0.0.0")]
35+
[assembly: AssemblyFileVersion("1.0.0.0")]
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{11E7C6DA-6D2C-4FFD-9B2B-80646FDF9500}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>WereDev.Utils.Win32Wrappers</RootNamespace>
11+
<AssemblyName>WereDev.Utils.Win32Wrappers</AssemblyName>
12+
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
<Deterministic>true</Deterministic>
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
<DebugSymbols>true</DebugSymbols>
18+
<DebugType>full</DebugType>
19+
<Optimize>false</Optimize>
20+
<OutputPath>bin\Debug\</OutputPath>
21+
<DefineConstants>DEBUG;TRACE</DefineConstants>
22+
<ErrorReport>prompt</ErrorReport>
23+
<WarningLevel>4</WarningLevel>
24+
<RunCodeAnalysis>false</RunCodeAnalysis>
25+
<CodeAnalysisRuleSet>SecurityRules.ruleset</CodeAnalysisRuleSet>
26+
</PropertyGroup>
27+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
28+
<DebugType>none</DebugType>
29+
<Optimize>true</Optimize>
30+
<OutputPath>bin\Release\</OutputPath>
31+
<DefineConstants>TRACE</DefineConstants>
32+
<ErrorReport>prompt</ErrorReport>
33+
<WarningLevel>4</WarningLevel>
34+
<RunCodeAnalysis>false</RunCodeAnalysis>
35+
<CodeAnalysisRuleSet>
36+
</CodeAnalysisRuleSet>
37+
</PropertyGroup>
38+
<ItemGroup>
39+
<Reference Include="System" />
40+
<Reference Include="System.Core" />
41+
</ItemGroup>
42+
<ItemGroup>
43+
<Compile Include="FileAccessBridge.cs" />
44+
<Compile Include="Models\ServiceConfigInfo.cs" />
45+
<Compile Include="Properties\AssemblyInfo.cs" />
46+
<Compile Include="WindowsApiBridge.cs" />
47+
<Compile Include="WindowsServiceBridge.cs" />
48+
</ItemGroup>
49+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
50+
</Project>

Wu10Man/Win32Wrappers/WinApiWrapper.cs renamed to WereDev.Utils.Win32Wrappers/WindowsApiBridge.cs

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
using System;
2-
using System.ComponentModel;
3-
using System.Runtime.InteropServices;
4-
using System.Security.Principal;
5-
6-
namespace WereDev.Utils.Wu10Man.Win32Wrappers
7-
{
8-
internal static class WinApiWrapper
1+
using System;
2+
using System.ComponentModel;
3+
using System.Runtime.InteropServices;
4+
using System.Security.Principal;
5+
6+
// https://stackoverflow.com/questions/17031552/how-do-you-take-file-ownership-with-powershell/17047190#17047190
7+
namespace WereDev.Utils.Win32Wrappers
8+
{
9+
public static class WindowsApiBridge
910
{
1011
private const uint SE_PRIVILEGE_ENABLED = 2;
1112

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

2526
using (var identity = WindowsIdentity.GetCurrent(TokenAccessLevels.AdjustPrivileges | TokenAccessLevels.Query))
2627
{
27-
var newPriv = new TokenPrivileges
28-
{
29-
Privileges = new LuidAndAttributes[]
30-
{
31-
new LuidAndAttributes {
32-
Luid = luid,
33-
Attributes = enable ? SE_PRIVILEGE_ENABLED : 0
34-
}
35-
},
36-
PrivilegeCount = 1
28+
var newPriv = new TokenPrivileges
29+
{
30+
Privileges = new LuidAndAttributes[]
31+
{
32+
new LuidAndAttributes {
33+
Luid = luid,
34+
Attributes = enable ? SE_PRIVILEGE_ENABLED : 0
35+
}
36+
},
37+
PrivilegeCount = 1
3738
};
3839

39-
var prevPriv = new TokenPrivileges
40-
{
41-
Privileges = new LuidAndAttributes[1],
42-
PrivilegeCount = 1
40+
var prevPriv = new TokenPrivileges
41+
{
42+
Privileges = new LuidAndAttributes[1],
43+
PrivilegeCount = 1
4344
};
4445

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

83-
internal enum PrivilegeName
84+
public enum PrivilegeName
8485
{
8586
SeAssignPrimaryTokenPrivilege,
8687
SeAuditPrivilege,
@@ -117,5 +118,5 @@ internal enum PrivilegeName
117118
SeTrustedCredManAccessPrivilege,
118119
SeUndockPrivilege,
119120
SeUnsolicitedInputPrivilege,
120-
}
121-
}
121+
}
122+
}
Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
1-
using System;
2-
using System.Runtime.InteropServices;
3-
4-
namespace WereDev.Utils.Wu10Man.Win32Wrappers
5-
{
6-
public static class ServiceWrapper
7-
{
1+
using System;
2+
using System.Runtime.InteropServices;
3+
4+
namespace WereDev.Utils.Win32Wrappers
5+
{
6+
public static class WindowsServiceBridge
7+
{
88
public const uint SC_MANAGER_ALL_ACCESS = 0x000F003F;
99
public const uint SC_MANAGER_QUERY_ACESS = 0x10000000;
1010
public const uint SERVICE_NO_CHANGE = 0xffffffff; //this value is found in winsvc.h
1111
public const uint SERVICE_QUERY_CONFIG = 0x00000001;
1212
public const uint SERVICE_CHANGE_CONFIG = 0x00000002;
13-
//public const uint SERVICE_QUERY_STATUS = 0x00000004;
14-
//public const uint SERVICE_ENUMERATE_DEPENDENTS = 0x00000008;
15-
//public const uint SERVICE_START = 0x00000010;
16-
//public const uint SERVICE_STOP = 0x00000020;
17-
//public const uint SERVICE_PAUSE_CONTINUE = 0x00000040;
18-
//public const uint SERVICE_INTERROGATE = 0x00000080;
19-
//public const uint SERVICE_USER_DEFINED_CONTROL = 0x00000100;
20-
//public const uint STANDARD_RIGHTS_REQUIRED = 0x000F0000;
21-
//public const uint SERVICE_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED |
22-
// SERVICE_CHANGE_CONFIG |
23-
// SERVICE_QUERY_STATUS |
24-
// SERVICE_ENUMERATE_DEPENDENTS |
25-
// SERVICE_START |
26-
// SERVICE_STOP |
27-
// SERVICE_PAUSE_CONTINUE |
28-
// SERVICE_INTERROGATE |
29-
// SERVICE_USER_DEFINED_CONTROL);
30-
13+
public const uint SERVICE_QUERY_STATUS = 0x00000004;
14+
public const uint SERVICE_ENUMERATE_DEPENDENTS = 0x00000008;
15+
public const uint SERVICE_START = 0x00000010;
16+
public const uint SERVICE_STOP = 0x00000020;
17+
public const uint SERVICE_PAUSE_CONTINUE = 0x00000040;
18+
public const uint SERVICE_INTERROGATE = 0x00000080;
19+
public const uint SERVICE_USER_DEFINED_CONTROL = 0x00000100;
20+
public const uint STANDARD_RIGHTS_REQUIRED = 0x000F0000;
21+
public const uint SERVICE_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED |
22+
SERVICE_CHANGE_CONFIG |
23+
SERVICE_QUERY_STATUS |
24+
SERVICE_ENUMERATE_DEPENDENTS |
25+
SERVICE_START |
26+
SERVICE_STOP |
27+
SERVICE_PAUSE_CONTINUE |
28+
SERVICE_INTERROGATE |
29+
SERVICE_USER_DEFINED_CONTROL);
30+
3131
[DllImport("advapi32.dll", SetLastError = true, CharSet = CharSet.Auto)]
3232
[return: MarshalAs(UnmanagedType.Bool)]
3333
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);
@@ -46,6 +46,6 @@ public static extern IntPtr OpenSCManager(
4646
public static extern bool CloseServiceHandle(IntPtr hSCObject);
4747

4848
[DllImport("advapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
49-
public static extern Boolean QueryServiceConfig(IntPtr hService, IntPtr intPtrQueryConfig, UInt32 cbBufSize, out UInt32 pcbBytesNeeded);
50-
}
51-
}
49+
public static extern Boolean QueryServiceConfig(IntPtr hService, IntPtr intPtrQueryConfig, UInt32 cbBufSize, out UInt32 pcbBytesNeeded);
50+
}
51+
}
Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
1-
using Autofac;
2-
using System;
3-
using System.Collections.Generic;
4-
using System.Linq;
5-
using System.Text;
6-
using System.Threading.Tasks;
7-
8-
namespace WereDev.Utils.Wu10Man
9-
{
10-
public static class DependencyManager
11-
{
12-
public static IContainer Container { get; set; }
13-
14-
public static T Resolve<T>() => Container.Resolve<T>();
15-
}
16-
}
1+
using Autofac;
2+
3+
namespace WereDev.Utils.Wu10Man.Core
4+
{
5+
public static class DependencyManager
6+
{
7+
public static IContainer Container { get; set; }
8+
9+
public static T Resolve<T>() => Container.Resolve<T>();
10+
}
11+
}

0 commit comments

Comments
 (0)