Powerful VB Script

本文介绍了一段VBS脚本代码,该代码用于设置IIS应用程序池的身份验证方式,并演示了如何将域用户添加到本地安全组中。

Just finished some code about vb script and realized how powerful it is, blog some useful code here:

function AssignAppPoolIdentity(AppPoolName)

    BasePath 
= "IIS://localhost/w3svc/AppPools"

    BasePath 
= BasePath & "/" & AppPoolName

    
Dim appPool

    
Set appPool = GetObject(BasePath)

    
'Tell IIS to use configurable identity for worker process
    appPool.AppPoolIdentityType = 3

    
'Set username
    appPool.WAMUserName = "domain\user"

    
'Set password
    appPool.WAMUserPass = "2wsx#EDC"

    
'Save changes to the IIS metabase
    appPool.SetInfo()

    

end function

Dim AppPool, AppPoolsList,AppPoolnName
Dim objArgs : Set objArgs = Wscript.Arguments

    
If objArgs.Count < 1 Then
        
        WScript.Quit(
0)
    
else
        AppPoolnName 
= objArgs(0)

    
end if

    
Set AppPoolsList = GetObject("IIS://localhost/w3svc/AppPools")
    
Set AppPool = AppPoolsList.Create("IISApplicationPool",AppPoolnName)
    AppPool.setInfo







function AddUserToIIS_WPG (username)
  
   
dim nw : set nw = CreateObject("WScript.Network")
   
dim computername : computername = nw.Computername
   
dim WMIUser
   
dim IIS_WPG
   
   
SET IIS_WPG = GetObject("WinNT://" & computername & "/IIS_WPG,group")
   
'Set WMIUser = GetObject("winmgmts:{impersonationlevel=impersonate}!/root/cimv2:Win32_UserAccount.Domain='domain',Name='user'")
    Set WMIUser = GetObject("WinNT://domain/user")

    
'Set objWMI = GetObject("winmgmts:\\" & computername & "\root\directory\LDAP")
    'Set objUsers = objWMI.ExecQuery("SELECT * FROM ds_user where ds_alias = 'user'")

    
'msgbox(objUsers.count)


    
msgbox(WMIUser.AdsPath)
    
      IIS_WPG.Add(WMIUser.AdsPath)


end function   


I spend a lot of time on how to add a domin user account into a local security group, but finally find out that no big difference compare with adding a local user. Please notice the code above. :)

转载于:https://www.cnblogs.com/helloyou/archive/2008/05/05/1182922.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值