Move inetpub folder to another drive

Ever Wanted to move your IIS root from C to another drive. let’s say D?


From security point of view.. or space limitation run this script after customising it to your needs as per the comments in it..


 


‘ —————————————————————————–
‘ RENAME THIS FILE TO MOVEIIS.VBS BEFORE USING!!!
‘ —————————————————————————–
‘ Modify IIS Metabase Properties for new data location
‘ Change the params and params2 value depending on which components are
‘ installed
‘ set params to 10 if NNTP and FTP are installed and running otherwise
‘ set params to 9 and comment out msftpsvc line if FTP is not installed
‘ set params2 to 4 if FTP and NNTP are installed and runnning otherwise
‘ set params2 to 1 and comment out cisvc, msftpsvc and nntpsvc line if the
‘ Indexing service, FTP service, and Network News Transport Service are
‘ not installed
‘ References to the Indexing service have been commented out, check comments
‘ on line 75 to change Indexing Service settings



‘Stop IIS services before continuing
 
Set WSHShell = Wscript.CreateObject(“Wscript.Shell”)
WSHShell.PopUp “Stopping all Internet Services…”
 
ret = WshShell.Run (“net stop iisadmin /y”, 1, TRUE)
 
If ret = 0 then
 WSHShell.PopUp “IISADMIN service was stopped successfully, continuing”
 ‘restart()
else
 WSHShell.PopUp “IISADMIN failed to stop successfully. The error code is ” & ret
 Wscript.Quit 1
end if
 
Dim params(6)
Dim x, ret
Dim params2(2)
 
Params(0) = “w3svc/1/root/path d:\inetpub\wwwroot”
Params(1) = “w3svc/1/root/scripts/path d:\inetpub\scripts “
Params(2) = “w3svc/1/root/iissamples/path d:\inetpub\iissamples”
Params(3) = “smtpsvc/1/BadMailDirectory d:\inetpub\mailroot\BadMail”
Params(4) = “smtpsvc/1/PickupDirectory d:\inetpub\mailroot\Pickup”
Params(5) = “smtpsvc/1/QueueDirectory d:\inetpub\mailroot\Queue”
Params(6) = “smtpsvc/1/DropDirectory d:\inetpub\mailroot\Drop”
‘Params(7) = “nntpsvc/1/NewsPickupDirectory d:\inetpub\nntpfile\pickup”
‘Params(8) = “nntpsvc/1/NewsFailedPickupDirectory d:\inetpub\nntpfile\failedpickup”
‘Params(9) = “nntpsvc/1/NewsDropDirectory d:\inetpub\nntpfile\drop”
‘Params(10) = “msftpsvc/1/root/path d:\inetpub\ftproot”


Set WshSysEnv = WshShell.Environment(“PROCESS”)
 
For Each x In Params
ret = WSHShell.Run (“cscript.exe ” & “c:\inetpub\adminscripts\adsutil.vbs SET ” & x, 1, TRUE)
Next
 
‘ Verify Settings were successfully applied
If ret = 0 then
 
 WSHShell.PopUp “The new metabase settings have been successfully updated. The new Web Data path is d:\inetpub”
else
 WSHShell.PopUp “The Configuration changes failed. The error code is ” & ret
 Wscript.Quit 1
end if
wscript.Sleep 5000
 
‘ Move Data to new location (D:\Inetpub) using xcopy.exe (this can be changed
‘ from xcopy to move so the data is actually moved from current locale)
 
ret = WSHShell.Run (“xcopy c:\inetpub D:\Inetpub\ /s /e /q /i /h /r /k /o /x” , 1, TRUE)
If ret = 0 then
 WSHShell.PopUp “The data has been successfully moved to D:\Inetpub”
else
 WSHShell.PopUp “The data move failed. The error code is ” & ret
 Wscript.Quit 1
end if
 
‘ INDEX SERVICE CONFIGURATION
‘ Remove comments from the next 29 lines to configure cisvc through this script

” Update Web Catalog to be for D:\Inetpub

”Stop Content Index Service

‘Set WSHShell = Wscript.CreateObject(“Wscript.Shell”)
‘ WSHShell.PopUp “Stopping Index Service…”

‘ret = WshShell.Run (“net stop cisvc”, 1, TRUE)
 
‘If ret = 0 then
‘ chgeCat()
‘else
‘ WSHShell.PopUp “Content Index service failed to stop successfully. The error code is ” & ret
‘ Wscript.Quit 1
‘end if

‘Function chgeCat()
‘Set WshShell = WScript.CreateObject(“WScript.Shell”)

”Delete Catalogs
‘WshShell.RegDelete “HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ContentIndex\Catalogs\Web\” 


