標籤:
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
命令列添加使用者的“作為服務登入”權利(添加Windows使用者的時候,門道不是一般的多)good