0

环境:Windows 2008 R2 x64,IIS 7

我正在尝试将“应用程序”和“应用程序池”添加到 IIS。IIS 已配置并且运行良好。我已经手动添加了站点/应用程序 - 它们也可以正常工作。

import wmi

oWebAdmin = wmi.GetObject(r"winmgmts:root\WebAdministration")

strApplicationPath = "/my_site"
strSiteName = "Default Web Site"
strPhysicalPath = r"C:\Windows\SysNative\certsrv\mscep"

#fails here:
oWebAdmin.Get('Application').Create(strApplicationPath, strSiteName, strPhysicalPath)

oWebAdmin.Get("ApplicationPool").Create("NewAppPool")

我得到错误:

Traceback (most recent call last):
  File "C:\work\selenium-project\mdm-setup-assistant\ndes\install_dnes_service.py", line 23, in <module>
    oWebAdmin.Get('Application').Create(strApplicationPath, strSiteName, strPhysicalPath)
  File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line 505, in __getattr__
    ret = self._oleobj_.Invoke(retEntry.dispid,0,invoke_type,1)
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, u'SWbemObjectEx', u'Invalid parameter ', None, 0, -2147217400), None)

有趣的是,.Create() msdn说我输入的所有参数都是有效的。

我尝试了什么:

1)首先创建应用程序池(但是顺序无关紧要,因为我需要在创建它们时绑定它们)

oWebAdmin.Get("ApplicationPool").Create("NewAppPool")

而且,当然,我得到了非常相似的错误:

Traceback (most recent call last):
  File "C:\work\selenium-project\mdm-setup-assistant\ndes\install_dnes_service.py", line 17, in <module>
    oWebAdmin.Get("ApplicationPool").Create("NewAppPool")
  File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line 505, in __getattr__
    ret = self._oleobj_.Invoke(retEntry.dispid,0,invoke_type,1)
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, u'SWbemObjectEx', u'Invalid parameter ', None, 0, -2147217400), None)

2)我试图列出应用程序。这有效:

oApps = oWebAdmin.InstancesOf("Application")

for app in oApps:
    print app.SiteName 
    print app.Path
    print app.ApplicationPool
    print app.EnabledProtocols

输出:

Default Web Site
/
DefaultAppPool
http

Default Web Site
/CertSrv/mscep_admin
SCEP
http

Default Web Site
/CertSrv/mscep
SCEP
http

MyApp
/
MyApp AppPool
http

我的.Create()电话可能有什么问题?

注意:我正在以提升的权限运行(如果这很重要)

更新:可能.Get会失败?:不,肯定是.Create()

app = oWebAdmin.Get('Application')

#fails here:
app.Create(strApplicationPath, strSiteName, strPhysicalPath)

错误:

Traceback (most recent call last):
  File "C:\work\selenium-project\mdm-setup-assistant\ndes\install_dnes_service.py", line 18, in <module>
    app.Create(strApplicationPath, strSiteName, strPhysicalPath)
  File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line 505, in __getattr__
    ret = self._oleobj_.Invoke(retEntry.dispid,0,invoke_type,1)
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, u'SWbemObjectEx', u'Invalid parameter ', None, 0, -2147217400), None)
4

1 回答 1

0

你确定不是 GET 失败了吗?

于 2012-12-19T21:17:38.560 回答