When a user logs onto my TERMINALSERVER I want to check their credentidials and if they belong to a certain group then I want to place a shortcut on their desktop. I have written the VBScript below but it seems to be bombing out on my LDAP statement as follows:
strPath ="LDAP://DBSERVER/CN=" & strUser & ",CN=users,DC=brombergs,DC=local"
WScript.Echo strPath
Set objUser = GetObject(strPath) <<<<< ERRORS OUT HERE
ERROR MESSAGE: No such object exists on the server
The code runs on TERMINALSERVER but my DC is called ADSERVER. I don't know if this makes a difference.
Thank you in advance for any help.
Option Explicit
Dim objGroup, objUser, objRootDSE
Dim objDomain, objOU, objMemberOf ' Objects
Dim strGroup, strPath, strUser, strOU, strDNSDomain, strDesktopFolder, strFile, strUserName
Dim objShell, objShortCut, WshShell, objFSO, objShortCutFile
Set wshShell = WScript.CreateObject("WScript.Shell")
strUserName = WshShell.ExpandEnvironmentStrings("%USERNAME%")
Set objShortCutFile = CreateObject("Scripting.FileSystemObject")
If objShortCutFile.FileExists("C:\Documents and Settings\" & strUserName & "\Desktop\BROMBERGS.lnk") Then
objShortCutFile.DeleteFile("C:\Documents and Settings\" & strUserName & "\Desktop\BROMBERGS.lnk")
Else
End If
' Commands to bind to AD and extract domain name
Set objRootDSE = GetObject("LDAP://RootDSE")
'strDNSDomain = objRootDSE.Get("DefaultNamingContext")
strDNSDomain="DC=brombergs,DC=local"
strOU ="CN=Users,"
Set wshShell = WScript.CreateObject("WScript.Shell")
strUserName = WshShell.ExpandEnvironmentStrings("%USERNAME%")
strUser ="CN=" & strUserName & ","
' Building the LDAP path
strPath ="LDAP://DBSERVER/CN=" & strUser & ",CN=users,DC=brombergs,DC=local"
WScript.Echo strPath
Set objUser = GetObject(strPath)
WScript.Echo strPath
objMemberOf = objUser.GetEx("MemberOf")
' Here is the heart of the script, extract MemberOf
For Each objGroup in objMemberOf
'**********************************************************************
'you have to edit this line to reflect your group and domain information
If objGroup = "CN=BrombergsUsers,CN=Users,DC=brombergs,DC=local" Then
'**********************************************************************
strFile = "C:\Documents and Settings\" & strUserName & "\Desktop\BROMBERGS.lnk"
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(strFile) Then
Else
Set objShell = WScript.CreateObject("WScript.Shell")
strDesktopFolder = objshell.SpecialFolders("Desktop")
set objShortCut = objshell.CreateShortcut(strDesktopFolder & "\BROMBERGS.lnk")
objShortCut.TargetPath = "\\dbserver\appwin\ASCMenu.exe C:Brombergs"
objShortCut.Description = "Brombergs ACS System"
objShortCut.Save
End If
Else
End If
Next
WSCript.Quit
' End of Script
strPath ="LDAP://DBSERVER/CN=" & strUser & ",CN=users,DC=brombergs,DC=local"
WScript.Echo strPath
Set objUser = GetObject(strPath) <<<<< ERRORS OUT HERE
ERROR MESSAGE: No such object exists on the server
The code runs on TERMINALSERVER but my DC is called ADSERVER. I don't know if this makes a difference.
Thank you in advance for any help.
Option Explicit
Dim objGroup, objUser, objRootDSE
Dim objDomain, objOU, objMemberOf ' Objects
Dim strGroup, strPath, strUser, strOU, strDNSDomain, strDesktopFolder, strFile, strUserName
Dim objShell, objShortCut, WshShell, objFSO, objShortCutFile
Set wshShell = WScript.CreateObject("WScript.Shell")
strUserName = WshShell.ExpandEnvironmentStrings("%USERNAME%")
Set objShortCutFile = CreateObject("Scripting.FileSystemObject")
If objShortCutFile.FileExists("C:\Documents and Settings\" & strUserName & "\Desktop\BROMBERGS.lnk") Then
objShortCutFile.DeleteFile("C:\Documents and Settings\" & strUserName & "\Desktop\BROMBERGS.lnk")
Else
End If
' Commands to bind to AD and extract domain name
Set objRootDSE = GetObject("LDAP://RootDSE")
'strDNSDomain = objRootDSE.Get("DefaultNamingContext")
strDNSDomain="DC=brombergs,DC=local"
strOU ="CN=Users,"
Set wshShell = WScript.CreateObject("WScript.Shell")
strUserName = WshShell.ExpandEnvironmentStrings("%USERNAME%")
strUser ="CN=" & strUserName & ","
' Building the LDAP path
strPath ="LDAP://DBSERVER/CN=" & strUser & ",CN=users,DC=brombergs,DC=local"
WScript.Echo strPath
Set objUser = GetObject(strPath)
WScript.Echo strPath
objMemberOf = objUser.GetEx("MemberOf")
' Here is the heart of the script, extract MemberOf
For Each objGroup in objMemberOf
'**********************************************************************
'you have to edit this line to reflect your group and domain information
If objGroup = "CN=BrombergsUsers,CN=Users,DC=brombergs,DC=local" Then
'**********************************************************************
strFile = "C:\Documents and Settings\" & strUserName & "\Desktop\BROMBERGS.lnk"
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(strFile) Then
Else
Set objShell = WScript.CreateObject("WScript.Shell")
strDesktopFolder = objshell.SpecialFolders("Desktop")
set objShortCut = objshell.CreateShortcut(strDesktopFolder & "\BROMBERGS.lnk")
objShortCut.TargetPath = "\\dbserver\appwin\ASCMenu.exe C:Brombergs"
objShortCut.Description = "Brombergs ACS System"
objShortCut.Save
End If
Else
End If
Next
WSCript.Quit
' End of Script