How to find relative path to C:\Inetpub\AdminScripts\ADSUTIL.VBS? - iis

IIS 6 and older ships with a utility script called ADSUTIL.VBS:
Adsutil.vbs is an IIS administration
utility that uses Microsoft Visual
Basic Scripting Edition (VBScript)
with Active Directory Service
Interfaces (ADSI) to manipulate the
IIS configuration. This script should
be run using CScript, which is
installed with Windows Script Host.
In other words, this tool lets you change IIS metabase settings programmatically, from the command line.
I would like to call this tool from an InstallShield project in order to make some configuration changes to IIS. I am curious if it either legal to re-distribute the script (there is no legal wording inside the source for it) or to simply launch the command via:
CSCRIPT %SYSTEMDRIVE%\Inetpub\AdminScripts\adsutil.vbs
and hope that the script exists on disk in that location.
So my question is - will it always exist in that path above, even if some other websites (inetpub roots) on the machine are located on a non-system drive? It seems all MSDN and other Microsoft KB articles that refer to the ADSUTIL tool do so by using the %SYSTEMDRIVE% path above.
I see that at least one other attempt to deal with this by distributing both cscript.exe and adsutil.vbs with their InstallShield projects.
Perhaps there is a registry key or other method to obtain the location of the Inetpub\AdminScripts path?
Maybe I should just write a C# application that changes the value or my own VBScript and distribute with my own little app instead?

I ran into a similar issue recently and decided to just rework a small bit of vbscript to use in a custom action in an msi installer. It can take a bit to figure out the core of how adsutil.vbs does things, but it is deently well writen. For example, i needed to switch an application pool to Classic instead of Integrated mode and explicitly set it to run in 32-bit mode when on 64-bit windows, in distilled form this resulted in this:
Option Explicit
Dim IIsObject
Set IIsObject = GetObject("IIS://LocalHost/W3SVC/AppPools/TestPool")
IIsObject.Put "ManagedPipelineMode", 1
IIsObject.Setinfo
IIsObject.Put "Enable32BitAppOnWin64", CBool("True")
IIsObject.Setinfo

I worked in JShumaker's answer to solve the problem. The best route seems to be the following InstallScript function that I call to run a batch script:
prototype SetIISValues();
function SetIISValues()
string szProgram, szCmd;
begin
szProgram = TARGETDIR + "SetIISValues.bat";
szCmd = "";
LaunchAppAndWait (szProgram, szCmd, LAAW_OPTION_WAIT);
end;
The batch script calls this:
#echo off
cscript.exe SetIISValues.vbs
And the VBScript looks like this:
Option Explicit
Dim IIsObject
Set IIsObject = GetObject("IIS://localhost/w3svc/1")
IIsObject.Put "Name", "Value"
IIsObject.Setinfo
Doing it this way relieves the need to use ADSUTIL.VBS as part of the installation - the (relative) path to it is irrelevant if you don't need to use it.

Related

How to setup IIS Express from a script the way Visual Studio does it?

When we configure a web application to run in IIS Express there are certain things VS does, like:
Creating the application host configuration file in the IISExpress subfolder of the user documents folder.
Creating a dedicated site section for each web application in the solution, including ours.
Maybe more things are done, which I am unaware of.
I would like to replicate the same process from a script, so that running the web application from the script would be equivalent to running it from VS. Including for the very first time.
Right now I start IISExpress with the /port and /path flags, because this is how I used to run Cassini. However, Cassini supported an additional flag - /vpath. They removed it from IISExpress, meaning I have to use another set of flags - /config, /site, /siteid. But I suspect it must be done in conjunction with the Appcmd.exe utility.
This second approach is still something I haven't managed to master. So, my question is this - suppose I am given the port, path and vpath of a web application (i.e. no need to read them from the web application's csproj file, like VS does). What command sets up the right application host configuration file and how do I run IISExpress to take advantage of it?

Wix Webapplication: How do I add an extension without replacing all existing mappings?

I'm trying to add a .plan extension to our IIS 6.0 website through WiX. I'm using
<iis:WebApplicationExtension CheckPath="no" Script="yes" Executable="[FRAMEWORKROOT]v4.0.30319\aspnet_isapi.dll" Verbs="GET,HEAD,POST,DEBUG" Extension="plan"/>
Although this is replacing all of the existing application extensions, which is not the behaviour that we want. Is there a way to simply add .plan? We would like to avoid using the Wildcard if possible as we're not sure how it will affect the rest of the site. I don't think that APPCMD is available on our 2003 server either.
Any suggestions would be greatly appreciated :)
Unfortunately we didn't find a way to do this cleanly using the iis:WebApplicationExtension in WiX.
We found this post http://blogs.msdn.com/b/david.wang/archive/2004/12/02/273681.aspx that provides a VBScript for adding ScriptMaps. We edited the script to only execute the HandleListOps function (with the relevant params) so that we didn't get any issues with WScript. We then call this from a CustomAction in WiX, with the vbs file added as a Binary file.
We're aware that running vbscript custom actions from within an installer isn't ideal, but luckily we're not distributing the application externally and is only going to be used on an internal website, so the target server environment is reasonably well known.

Run a vbscript under an IIS application

I have a vbs file that runs fine and I want to run it under an IIS7 application name. Can this be done? If so, how?
thanks
You could look under "Handler Mappings" in IIS and add one similar to ASP which is how I used to run VBScript on the server side years ago. This does imply that the file is on a web server and you are OK with HTML output of the result.
Just for fun, I was wondering how to do this. I found an article on the Microsoft support site which told me this was possible at one time. As of IIS 7.5 this is even easier than the article suggests. You simply need to create the mapping in IIS:
Steps
Go to the IIS configuration and select the site you'd like to use
VBS files with.
Go to the Handler Mappings configuration for that site.
Click Add Script Map... on the right hand side.
Set the Request Path to *.vbs
Set the Executable to "C:\Windows\System32\cscript.exe" //NOLOGO %s %s
Set the Name to something you'll remember if you need to.
Restart IIS (possibly optional but I did this)
Then, test it with a script such as the following:
WScript.Echo "Content-Type: text/html"
WScript.Echo
WScript.Echo "If you see this, it worked."
Save it as test.vbs in your site and go to the URL to see the results. Every script used this way must begin output with the first two lines of this script or IIS will not use it.
Note: I also have the CGI (from the Windows installation disk) and Fast-CGI (from the Windows download center) modules installed. I'm not sure whether either of these are actually needed though.

Hklm/Init on Windows CE 6.0

I've been trying to make my application run at startup on windows CE 6.0, unfortunately since the device (YFAtlas4) is customized by manufacturer I'm unable to place shortcut in \Windows\Startup. (for some misterious reasons)
So now I'm trying to place path to my application in Hklm\Init registry key, and here's my problem: I's there a way to place absolute path there ? In every example that I've seen there's only application name, and my application has to be instaled in \ResidentFlash\ folder.
Did you try to put the full path there?
There should not be any problem doing so.
If you edit your registry using code, then the string you want to store is L"\\ResidentFlash\\AppName.exe". Alternatively, in case you have an ActiveSync connection with the device you can use a remote registry editor and not mess with the double backslashes.
Also, since you are using the HKLM\Init functionality - make sure your application calls SignalStarted so other programs that are dependent on it can start as well.
A fully qualified path should be supported jusy fine. Be aware that if the path has a space in it, you'll need to quote delimit it. Also, if it's a Compact Framework app, it's not as simple as just adding your app to the Init key - often that will fail. See this blog entry on getting CF apps working with the Init key.

IIS 7 'Server.CreateObject failed'

I've installed IIS7 on my workstation and enabled IIS6 compatibility so I can test classic asp pages (for some old projects here at work).
Some pages work, but others don't.
I receive:
Serverobject error 'ASP 0177 : 800401f3'
Server.CreateObject failed
/master.central.be/master_connection.asp, line 55
800401f3
On that line i've got:
Set dicTalenLabels = Server.CreateObject("Scripting.Dictionary")
Anybody got some ideas what todo to fix this?
Edit:
As suggested by Michael Pryor, i've ran a vbscript with similar code and it was succesful. So it probably has something todo with permissions. Currently trying to figure out which files exactly...
Do I need to add IUSR to scrrun.dll? When trying, I do not have permission, although i'm a adminstrator.
Edited: He's running 32 bit vista, so it's definitely not a 64 bit issues.
Make a test.vbs file and put this in it
Dim o: Set o = CreateObject("Scripting.Dictionary")
Then run it like so
cscript.exe test.vbs
Does it give you the same error?
If it does, then the regsvr32 is failing or something is wrong with the registry keys it would normally put in the registry.
If it doesn't fail, it's likely that the user you have running your asp page (by default it is IUSR_machinename) doesn't have permissions on either ther registry keys it needs, or the actual .dll
0x800401f3 means that the "Scripting.Dictionary" is incorrect or not found. The Scripting.FileSystemObject is provided by the same dll file, and I know that some hosts have disabled this by unregistering the dll file, which would also disable the Dictionary object. Could you check if the Scripting.FileSystemObject works?
Both objects are provided by Windows\System32\scrrun.dll (or Windows\SysWOW64\scrrun.dll if you're executing 32bit on 64bit host). Check the permissions on this file, and verify what privileges your asp script executes as.
Take a look at:
Tips for Classic ASP developers on IIS7
More Tips and Troubleshooting Help for Classic ASP Developers
Both the links are from Bill Staples' blog, he's one of the head honchos on the IIS side of things and the tips in the first link sorted me out when I was trying to get Classic ASP up and running.
I've found that calls to system objects such as
set rs = server.createobject("adodb.recordset")
and
set fs = server.createobject("scripting.filesystemobject");
sometimes fail after running fine for weeks on a production server. It's not a great solution, but manually recycling the app pool fixes it. Also, setting the app pool to recycle every few hours is a way to keep it fresh. Just make sure that you don't accidentally log everyone off (if using session for credentials).
It could be that the developer forgot to 'close' and 'set to nothing' the objects. Any objects you create using 'set' need to be allowed to dispose by setting them to nothing after use.
set rs = server.createobject("adodb.recordset")
rs.open sql, db, 1, 3 ' adOpenKeyset, adLockOptimistic
' some process here
rs.close
set rs = nothing

Resources