Hi,
I'm trying to kick off the iiscnfg.vbs from a webservice to export a
website's config to an xml file (And eventually populate other servers with
the config). I initially tried this using the 1.1 framework, but discovered
that when I used Process.Start() the user's credentials were not
impersonated, it just kept using the asp.net's user, so I switched the
webservice over to 2.0 as Diagnostics.Process.StartInfo now has username,
password and domain properties. If I set these however, the service hangs. If
I check the processes list on the server, I can see that cscript.exe fires
up, but nothing else seems to happen. If I kill that process then the
webservice returns but the script never gets run, otherwise it just sits
there, probably until my browser would timeout. If I take away the username
and password, the script runs fine, however it returns access denied due to
the ASP.NET account not having permission to run that script. Does anyone
have any idea why it's locking up, I tried just running a .bat file, but that
locked up too! So it's not cscript it's having problems with... here's the
VB.NET code I've written:
<WebMethod()> _
Public Function publishToCluster(ByVal site As String) As String
Try
Return copyIISTree("/lm/w3svc/" & site, "")
Catch ex As Exception
Return ex.ToString
End Try
End Function
Private Function copyIISTree(ByVal sourcePath As String, ByVal
destinationPath As String) As String
Dim p As New Diagnostics.Process
p.StartInfo.RedirectStandardOutput = True
p.StartInfo.UseShellExecute = False
p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden
p.StartInfo.UserName = "<someusername>"
Dim pw As New System.Security.SecureString
For Each ch As Char In "<somepassword>"
pw.AppendChar(ch)
Next
p.StartInfo.Password = pw
p.StartInfo.Domain = "<somedomain>"
p.StartInfo.FileName = "c:\windows\system32\cscript.exe"
p.StartInfo.Arguments = "c:\windows\system32\iiscnfg.vbs /export /f
d:\test.xml /sp " & sourcePath & " /inherited /children"
p.Start()
Try
p.WaitForExit()
Catch ex As Exception
End Try
Dim output As String = ""
output = p.StandardOutput.ReadToEnd
p.Close()
p.Dispose()
Return output
End Function
Thanks.
--
Paul.