Powerful VB Script
2008-05-05 10:36 俺是老Z 阅读(408) 评论(0) 编辑 收藏 举报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
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
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
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. :)