导航

命令行添加用户的“作为服务登录”权利

Posted on 2009-02-18 12:50  pegger  阅读(852)  评论(0编辑  收藏  举报

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;

 

 

河南恒友科贸有限公司 
电话 :0371-53733453    传真:0371-65388972
地址:郑州市郑花路8号 E-mail:hengyousoft@QQ.com