Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How To Verify User is in Group and Provide Shortcut

Status
Not open for further replies.

byrne1

Programmer
Aug 7, 2001
415
US
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
 
byrne1,

Try this:

Code:
On Error Resume Next

set ADSysInfo = CreateObject("ADSystemInfo")
set CurrentUser = GetObject("LDAP://" & ADSysInfo.UserName)
if IsArray(CurrentUser.MemberOf) then
 strGroups = LCase(Join(CurrentUser.MemberOf))
 else
  strGroups = LCase(CurrentUser.MemberOf)
end if
set ADSysInfo = nothing
set CurrentUser = nothing

Set WSHShell = CreateObject("WScript.Shell")
Set objfso = CreateObject("Scripting.FileSystemObject")
strDesktopFolder = WSHshell.SpecialFolders("Desktop")
strShortcut = strDesktopFolder & "\BROMBERGS.lnk"
If objfso.FileExists(strShortcut) then
 objfso.DeleteFile(strShortcut)
end if

if instr(strGroups,"cn=brombergsusers") then
 if objfso.FileExists(strShortcut) then
  else
   set objShortCut = WSHshell.CreateShortcut(strShortcut)
   objShortCut.TargetPath = "\\dbserver\appwin\ASCMenu.exe C:Brombergs"
   objShortCut.Description = "Brombergs ACS System"
   objShortCut.Save
   set objShortcut = nothing
 end if
end if

set WSHShell = nothing
set objfso = nothing

zcolton
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top