Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (3)
As of 2024-04-19 22:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found