简体   繁体   中英

Cannot create Application/ApplicationPool for IIS7 through WMI

Environment: Windows 2008 R2 x64, IIS 7

I'm trying to add "Application" and "Application Pool" to IIS. IIS is configured and is running just fine. I've manually added sites/applications - and they work fine as well.

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")

I get the error:

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)

The interesting part is that .Create() from msdn says all the parameters I put are valid.

What have I tried:

1) to create Application Pool first (however the order should not matter, since I need to bind them when they are both created)

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

and, of course, I get the very similar error:

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) I've tried to list the applications. And that works:

oApps = oWebAdmin.InstancesOf("Application")

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

Output:

Default Web Site
/
DefaultAppPool
http

Default Web Site
/CertSrv/mscep_admin
SCEP
http

Default Web Site
/CertSrv/mscep
SCEP
http

MyApp
/
MyApp AppPool
http

What could be wrong with my .Create() call?

NOTE: I'm running with elevated privileges (if that matters)

UPDATE: Could .Get be failing?: No, it's definetely .Create() :

app = oWebAdmin.Get('Application')

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

error:

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)

您确定不是GET失败吗?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM