redleg7 has asked for the wisdom of the Perl Monks concerning the following question:
I am attempting to use Perl's Win32::OLE module to create virtual directories and ftp sites on an IIS server remotely (I have been able to accomplish this running the code locally). In essence, each user will have their own website. However, when I run the code below, I receive an error that the syntax is not correct (I believe that it has something to do with how I am passing the server name) and that no OLE object could be obtained. Can someone tell me what I am doing wrong or if this is even possible.
use strict; use warnings; use Win32::OLE; $Win32::OLE::Warn = 3; # ------ SCRIPT CONFIGURATION ------ my $IISSERVER = 'Mosiac'; my $logonName = 'jsmith'; #my $baseVdirPath = "d:\\userdirs\\Students\\$logonName\\WWW"; my $baseVdirPath = "d:\\userdirs\\Students\\"; # ------ END CONFIGURATION --------- my @users = ($logonName); createVirDir($IISSERVER, $baseVdirPath, \@users); ###################################################################### +################################# sub createVirDir { my ($IISSERVER, $baseVdirPath, $users) = @_; # $baseVdirPath = "d:\\userdirs\\Students\\"; my $objVdir; for(my $index=0; $index<@$users; $index++) { my $userVdirPath = $baseVdirPath . $$users[$index] . "\\WWW"; # Does the vdir already exist?? if(Win32::OLE->GetObject("IIS://" . $IISSERVER . '/W3svc/1/Roo +t/' . $logonName . '/www')) # Win32::OLE->GetObject("IIS://" . "\\\\$IISSERVER" . '/W3svc/ +1/Root/' . $logonName . '/www' { print "$logonName www directory already exists.\n "; return; } eval { my $objIIS = Win32::OLE->GetObject('IIS://' . $IISSERVER . + '/W3SVC/1'); # || Win32::OLE->GetObject('IIS://' . "\\\\$IISSERVER" +. '/W3SVC/1'); my $objWebSite = $objIIS->GetObject("IISWebVirtualDir","R +oot"); my $objVdir = $objWebSite->Create('IISWebVirtualDir', $log +onName); $objVdir->{AccessRead} = 1; $objVdir->{Path} = $userVdirPath; $objVdir->AppCreate(1); $objVdir->{AppIsolated} = 2; $objVdir->{AppFriendlyName} = $logonName; $objVdir->SetInfo(); $objVdir->Close(); }; if($@) { print 'Unable to create virtual directory: ' . $objVdir->N +ame, "\n"; Error("IIsWebVirtualDir"); return 0; } else { return 1; } } } sub Error { my ($Object) = @_; print "unable to create a '$Object' object.\n"; print "Error: " . Win32::OLE->LastError() . "\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Create WebSites on IIS Server
by shmem (Chancellor) on Nov 16, 2010 at 18:08 UTC |