命令列添加使用者的“作為服務登入”權利(添加Windows使用者的時候,門道不是一般的多)good

來源:互聯網
上載者:User

標籤:

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.