使用VB或C#在广告中创建家庭目录 [英] Create homedirectory in ad with VB or C#

查看:56
本文介绍了使用VB或C#在广告中创建家庭目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

除了创建一个homedirectory这个代码有效。

任何人都可以给我正确的 homedirectory 值格式吗?

这个在AD的配置文件页面上给我正确的用户数据

属性(homedirectory)。添加(\\TestServer2 \Home_Folders $ \& sUserName)

但是在成员服务器TestServer2上没有创建用户文件夹。



我尝试过:



 公开  Sub  CreateAdAccount( ByVal  sUserName  As  字符串 ByVal  sPassword 作为 字符串 ByVal  sFirstName 作为 字符串, ByVal  sLastName 作为 字符串 ByVal  sGroupName 作为 字符串 ByVal  Ou 作为 字符串
尝试
' SaveTextToFile(1,AppLogPath)
Dim StrRoot As String = LDAP://&欧&
Dim root 作为 DirectoryEntry(StrRoot)
Dim newUser 作为 DirectoryEntry = root.Children.Add( CN =& sUserName, user
SetProperty (newUser, description 某些测试
SetProperty(newUser, givenname,sFirstName)
SetProperty(newUser, sn, sLastName)
SetProperty(newUser, SAMAccountName,sUserName)
SetProperty(newUser, DisplayName,Info .DisplayName)
SetProperty(newUser, userPrincipalName,sUserName& @ TecGroup.org
SetProperty(newUser, mail,sUserName& @ TecGroup.org
SetProperty(newUser, homedrive H:

' 格式错误?
' SetProperty(newUser,homedirectory,@ \\TestServer2 \Home_Folders $ \%UserName%)
' newUser.Properties(homedirectory)。添加(\\TestServer2 \Home_Folders $ \& sUserName)

newUser.CommitChanges()

newUser.Close()
root.Close()
'
写入日志
SaveTextToFile(sUserName& 添加到AD,密码& sPassword,AppLogPath)

Catch ExtendedErrorMessage As 异常
SaveTextToFile( 添加用户& sUserName& 失败,错误& ExtendedErrorMessage.Message,AppLogPath)
结束 尝试
结束 sub

解决方案

\& sUserName)

但是在成员服务器上没有创建用户文件夹TestServer2。



我的尝试:



 公共  Sub  CreateAdAccount( ByVal  sUserName 作为 字符串, ByVal  sPassword  As  字符串 ByVal  sFirstName 作为  String  ByVal  sLastName  As  字符串 ByVal  sGroupName 作为 字符串 ByVal  Ou  As   String 
尝试
' SaveTextToFile( 1,AppLogPath)
Dim StrRoot As String = LDAP://&欧&
Dim root 作为 DirectoryEntry(StrRoot)
Dim newUser 作为 DirectoryEntry = root.Children.Add( CN =& sUserName, user
SetProperty (newUser, description 某些测试
SetProperty(newUser, givenname,sFirstName)
SetProperty(newUser, sn, sLastName)
SetProperty(newUser, SAMAccountName,sUserName)
SetProperty(newUser, DisplayName,Info .DisplayName)
SetProperty(newUser, userPrincipalName,sUserName& @ TecGroup.org
SetProperty(newUser, mail,sUserName& @ TecGroup.org
SetProperty(newUser, homedrive H:

' 格式错误?
' SetProperty(newUser,homedirectory,@ \\TestServer2 \Home_Folders


\%UserName%)
< span class =code-comment>' newUser.Properties(homedirectory)。添加(\\TestServer2 \Home_Folders


\& sUserName)

newUser.CommitChange s()

newUser.Close()
root.Close()
' 写入日志
SaveTextToFile(sUserName& 添加到AD,密码& sPassword,AppLogPath)

Catch ExtendedErrorMessage As 异常
SaveTextToFile( 添加用户& sUserName& 失败,错误& ExtendedErrorMessage.Message,AppLogPath)
结束 尝试
结束 sub


With the exception of the creating a homedirectory this code works.
Can anyone give me the correct format for the homedirectory value?
this one give me the correct userdata on the profile page in AD
Properties("homedirectory").Add("\\TestServer2\Home_Folders$\" & sUserName)
but the users folder is not created on the members server TestServer2.

What I have tried:

Public Sub CreateAdAccount(ByVal sUserName As String, ByVal sPassword As String, ByVal sFirstName As String, ByVal sLastName As String, ByVal sGroupName As String, ByVal Ou As String)
Try
' SaveTextToFile("1", AppLogPath)
Dim StrRoot As String = "LDAP://" & Ou & ""
Dim root As New DirectoryEntry(StrRoot)
Dim newUser As DirectoryEntry = root.Children.Add("CN=" & sUserName, "user")
SetProperty(newUser, "description", "Some Test")
SetProperty(newUser, "givenname", sFirstName)
SetProperty(newUser, "sn", sLastName)
SetProperty(newUser, "SAMAccountName", sUserName)
SetProperty(newUser, "DisplayName", Info.DisplayName)
SetProperty(newUser, "userPrincipalName", sUserName & "@TecGroup.org")
SetProperty(newUser, "mail", sUserName & "@TecGroup.org")
SetProperty(newUser, "homedrive", "H:")

'format wrong ?
'SetProperty(newUser, "homedirectory", "@\\TestServer2\Home_Folders$\%UserName%")
'newUser.Properties("homedirectory").Add("\\TestServer2\Home_Folders$\" & sUserName)

newUser.CommitChanges()

newUser.Close()
root.Close()
'write to log
SaveTextToFile(sUserName & " added to AD, password " & sPassword, AppLogPath)

Catch ExtendedErrorMessage As Exception
SaveTextToFile("Add User " & sUserName & " failed, Error " & ExtendedErrorMessage.Message, AppLogPath)
End Try
end sub

解决方案

\" & sUserName)
but the users folder is not created on the members server TestServer2.

What I have tried:

Public Sub CreateAdAccount(ByVal sUserName As String, ByVal sPassword As String, ByVal sFirstName As String, ByVal sLastName As String, ByVal sGroupName As String, ByVal Ou As String)
Try
' SaveTextToFile("1", AppLogPath)
Dim StrRoot As String = "LDAP://" & Ou & ""
Dim root As New DirectoryEntry(StrRoot)
Dim newUser As DirectoryEntry = root.Children.Add("CN=" & sUserName, "user")
SetProperty(newUser, "description", "Some Test")
SetProperty(newUser, "givenname", sFirstName)
SetProperty(newUser, "sn", sLastName)
SetProperty(newUser, "SAMAccountName", sUserName)
SetProperty(newUser, "DisplayName", Info.DisplayName)
SetProperty(newUser, "userPrincipalName", sUserName & "@TecGroup.org")
SetProperty(newUser, "mail", sUserName & "@TecGroup.org")
SetProperty(newUser, "homedrive", "H:")

'format wrong ?
'SetProperty(newUser, "homedirectory", "@\\TestServer2\Home_Folders


\%UserName%") 'newUser.Properties("homedirectory").Add("\\TestServer2\Home_Folders


\" & sUserName) newUser.CommitChanges() newUser.Close() root.Close() 'write to log SaveTextToFile(sUserName & " added to AD, password " & sPassword, AppLogPath) Catch ExtendedErrorMessage As Exception SaveTextToFile("Add User " & sUserName & " failed, Error " & ExtendedErrorMessage.Message, AppLogPath) End Try end sub


这篇关于使用VB或C#在广告中创建家庭目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