环境: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()
from 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)
答案 0 :(得分:0)
你确定GET没有失败吗?