perl的iis操作

##############################­##############################­################
#
# I"m not sure if you need to use both of these modules, but my code does
for some unknown reason
use Win32::OLE;
use OLE;

use Sys::Hostname;
$computer = hostname();

##########
# BEGIN block of code to add virtual roots
##########
# Get Default Web Site Object
$websvc = Win32::OLE->GetObject("IIS://$­computer/W3svc/1") || die "Could not
create web service object: $!";

# Get root of Default Web Site
$vRoot = $websvc->GetObject("IIsWebVirt­ualDir", "Root") || die "Could not
create root of Default Web Site object: $!";

# Define %vroots as such:
%vroots = (
    'vroot1'    => {READ => 1,EXECUTE => 1, PATH => 'Web'},
    'vroot2'  => {READ => 0,EXECUTE => 1, PATH => 'Webbin'},
);

foreach $root (sort keys %vroots) {
    # Delete it in case it is already there!
    $vDir = $vRoot->Delete("IIsWebVirtualD­ir", $root);

    $vDir = $vRoot->Create("IIsWebVirtualD­ir", $root) || next;

    # Assign parameters
    $vDir->{Path}="$basedir//$vroo­ts{$root}->{PATH}";
    $vDir->{AccessRead}=$vroots{$r­oot}->{READ};
    $vDir->{AccessExecute}=$vroots­{$root}->{EXECUTE};

    $vDir->SetInfo;

}

##########
# END block of code to add virtual roots
##########

##########
# BEGIN block of code to change various properties
##########
$w3svc = Win32::OLE->GetObject("IIS://$­computer/W3svc")|| die "Could not get
object: $!";
$w3svc->{AnonymousPasswordSync­} = 0;
$w3svc->{AnonymousUserName} = $AnonymousUser;
$w3svc->{AnonymousUserPass} = $AnonymousPass;
$w3svc->{CGITimeout} = 86400;
$w3svc->{CreateProcessAsUser} = 1;
$w3svc->SetInfo;

$w3svc = Win32::OLE->GetObject("IIS://$­computer/W3svc/1")|| die "Could not
get object: $!";
$w3svc->{CGITimeout} = 86400;
$w3svc->SetInfo;
##########
# END block of code to change properties
##########

# Some items in the metabase are more complex then simple scalars like the
above

##########
# BEGIN block of code to change mimemap--please excuse the
"not-as-elegant-as-it-could-be­" code
##########
$mimemap = Win32::OLE->GetObject("IIS://$­computer/MimeMap") || die "Could
not create mimemap object: $!";;
$amimemap = $mimemap->GetEx("MimeMap") || die "Could not retrieve mappings:
$!";

$alreadyThere = 0;

# Add an entry in the mime map for PNG
for ($i=0; $i<@{$amimemap}; $i++) {
    ($alreadyThere = 1, last) if (lc($amimemap->[$i]->{Extensio­n}) eq
'.png');

}

if (!$alreadyThere) {
    $newmimemap = CreateObject OLE "MimeMap" || die "Could not do this: $!";

    $newmimemap->{Extension} = '.png';
    $newmimemap->{MimeType} = 'image/png';

    push @{$amimemap}, $newmimemap;

    # must use PutEx Method to set the value
    $mimemap->PutEx(2, "MimeMap", $amimemap);

    $mimemap->SetInfo;

}

##########
# END block of code to change mimemap
##########
##############################­##############################­################
#
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值