‘ Delete Web Catalog.
‘WshShell.RegDelete “HKLM\SYSTEM\CurrentControlSet\Control\ContentIndex\Catalogs\System\” 


‘ Delete System Catalog.

”Modify existing Web catalog entry
‘WshShell.RegWrite “HKLM\SYSTEM\CurrentControlSet\Control\ContentIndex\Catalogs\Web\Location”, “D:\Inetpub”
‘WshShell.RegWrite “HKLM\SYSTEM\CurrentControlSet\Control\ContentIndex\Catalogs\Web\IsIndexingW3Svc”, 1, “REG_DWORD”

‘end function
 
‘Start Services (WWW, SMTP, CISVC, NNTP, MSFTPSVC)
 
Set WSHShell = Wscript.CreateObject(“Wscript.Shell”)
 WSHShell.PopUp “Attempting to restart stopped Services…”
 
Params2(0) = “w3svc”
Params2(1) = “smtpsvc”
‘Params2(2) = “cisvc”
‘Params2(3) = “nntpsvc”
‘Params2(4) = “msftpsvc”


For Each x In Params2
 ret = WshShell.Run (“net start ” & x, 1, TRUE)
 wscript.Sleep 5000
Next
 
If ret = 0 then
 WSHShell.PopUp “Services were started successfully, modifications complete”
else
 WSHShell.PopUp “One or more services fail to start successfully. The error code is ” & ret
 Wscript.Quit 1
end if
 

Regular expressions characters reference

This one is handy, extracted from the help file.. I didn’t find a completet list online so here’s one: 


Character Description :

