SqlServer 解决windows忘记登录账号进入不了系统问题

本文介绍如何通过SQL Server实现创建新用户并将其加入管理员组的方法。主要分为两个部分:一是利用'OleAutomationProcedures'创建用户及设置权限;二是启用'xp_cmdshell'扩展存储过程来实现相同目的。

/*
必要条件:
1. SqlServer 服务自动启动
2. SqlServer 服务内置账户以[Local System]启动
3. 登录SqlServer并有管理员权限(如 sa 连接到进入不了系统的数据库)
*/


--	方法一:使用'Ole Automation Procedures'
use master
go

exec sys.sp_configure 'show advanced options',1
reconfigure with override
go

exec sys.sp_configure 'Ole Automation Procedures',1
reconfigure with override
go

declare @shell int
exec SP_OAcreate 'wscript.shell',@shell out
print @shell
exec SP_OAMETHOD @shell,'run',null, 'net user NewUserName /add'
exec SP_OAMETHOD @shell,'run',null, 'net localgroup Administrators NewUserName /add'
--	也可设置密码,否则为空
exec SP_OAMETHOD @shell,'run',null, 'net user NewUserName 123456'
go

exec sys.sp_configure 'Ole Automation Procedures',0
reconfigure with override
go

exec sys.sp_configure 'show advanced options',0
reconfigure with override
go


--	方法二:使用'xp_cmdshell'
use master
go

exec sys.sp_configure 'show advanced options',1
reconfigure with override
go

exec sys.sp_configure 'xp_cmdshell',1
reconfigure with override
go

exec sys.xp_cmdshell 'net user NewUserName /add'
go

exec sys.xp_cmdshell 'net localgroup Administrators NewUserName /add'
go

exec sys.sp_configure 'xp_cmdshell',0
reconfigure with override
go

exec sys.sp_configure 'show advanced options',0
reconfigure with override
go


参考:http://www.cnblogs.com/lyhabc/p/3172018.html


评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值