Perl或VBscript:Wow64DisableWow64FsRedirection

时间:2012-06-06 18:54:29

标签: perl vbscript

如何制作两个简单的脚本来执行此操作:

Wow64DisableWow64FsRedirection

我想禁用文件夹重定向,安装程序,然后重新激活它。

2 个答案:

答案 0 :(得分:3)

如果它没有意义,因为它只影响调用该函数的线程,可以使用Inline::CWin32::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;

答案 1 :(得分:0)

从脚本执行此操作毫无意义,因为它只会影响调用该函数的线程。它在脚本之外没有任何影响。