列出本機(localhost)的使用者帳號(User Account) #2
修改微軟MSDN文件上的一個範例後,就變得簡單多了。
上一篇文章的方法較蠢(列出本機(localhost)的使用者帳號(User Account) )
我修改微軟MSDN文件上的一個範例後,就變得簡單多了。
.....................................................................................................................
Imports System.DirectoryServices
Partial Class 每個人都不一樣
Inherits System.Web.UI.Page
'==資料來源:http://msdn.microsoft.com/zh-tw/library/87tye19w(VS.80).aspx
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim objDE As DirectoryEntry
'--使用DirectoryEntry,可以查 LDAP與 WinNT 以下兩行是自己動手填寫
'Dim strPath As String = "LDAP://DC=onecity,DC=corp,DC=fabrikam,DC=com"
'Dim strPath As String = "WinNT://Acer_4105NB"
'--下面這一行,是系統自動尋找本機名稱
Dim strPath As String = "WinNT://" + Environment.MachineName
'==================================================
objDE = New DirectoryEntry(strPath)
Dim output_string As String = Nothing
Dim objChildDE As DirectoryEntry
For Each objChildDE In objDE.Children
If objChildDE.SchemaClassName = "User" Then '--只搜尋使用者名稱
output_string = output_string + objChildDE.Name & "<br>"
'--列出所有物件(使用者、群組等等)的名稱
End If
Next objChildDE
Label1.Text = output_string
End Sub
End Class
2009/3/2補充 -- 上面的User(使用者帳號)位置,可以寫成Group(群組)或Service(服務名稱)
.................................................................................................
您也可以參考這一篇文章的解法:
http://social.msdn.microsoft.com/Forums/zh-TW/236/thread/3110f5f8-16f9-4a16-bc42-55d54ec1b14e
我在最後有提供一段程式碼,是可以運作的。
我將思想傳授他人, 他人之所得,亦無損於我之所有;
猶如一人以我的燭火點燭,光亮與他同在,我卻不因此身處黑暗。----Thomas Jefferson
線上課程,遠距教學 (Web Form 49hr) https://dotblogs.com.tw/mis2000lab/2016/02/01/aspnet_online_learning_distance_education_VS2015
線上課程,遠距教學 (ASP.NET MVC 75~80hr) https://dotblogs.com.tw/mis2000lab/2018/08/14/ASPnet_MVC_Online_Learning_MIS2000Lab
ASP.NET MVC線上課程 第一天 免費看 (5.5小時)
寫信給我,不要私訊 -- mis2000lab (at) yahoo.com.台灣 或 school (at) mis2000lab.net
ASP.NET遠距教學、線上課程(Web Form + MVC)。 第一天課程, "完整" 試聽。
................ facebook社團 https://www.facebook.com/mis2000lab ......................
................ YouTube (ASP.NET) 線上教學影片 https://www.youtube.com/channel/UC6IPPf6tvsNG8zX3u1LddvA/
Blog文章 "附的範例" 無法下載,請看 這裡 ...... https://dotblogs.com.tw/mis2000lab/2016/03/14/2008_2015_mis2000lab_sample_download
請看我們的「售後服務」範圍(嚴格認定)。
......................................................................................................................................................
[遠距教學、教學影片] ASP.NET (Web Form) 課程 上線了!MIS2000Lab.主講
事先錄製好的影片,並非上課時側錄! 觀看影片時,有如我「一對一」跟您面對面講課。
ASP.NET MVC 5 線上教學
累積時數約 75~ 80小時...... 第一天(5.5小時)完整內容,"免費"讓您評估