1

The command:

appcmd lock config -section:...

Will lock the specified config section. But I need to check if the config section is locked or not.

Is there any possible way to do that? Thanks for any reply!

Tran Ngu Dang
  • 2,540
  • 6
  • 29
  • 38
  • I am not to familiar with `appcmd`, but when the `config` object-type is locked, is there a list command or similar command that changes nothing, which will be denied when config is locked and allowed when unlocked? – David Ruhmann Jan 11 '13 at 18:11
  • Hi, did you ever find a solution to this? I have the same problem - i only want to run the unlock if it's locked (chef) – Stono Feb 20 '14 at 12:52

1 Answers1

2

I know this is a few years old now but I was searching for this for Puppet so here's what I came up with.

The command Get-WebConfigurationLock shows if any locks exist on the config section.

E.g. to check the IIS global config section for system.webServer/security/ipSecurity:

Get-WebConfigurationLock -PSPath "IIS:\" -Filter //system.webServer/security/ipSecurity

If the section is unlocked the above command will return null. e.g. to "unlock if locked":

if (Get-WebConfigurationLock -PSPath "IIS:\" -Filter //system.webServer/security/ipSecurity)  {
    %windir%/System32/inetsrv/appcmd.exe unlock config -section:system.webServer/security/ipSecurity
} else {
    Write-Host "Already unlocked"
}

Remove-WebConfigurationLock can be used instead of appcmd, I favoured appcmd because you can pass lock/unlock as a parameter rather than changing the command itself.

Not sure what Chef looks like though here's the puppet define I've created to unlock/lock sections for reference: https://gist.github.com/krutisfood/d59b3a5c62f6123bf553

For reference I found this Stack Overflow link Programmatically unlocking IIS configuration sections in Powershell though found that Get-WebConfigurationLock more accurately matched the locked state, even reloading the dll or the powershell window getting the attribute value often show IsLocked false when it was locked. ymmv.

Community
  • 1
  • 1
krutisfood
  • 143
  • 6