11
11
Tested Versions: v10.5, v11, v12
12
12
13
13
. NOTES
14
- Version: 1.5
14
+ Version: 1.6
15
15
Author: Chris Taylor
16
16
Website: labtechconsulting.com
17
17
Creation Date: 3/14/2016
32
32
Update Date: 8/28/2018
33
33
Purpose/Change: Added Update-LTService function
34
34
35
+ Update Date: 2/26/2019
36
+ Purpose/Change: Update to support 32-bit execution in 64-bit without SYSNATIVE redirection
35
37
#>
36
38
37
39
if (-not ($PSVersionTable )) {Write-Warning ' PS1 Detected. PowerShell Version 2.0 or higher is required.' ;return }
@@ -43,35 +45,31 @@ $ModuleVersion = "1.5"
43
45
If ($env: PROCESSOR_ARCHITEW6432 -match ' 64' -and [IntPtr ]::Size -ne 8 ) {
44
46
Write-Warning ' 32-bit PowerShell session detected on 64-bit OS. Attempting to launch 64-Bit session to process commands.'
45
47
$pshell = " ${env: WINDIR} \sysnative\windowspowershell\v1.0\powershell.exe"
46
- Write-Debug " Launch Context: $ ( $myInvocation | out-String ) "
47
48
If (! (Test-Path - Path $pshell )) {
48
- Write-Warning ' SYSNATIVE REDIRECTION IS NOT AVAILABLE. Attempting to access 64bit binaries directly.'
49
+ Write-Warning ' SYSNATIVE PATH REDIRECTION IS NOT AVAILABLE. Attempting to access 64-bit PowerShell directly.'
49
50
$pshell = " ${env: WINDIR} \System32\WindowsPowershell\v1.0\powershell.exe"
50
51
$FSRedirection = $True
51
- $MethodSignature = @"
52
+ Add-Type - Debug: $False - Name Wow64 - Namespace " Kernel32 " - MemberDefinition @"
52
53
[DllImport("kernel32.dll", SetLastError=true)]
53
54
public static extern bool Wow64DisableWow64FsRedirection(ref IntPtr ptr);
55
+
56
+ [DllImport("kernel32.dll", SetLastError=true)]
57
+ public static extern bool Wow64RevertWow64FsRedirection(ref IntPtr ptr);
54
58
"@
55
- $Kernel32 = Add-Type - MemberDefinition $MethodSignature - Namespace " Kernel32" - Passthru - Name DisableWow64Redirection
56
59
[ref ]$ptr = New-Object System.IntPtr
57
- # $Result = $ Kernel32::Wow64DisableWow64FsRedirection($ptr) # Now you can call 64-bit Powershell from system32
60
+ $Result = [ Kernel32.Wow64 ] ::Wow64DisableWow64FsRedirection($ptr ) # Now you can call 64-bit Powershell from system32
58
61
}
59
62
If ($myInvocation.Line ) {
60
- Write-Output ' &"$pshell" -NonInteractive -NoProfile $myInvocation.Line'
63
+ & " $pshell " - NonInteractive - NoProfile $myInvocation.Line
61
64
} Elseif ($myInvocation.InvocationName ) {
62
- Write-Output ' &"$pshell" -NonInteractive -NoProfile -File "$($myInvocation.InvocationName)" $args'
65
+ & " $pshell " - NonInteractive - NoProfile - File " $ ( $myInvocation.InvocationName ) " $args
63
66
} Else {
64
- Write-Output ' &"$pshell" -NonInteractive -NoProfile $myInvocation.MyCommand'
67
+ & " $pshell " - NonInteractive - NoProfile $myInvocation.MyCommand
65
68
}
66
69
$ExitResult = $LASTEXITCODE
67
70
If ($FSRedirection -eq $True ) {
68
- $MethodSignature = @"
69
- [DllImport("kernel32.dll", SetLastError=true)]
70
- public static extern bool Wow64RevertWow64FsRedirection(ref IntPtr ptr);
71
- "@
72
- $Kernel32Default = Add-Type - MemberDefinition $MethodSignature - Namespace " Kernel32" - Passthru - Name RevertWow64Redirection
73
71
[ref ]$defaultptr = New-Object System.IntPtr
74
- # $Result = $Kernel32Default ::Wow64RevertWow64FsRedirection($defaultptr)
72
+ $Result = [ Kernel32.Wow64 ] ::Wow64RevertWow64FsRedirection($defaultptr )
75
73
}
76
74
Write-Warning ' Exiting 64-bit session. Module will only remain loaded in native 64-bit PowerShell environment.'
77
75
Exit $ExitResult
0 commit comments