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