VB script to copy a file if member of an AD group - Need help

Hi guys, I normally use powershell and am venturing into a little VB.  

I have written a script to copy a file to the subdirictory in the users AppData directory if they are a member of a certain group in AD.  The problem is that it always thinks I am a member of the group and copies the file even if I am not a member.  Can someone help me with my code please?

Thanks,

Keith

*** Script Begin ***

 

Set objNetwork = CreateObject("WScript.Network")
Set objShell = CreateObject("WScript.Shell")
strUserDomain = objNetwork.UserDomain
strUserName = objNetwork.UserName
Set objWinntUser = GetObject("WinNT://" & strUserDomain & "/" & strUserName)

strGroupToCheck = "RecordedIMs"
strShortcut = "\\XXX.local\netlogon\global.xml"
strDesktop = objShell.ExpandEnvironmentStrings("%UserProfile%") & "\AppData\Local\AIM\Settings\"

If IsMemberOfGroup(strUserComputer, objWinntUser, strGroupToCheck) = False Then
MsgBox "You are not a member of the " & strGroupToCheck & " group."
Else
MsgBox "You are a member of the " & strGroupToCheck & " group."
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CopyFile strShortCut, strDesktop, True
End If

Function IsMemberOfGroup(strUserDomain, objUser, strGroup)
      IsMemberOfGroup = False
      Dim objGroup
      On Error Resume Next
      Set objGroup = GetObject("WinNT://" & strUserDomain & "/" & strGroup & ",group")
      If Err.Number Then
            IsMemberOfGroup = "Error"
      Else
            IsMemberOfGroup = objGroup.IsMember(objUser.ADsPath)
      End If
End Function

*** Script End ***


  • Edited by Keithdubya Wednesday, July 02, 2014 3:43 PM Edited out company name
July 2nd, 2014 6:31pm

Looks like strUserComputer is not defined.

Free Windows Admin Tool Kit Click here and download it now
July 2nd, 2014 7:00pm

You are Correct.  Typo, it should have been strUserDomain.

Thanks for your help.

Keith


  • Edited by Keithdubya Wednesday, July 02, 2014 4:07 PM
July 2nd, 2014 7:05pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics