命令行添加用户的“作为服务登录”权利(添加Windows用户的时候,门道不是一般的多)good
2016-10-19 00:24
423 查看
1、打开控制台(“开始”|“运行”中输入:MMC)
2、“文件”菜单|“添加删除管理单元”|“添加...”|选“安全模板”|“关闭”。
3、在“C:\Windows\Security\templates”节点上,右键“新建模板...”,在弹出的对话框中“模板名”中输入:new,确定。
4、打开“New|本地策略|用户权利指派”节点,在右侧的“作为服务器登录”中添加要赋予该权限的用户。
5、然后,在“New”节点上单击右键,选“另存为...”保存到“C:\Sec.inf”。
6、建立批处理文档中输入:secedit configure /db secedit.sdb /cfg c:\Sec.inf
这两天新项目中用到了SQLServer数据库同步功能,要求程序在安装过程中自动添加SQLServerAgent服务的登录账户。
下面将SetupFactory中写的代码写出来,供参考。
--安装MSDE2000
if (not Registry.DoesKeyExist(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\MSSQLServer\\Setup")) then
Shell.Execute(SessionVar.Expand("%AppFolder%\\MSDE2000\\setup.exe"), "open", "", "", SW_SHOWNORMAL, true);
end
--重启后附加数据库,及自动添加同步作业。
File.RunOnReboot(SessionVar.Expand("C:\\Program Files\\数据库\\Setup.cmd"), "");
--添加Windows用户
Shell.Execute("net", "open", "user SQLAgent 123456 /add /passwordreq:yes /passwordchg:no /expires:never", "", SW_MINIMIZE, true);
--将用户添加到Administrator组中
Shell.Execute("net", "open", "localgroup Administrators SQLAgent /add", "", SW_MINIMIZE, true);
--设置SQLServerAgent服务的登录帐号,密码,及启动类型为自动。
Shell.Execute("sc", "open", "config SQLSERVERAGENT start= auto obj= .\\SQLAgent password= 123456", "", SW_MINIMIZE, true);
--在Windows启动时隐藏该用户。
Shell.Execute("regedit", "open", "/s C:\\HideSQLAgent.reg", "", SW_MINIMIZE, true);
--赋予该用户"以服务登录的权利"和"拒绝本地登录"
Shell.Execute("secedit", "open", "/configure /db secedit.sdb /cfg c:\\Sec.inf", "", SW_MINIMIZE, true);
--清理临时文件
Folder.DeleteTree(SessionVar.Expand("%AppFolder%\\MSDE2000"), nil);
File.DeleteOnReboot("C:\\HideSQLAgent.reg");
File.DeleteOnReboot("c:\\Sec.inf");
--安装完毕后要求重新启动计算机
_NeedsReboot = true;
http://www.cnblogs.com/pegger/archive/2009/02/18/1393052.html
2、“文件”菜单|“添加删除管理单元”|“添加...”|选“安全模板”|“关闭”。
3、在“C:\Windows\Security\templates”节点上,右键“新建模板...”,在弹出的对话框中“模板名”中输入:new,确定。
4、打开“New|本地策略|用户权利指派”节点,在右侧的“作为服务器登录”中添加要赋予该权限的用户。
5、然后,在“New”节点上单击右键,选“另存为...”保存到“C:\Sec.inf”。
6、建立批处理文档中输入:secedit configure /db secedit.sdb /cfg c:\Sec.inf
这两天新项目中用到了SQLServer数据库同步功能,要求程序在安装过程中自动添加SQLServerAgent服务的登录账户。
下面将SetupFactory中写的代码写出来,供参考。
--安装MSDE2000
if (not Registry.DoesKeyExist(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\MSSQLServer\\Setup")) then
Shell.Execute(SessionVar.Expand("%AppFolder%\\MSDE2000\\setup.exe"), "open", "", "", SW_SHOWNORMAL, true);
end
--重启后附加数据库,及自动添加同步作业。
File.RunOnReboot(SessionVar.Expand("C:\\Program Files\\数据库\\Setup.cmd"), "");
--添加Windows用户
Shell.Execute("net", "open", "user SQLAgent 123456 /add /passwordreq:yes /passwordchg:no /expires:never", "", SW_MINIMIZE, true);
--将用户添加到Administrator组中
Shell.Execute("net", "open", "localgroup Administrators SQLAgent /add", "", SW_MINIMIZE, true);
--设置SQLServerAgent服务的登录帐号,密码,及启动类型为自动。
Shell.Execute("sc", "open", "config SQLSERVERAGENT start= auto obj= .\\SQLAgent password= 123456", "", SW_MINIMIZE, true);
--在Windows启动时隐藏该用户。
Shell.Execute("regedit", "open", "/s C:\\HideSQLAgent.reg", "", SW_MINIMIZE, true);
--赋予该用户"以服务登录的权利"和"拒绝本地登录"
Shell.Execute("secedit", "open", "/configure /db secedit.sdb /cfg c:\\Sec.inf", "", SW_MINIMIZE, true);
--清理临时文件
Folder.DeleteTree(SessionVar.Expand("%AppFolder%\\MSDE2000"), nil);
File.DeleteOnReboot("C:\\HideSQLAgent.reg");
File.DeleteOnReboot("c:\\Sec.inf");
--安装完毕后要求重新启动计算机
_NeedsReboot = true;
http://www.cnblogs.com/pegger/archive/2009/02/18/1393052.html
相关文章推荐
- 命令行添加用户的“作为服务登录”权利
- 组策略限制添加用户作为服务登录导致ITAtomcat服务无法启动(log on as a service)
- windows下sc create命令行添加/创建/修改服务
- Windows中添加svnserve作为系统服务
- Windows服务(system权限)程序显示界面与用户交互,Session0通知Session1里弹出对话框(真的很牛) good
- Windows下sc create命令行添加/创建/修改服务
- Win2003终端服务,添加多用户登录支持
- 通过Powershell, C#, CMD and VBScript等设置 用户 作为服务登录
- Windows 服务如何设置为多个用户可以远程登录
- windows命令行添加用户
- windows添加用户可以远程登录
- Windows:服务程序用当前登录用户来执行函数
- [windows]禁止指定用户使用远程桌面服务登录
- windows无法连接到user profile service服务。此问题阻止标准用户登录系统
- 课下参考五 linux的ssh服务实现多用户登录linux系统--windows客户端篇
- 写了一个Windows服务,通过C#模拟网站用户登录并爬取BUG列表查询有没有新的BUG,并提醒我
- 关于Windows 2008 IIS无法使用虚拟目录密码作为用户 administrator 在本地登录到...解决方案
- windows下sc create命令行添加/创建/修改服务
- 命令行登录局域网中的机器(windows中)
- WINDOWS 2000下如何获得用户登录名和密码