Friday, March 30, 2007

VBScript : IfMember and MapNetworkDrive

Set wshnetwork = CreateObject("Wscript.Network")
Set fso = CreateObject("Scripting.FileSystemObject")

Private Function IsMember(groupName)

Set wshnetwork = CreateObject("WScript.Network")
domain = wshnetwork.UserDomain
user = wshnetwork.UserName
flgIsMember = false
Set userObj = GetObject("WinNT://" & domain & "/" & user & ",user")
For Each grp In userObj.Groups
If grp.Name = groupName Then
flgIsMember = true
Exit For
End If
Next
IsMember = flgIsMember
Set userObj = nothing
Set wshnetwork = nothing

End Function

strComputer = "."

Set objWMIService = GetObject("winmgmts:" & "!\\" & strComputer & "\root\cimv2")
Set colAdapters = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled = True")

For Each objAdapter In colAdapters
If Not IsNull(objAdapter.IPAddress) Then
For i = LBound(objAdapter.IPAddress) To UBound(objAdapter.IPAddress)
address = objAdapter.IPAddress(i)
VLANX = instr(address, "10.14.3.")
If VLANX = 1 Then
IFM = IsMember("GG-VLS-SEN-CAO")
Set wshnetwork = CreateObject("Wscript.Network")
user = wshnetwork.UserName
If IFM = true then
If fso.folderexists("X:\")=False Then
WshNetwork.MapNetworkDrive "X:", "\\Paris\" & user
Else
WshNetwork.RemoveNetworkDrive "X:"
WshNetwork.MapNetworkDrive "X:", "\\Paris\" & user
End If
End If
End If
Next
End If
Next

M1 = IsMember("GG-HelpDesk")
Set wshnetwork = CreateObject("Wscript.Network")
user = wshnetwork.UserName
If M1 = true then
If fso.folderexists("R:\")=False Then
WshNetwork.MapNetworkDrive "R:", "\\Tokyo\HelpDesk"
Else
WshNetwork.RemoveNetworkDrive "R:"
WshNetwork.MapNetworkDrive "R:", "\\Tokyo\HelpDesk"
End If
End If

M2 = IsMember("GG-Project")
Set wshnetwork = CreateObject("Wscript.Network")
user = wshnetwork.UserName
If M2 = true then
If fso.folderexists("F:\")=False Then
WshNetwork.MapNetworkDrive "F:", "\\NewYork\project"
Else
WshNetwork.RemoveNetworkDrive "F:"
WshNetwork.MapNetworkDrive "F:", "\\NewYork\project"
End If
If fso.folderexists("M:\")=False Then
WshNetwork.MapNetworkDrive "M:", "\\NewYork\report"
Else
WshNetwork.RemoveNetworkDrive "M:"
WshNetwork.MapNetworkDrive "M:", "\\NewYork\report"
End If
End If

M3 = IsMember("GG-HR")
Set wshnetwork = CreateObject("Wscript.Network")
user = wshnetwork.UserName
If M3 = true then
If fso.folderexists("R:\")=False Then
WshNetwork.MapNetworkDrive "R:", "\\Hamilton\HR"
Else
WshNetwork.RemoveNetworkDrive "R:"
WshNetwork.MapNetworkDrive "R:", "\\Hamilton\HR"
End If
If fso.folderexists("X:\")=False Then
WshNetwork.MapNetworkDrive "X:", "\\vls-sen-s04\CV"
Else
WshNetwork.RemoveNetworkDrive "X:"
WshNetwork.MapNetworkDrive "X:", "\\vls-sen-s04\CV"
End If
End If

M4 = IsMember("GG-Director")
Set wshnetwork = CreateObject("Wscript.Network")
user = wshnetwork.UserName
If M4 = true then
If fso.folderexists("H:\")=False Then
WshNetwork.MapNetworkDrive "H:", "\\NewYork\Director"
Else
WshNetwork.RemoveNetworkDrive "H:"
WshNetwork.MapNetworkDrive "H:", "\\NewYork\Director"
End If
End If

Related Titles

 
visitors since March 26 2007
©2007