Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to setup IIS with VB Script?

Posted on 2009-07-08
4
Medium Priority
?
499 Views
Last Modified: 2012-05-07
Basically what I do right now is I manually go to IIS

1. add UserAcct to sercurity in IIS
2. create web site name Test and set local path to C:\Inetpub\Test
3. set host name as test.website.com
4. create new virtual directory: op
5. set local path to C:\Inetpub\Test\MoreTest
6. Application name: op

How would I do automate all of that using VB script?

Thanks!
0
Comment
Question by:dy211
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 

Author Comment

by:dy211
ID: 24813725
can anyone help please?? I dont have the MicrosoftIISv2 namespace, are there other ways to do it?
0
 

Accepted Solution

by:
dy211 earned 0 total points
ID: 24817533
I was able to create the website successfully with mkw3site.vbs, and i was able to create the virtual directory under it with

set objIIS = GetObject("IIS://localhost/W3SVC/2/root")

with /1/ it was creating the vir dir at Default Website before but after switching to /2/ it works correctly by creating it under Test.

But the problem is, what if I run this script on another computer with many websites in IIS and Test is not the second 1?? why doesnt IIS://localhost/W3SVC/Test/root work?
	' create website with mkw3site.vbs
	dim objShell : set objShell = wscript.CreateObject("WScript.Shell")	
	strCmd = "cscript C:\""Documents and Settings""\user\Desktop\scripts\mkw3site.vbs -r C:\Inetpub\Test -t Test -h test.website.com -o 8080"	
	dim objExec : set objExec = objShell.Exec(strCmd)
	
	'strOutPut = objExec.StdOut.ReadAll
	strErr = objExec.StdErr.ReadAll
	'strECode = objExec.ExitCode
 
	' outputs
	if strErr = "" then
		wscript.echo vbtab & "Website ""Test"" created..."
	else
		wscript.echo vbtab & strErr	
	end if
 
	set objShell = Nothing	
 
	
	' create virtual directory
    	dim objIIS, objVirtualDir
    	dim objIIsIPSecurity
	dim packageName : packageName = "op"
	dim path : path = "C:\Inetpub\Test\MoreTest"
   
    	' remove virual directory if any
	'On Error Resume Next
    	set objIIS = GetObject("IIS://localhost/W3SVC/1/root")
    	objIIS.Delete "IIsWebVirtualDir", PackageName
    	Set oIIS = Nothing
   
    	' Set up configuration
    	set objIIS = GetObject("IIS://localhost/W3SVC/2/root")  
    	set objVirtualDir = objIIS.Create("IIsWebVirtualDir", packageName)
    	objVirtualDir.Path = path
    	objVirtualDir.AccessRead = True
    	objVirtualDir.AccessWrite = True
    	objVirtualDir.AccessExecute = True
    	objVirtualDir.AuthAnonymous = False
    	objVirtualDir.AuthBasic = False
    	objVirtualDir.AuthNTLM = True
    	objVirtualDir.ContentIndexed = True
    	objVirtualDir.EnableDirBrowsing = False
    	objVirtualDir.AppIsolated = False
    	objVirtualDir.AspBufferingOn = True
    	objVirtualDir.AspSessionTimeout = 1
 
 	if inStr(1, objVirtualDir.DefaultDoc, "Default.asp") = 0 then
 	       objVirtualDir.DefaultDoc = "Default.asp, " & objVirtualDir.DefaultDoc
 	end if
 
 	objVirtualDir.EnableDefaultDoc = True
	call objVirtualDir.AppCreate(True)
 
   	objVirtualDir.AppFriendlyName = packageName
    	call objVirtualDir.SetInfo
 
	set objVirtualDir = nothing
    	set objIIS = nothing

Open in new window

0
 

Author Comment

by:dy211
ID: 24817564
Also, to give permission to folders work with the code below, but how would I do the samething to the website Test I created? can I set it during creation? if not how can I set it afterwards?
	set objShell = wscript.CreateObject("WScript.Shell")
        objShell.Run "cmd /c echo y | cacls ""C:\Inetpub"" /E /P ""Network Service:R"" ""Internet Guest Account:R"" ""Launch IIS Process:R""", 7, True

Open in new window

0
 
LVL 37

Assisted Solution

by:meverest
meverest earned 400 total points
ID: 24894519
Hi,

the site-id ('1' and '2') defines which web site you are operating on.  You can see the site ID in the IIS manager application when you select the 'web sites' node and view the list of web sites in the right hand panel.  The number shown under "Identifier" is the same as the number that you use in the adsi path.

each time you create a new web site, assign a unique ID, and then you can manage that web site using the functions you are already using.

Cheers.
0

Featured Post

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question