Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

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

$
0
0

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 ***



Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>