Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Create WebSites on IIS Server

by redleg7 (Initiate)
on Nov 16, 2010 at 13:11 UTC ( #871714=perlquestion: print w/ replies, xml ) Need Help??
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"; }

Comment on Create WebSites on IIS Server
Download Code
Re: Create WebSites on IIS Server
by shmem (Canon) on Nov 16, 2010 at 18:08 UTC
    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.

    I don't have any expertise in neither Win32::OLE nor IIS, but it could be helpful if you did post the actual error. That way anybody willing to help you might have a starting point. Why should anybody run that snippet of code just to get the error you didn't post?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://871714]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2014-04-20 09:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (485 votes), past polls