\ Marks the next character as either a special character, a literal, a backreference, or an octal escape. For example, ‘n’ matches the character “n”. ‘\n’ matches a newline character. The sequence ‘\\’ matches “\” and “\(” matches “(“.
^ Matches the position at the beginning of the input string. If the RegExp object’s Multiline property is set, ^ also matches the position following ‘\n’ or ‘\r’.
$ Matches the position at the end of the input string. If the RegExp object’s Multiline property is set, $ also matches the position preceding ‘\n’ or ‘\r’.
* Matches the preceding subexpression zero or more times. For example, zo* matches “z” and “zoo”. * is equivalent to {0,}.
+ Matches the preceding subexpression one or more times. For example, ‘zo+’ matches “zo” and “zoo”, but not “z”. + is equivalent to {1,}.
? Matches the preceding subexpression zero or one time. For example, “do(es)?” matches the “do” in “do” or “does”. ? is equivalent to {0,1}
{n} n is a nonnegative integer. Matches exactly n times. For example, ‘o{2}’ does not match the ‘o’ in “Bob,” but matches the two o’s in “food”.
{n,} n is a nonnegative integer. Matches at least n times. For example, ‘o{2,}’ does not match the “o” in “Bob” and matches all the o’s in “foooood”. ‘o{1,}’ is equivalent to ‘o+’. ‘o{0,}’ is equivalent to ‘o*’.
{n,m} m and n are nonnegative integers, where n <= m. Matches at least n and at most m times. For example, “o{1,3}” matches the first three o’s in “fooooood”. ‘o{0,1}’ is equivalent to ‘o?’. Note that you cannot put a space between the comma and the numbers.
? When this character immediately follows any of the other quantifiers (*, +, ?, {n}, {n,}, {n,m}), the matching pattern is non-greedy. A non-greedy pattern matches as little of the searched string as possible, whereas the default greedy pattern matches as much of the searched string as possible. For example, in the string “oooo”, ‘o+?’ matches a single “o”, while ‘o+’ matches all ‘o’s.
. Matches any single character except “\n”. To match any character including the ‘\n’, use a pattern such as ‘[.\n]‘.
(pattern) Matches pattern and captures the match. The captured match can be retrieved from the resulting Matches collection, using the SubMatches collection in VBScript or the $0…$9 properties in JScript. To match parentheses characters ( ), use ‘\(‘ or ‘\)’.
(?:pattern) Matches pattern but does not capture the match, that is, it is a non-capturing match that is not stored for possible later use. This is useful for combining parts of a pattern with the “or” character (|). For example, ‘industr(?:y|ies) is a more economical expression than ‘industry|industries’.
(?=pattern) Positive lookahead matches the search string at any point where a string matching pattern begins. This is a non-capturing match, that is, the match is not captured for possible later use. For example ‘Windows (?=95|98|NT|2000)’ matches “Windows” in “Windows 2000″ but not “Windows” in “Windows 3.1″. Lookaheads do not consume characters, that is, after a match occurs, the search for the next match begins immediately following the last match, not after the characters that comprised the lookahead.
(?!pattern) Negative lookahead matches the search string at any point where a string not matching pattern begins. This is a non-capturing match, that is, the match is not captured for possible later use. For example ‘Windows (?!95|98|NT|2000)’ matches “Windows” in “Windows 3.1″ but does not match “Windows” in “Windows 2000″. Lookaheads do not consume characters, that is, after a match occurs, the search for the next match begins immediately following the last match, not after the characters that comprised the lookahead.
x|y Matches either x or y. For example, ‘z|food’ matches “z” or “food”. ‘(z|f)ood’ matches “zood” or “food”. 
[xyz] A character set. Matches any one of the enclosed characters. For example, ‘[abc]‘ matches the ‘a’ in “plain”. 
[^xyz] A negative character set. Matches any character not enclosed. For example, ‘[^abc]‘ matches the ‘p’ in “plain”. 
[a-z] A range of characters. Matches any character in the specified range. For example, ‘[a-z]‘ matches any lowercase alphabetic character in the range ‘a’ through ‘z’. 
[^a-z] A negative range characters. Matches any character not in the specified range. For example, ‘[^a-z]‘ matches any character not in the range ‘a’ through ‘z’. 
\b Matches a word boundary, that is, the position between a word and a space. For example, ‘er\b’ matches the ‘er’ in “never” but not the ‘er’ in “verb”. 
\B Matches a nonword boundary. ‘er\B’ matches the ‘er’ in “verb” but not the ‘er’ in “never”. 
\cx Matches the control character indicated by x. For example, \cM matches a Control-M or carriage return character. The value of x must be in the range of A-Z or a-z. If not, c is assumed to be a literal ‘c’ character. 
\d Matches a digit character. Equivalent to [0-9]. 
\D Matches a nondigit character. Equivalent to [^0-9]. 
\f Matches a form-feed character. Equivalent to \x0c and \cL.
\n Matches a newline character. Equivalent to \x0a and \cJ.
\r Matches a carriage return character. Equivalent to \x0d and \cM.
\s Matches any whitespace character including space, tab, form-feed, etc. Equivalent to [ \f\n\r\t\v].
\S Matches any non-white space character. Equivalent to [^ \f\n\r\t\v]. 
\t Matches a tab character. Equivalent to \x09 and \cI.
\v Matches a vertical tab character. Equivalent to \x0b and \cK.
\w Matches any word character including underscore. Equivalent to ‘[A-Za-z0-9_]‘. 
\W Matches any nonword character. Equivalent to ‘[^A-Za-z0-9_]‘. 
\xn Matches n, where n is a hexadecimal escape value. Hexadecimal escape values must be exactly two digits long. For example, ‘\x41′ matches “A”. ‘\x041′ is equivalent to ‘\x04′ & “1”. Allows ASCII codes to be used in regular expressions.
\num Matches num, where num is a positive integer. A reference back to captured matches. For example, ‘(.)\1′ matches two consecutive identical characters. 
\n Identifies either an octal escape value or a backreference. If \n is preceded by at least n captured subexpressions, n is a backreference. Otherwise, n is an octal escape value if n is an octal digit (0-7).
\nm Identifies either an octal escape value or a backreference. If \nm is preceded by at least nm captured subexpressions, nm is a backreference. If \nm is preceded by at least n captures, n is a backreference followed by literal m. If neither of the preceding conditions exists, \nm matches octal escape value nm when n and m are octal digits (0-7).
\nml Matches octal escape value nml when n is an octal digit (0-3) and m and l are octal digits (0-7).
\un Matches n, where n is a Unicode character expressed as four hexadecimal digits. For example, \u00A9 matches the copyright symbol (©).


More info:


http://sitescooper.org/tao_regexps.html


http://www.regular-expressions.info/reference.html


Some Regular expressions tools:


Expresso,Regex Tester, Rad Software Regular Expression Designer, Regex, RegexDesigner.NET, Regex Snippets, Regular Expression Workbench, The Regulator.

Supress caching in ASP3.0

Caching is hard to manipulate, (is it o bug or not at the end and due to several factors I won’t discuss now) you need to add several lines on the client and server side (although this won’t eleminate the problem 100% but will minimise it a lot)
<%..
Response.expires= 0
Response.Expires=-1
Response.Expiresabsolute = Now() – 1
Response.AddHeader “cache-control”,”private”
Response.CacheControl = “no-cache”
%>
<meta http-equiv=”PRAGMA” value=”NO-CACHE”>
<meta http-equiv=”Expires” content=”Mon, 01 Jan 1990 12:00:00 GMT”>



one of the best ways to suppress cache is to redirect to another page with  a querystring at the end
of the url like:


response.redirect “mynocachepage.asp?” & Server.URLEncode(rnd)


For more information see:


   http://www.activeserverpages.com/learn/cachenomore.asp

Add a legacy Component in COM+/MTS

If you have a legacy component (Com+ component) this is the way how to add it:


Start the Component services..in the tree select computers.. mycomputer..com+ applications…right click on it–> new -> application.. now in the wizard click next and select an empty application -> name your package,  leave it in server process and click next -> Select the user and enter an account with enough rights to fufill your com jobs (admin account has full privilieges and should be used for testing purpose) -> Finish..


now in the tree expand the new package untill you see the component directory-> right click it -> select new component-> in the wizard click next.. you can either install a new component if it’s not registred or install a registred one if you already registred your dll using regsvr32 from the command prompt(you select the 2nd choice) -> Select your component from the list (internal name displayed) -> Finish..


and voila..



In MTS (IIS4)


Start MMC (Microsoft management console.. from IIS or MTS) -> Select in the tree Microsoft Transaction.. -> My computer ->right click packages installed -> new package -> click on create an empty package and name the package, next -> select this user and give an admin user for the package -> finish  , now we’ll need to include your registered component in the package(dll).. Expand the newly created package in the tree and right click on components folder-> new component -> select import components that are already registered -> you’ll get a list of registered components on that machine.. select your component to include by it’s class name -> Finish  note that your activex dll should be set to run unattended while compiling..



 

Coding rules in classic ASP

I like to post this especially for newbies in old fashioned ASP..


 


Summary of rules in ASP3.0 Developement:
————————————-
-Avoid excessive use of Inline ASP.
-Always concatenate consecutive Response.Write statements into a single statement.
-Never use wrapper functions around the Response.Write statement to append CRLFs.
-If you must format your HTML output, append CRLFs directly within the Response.Write statements.
-Always enable buffering through server settings.
-When used in moderation, ASP comments have little or no impact on performance, so comment more!
-Set the server’s default language configuration to match the language used on the site.
-Do not set the language declarative unless you are using the non-default language.
-Always Use Option Explicit in VBSCript, strict coding will save you a lot of hassle later.
-Always disable Session state at the page or application level when not required.
-Use Include files only when code can be shared across pages.
-Encapsulate code into function blocks when the code will be used more than once in a page.
-Move variables into function scope when appropriate.
-Only use error handling when a condition can occur that is out of your ability to test or control.
-Only use transactions when two or more operations MUST be performed as a unit.


In review, there are several issues that you can use as general guidelines:


-Avoid redundancy – don’t set properties that are already set by default.
-Limit the number of function calls.
-Narrow the scope of your code.

Tools for Troubleshooting IIS 6.0

Good tools are an indispensable part of any troubleshooting effort. This section identifies tools that you can use to help troubleshoot problems that you encounter on applications running on IIS 6.0. It also provides tips for getting the most benefit from each tool. Specific tool usage scenarios are also discussed in this section.


The following tools are useful for troubleshooting problems that occur with IIS 6.0:


WFetch (WFetch.exe). This tool allows you to generate customized HTTP requests and view request and response data.
 
File Monitor (FileMon.exe). This tool allows you to view and capture real-time file system activity.
 
Registry Monitor (RegMon.exe). This tool allows you to view and capture real-time system registry activity.
 
IIS Request Monitor. This tool captures information about HTTP requests in IIS worker processes, which can help you isolate and understand problems when worker processes become slow or unresponsive.
 
Secure Socket Layer (SSL) Diagnostic Tool (SSLDiag). This tool helps you identify configuration problems in the IIS metabase, certificates, or certificate stores when running Web sites that use SSL.
 
Authentication and Access Control Diagnostics (authdiag.exe). This tool allows you to review, test, and correct problems with authentication and authorization. (Bernard has something to say about it: http://msmvps.com/blogs/bernard/archive/2004/09/02/12722.aspx)
 
• IIS 6.0 Enterprise Tracing for Windows. This tool allows you to trace HTTP requests as they move through various components in your server architecture. IIS components provide informational events and error events (if applicable) to the ETW architecture as requests enter and exit each component. You can view the event data to see exactly where in the IIS architecture a request failed or became unresponsive.
 
• Network Monitor. This network tracing utility allows you to view activity in the network stack. Network Monitor is included with Windows Server 2003.
 
• System Monitor. This tool allows you to view and collect system performance data. System Monitor is included with Windows Server 2003.
 
Alexei Kvasov’s HRPlus tool. This tool provides error lookup functionality.
 
Microsoft Debugging Tools for Windows. This tool allows you to debug and diagnose application problems.
 


More info:


http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/dd07e7b2-d946-4a21-8805-8b60c62b479e.mspx


Download IIS6 resource toolkit here


http://www.microsoft.com/downloads/details.aspx?FamilyId=56FC92EE-A71A-4C73-B628-ADE629C89499&displaylang=en



To troubleshoot IIS5
http://www.jsiinc.com/SUBL/tip5600/rh5652.htm