我如何制作两个简单的脚本来做到这一点:
我想禁用文件夹重定向,安装一个程序,然后重新激活它。
如果它不是毫无意义的,因为它只影响调用该函数的线程,那么可以使用Inline::C、Win32::API或 XS 模块。
script.pl
:
use Win32API::Wow64FsRedirection qw( :ALL );
my $saved = Wow64Disable()
or die("Wow64Disable: $^E\n");
# ...
Wow64Revert($saved)
or die("Wow64Revert: $^E\n");
Win32API/Wow64FsRedirection.pm
:
package Win32API::Wow64FsRedirection;
use strict;
use warnings;
use feature qw( state );
use Exporter qw( import );
use Win32::API qw( );
our @EXPORT_OK = qw( Wow64Disable Wow64Revert );
our %EXPORT_TAGS = ( ALL => \@EXPORT_OK );
# On success, returns value to pass to Wow64Revert. This value will be true.
# On error, returns false and sets $^E.
sub Wow64Disable {
state $Wow64DisableWow64FsRedirection = Win32::API->new(
'kernel32', 'Wow64DisableWow64FsRedirection', 'P', 'L',
);
my $OldValue_buf = pack('L', 0);
$Wow64DisableWow64FsRedirection->Call($OldValue_buf)
or return undef;
return unpack('L', $OldValue_buf) || "0 but true";
}
# On success, returns true.
# On error, returns false and sets $^E.
sub Wow64Revert {
my ($OldValue) = @_;
state $Wow64RevertWow64FsRedirection = Win32::API->new(
'kernel32', 'Wow64RevertWow64FsRedirection', 'N', 'L',
);
return $Wow64RevertWow64FsRedirection->Call($OldValue);
}
1;
从脚本中执行此操作毫无意义,因为它只会影响调用该函数的线程。它在脚本之外没有任何影响。