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"; }

In reply to Create WebSites on IIS Server by redleg7

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.