@@ -49,11 +49,10 @@ If ($env:PROCESSOR_ARCHITEW6432 -match '64' -and [IntPtr]::Size -ne 8) {
49
49
$MethodSignature = @"
50
50
[DllImport("kernel32.dll", SetLastError=true)]
51
51
public static extern bool Wow64DisableWow64FsRedirection(ref IntPtr ptr);
52
- public static extern bool Wow64RevertWow64FsRedirection(IntPtr ptr);
53
52
"@
54
- $Kernel32 = Add-Type - MemberDefinition $MethodSignature - Namespace " Kernel32" - Passthru
55
- $ptr = [ IntPtr ]::Zero
56
- $Result = $Kernel32 ::Wow64DisableWow64FsRedirection([ ref ] $ptr )
53
+ $Kernel32 = Add-Type - MemberDefinition $MethodSignature - Namespace " Kernel32" - Passthru - Name DisableWow64Redirection
54
+ [ ref ] $ptr = New-Object System. IntPtr
55
+ $Result = $Kernel32 ::Wow64DisableWow64FsRedirection($ptr )
57
56
# Now you can call 64-bit Powershell from system32
58
57
$pshell = " ${env: windir} \System32\WindowsPowershell\v1.0\powershell.exe"
59
58
}
@@ -65,7 +64,13 @@ public static extern bool Wow64RevertWow64FsRedirection(IntPtr ptr);
65
64
& " $pshell " - NonInteractive - NoProfile $myInvocation.MyCommand
66
65
}
67
66
If ($RevertFSRedirection -eq $True ) {
68
- $Result = $Kernel32 ::Wow64RevertWow64FsRedirection($ptr )
67
+ $MethodSignature = @"
68
+ [DllImport("kernel32.dll", SetLastError=true)]
69
+ public static extern bool Wow64RevertWow64FsRedirection(ref IntPtr ptr);
70
+ "@
71
+ $Kernel32Default = Add-Type - MemberDefinition $MethodSignature - Namespace " Kernel32" - Passthru - Name Wow64RevertWow64FsRedirection
72
+ [ref ]$defaultptr = New-Object System.IntPtr
73
+ $Result = $Kernel32Default ::Wow64RevertWow64FsRedirection($defaultptr )
69
74
}
70
75
Write-Warning ' Exiting 64-bit session. Module will only remain loaded in native 64-bit PowerShell environment.'
71
76
Exit $lastexitcode
0 commit comments