středa 15. července 2009

Logon Script - mapování sdílených disků (VB Script)

ON ERROR RESUME NEXT

Dim wshNetwork, strUser, strComputer, objNetwork

Set wshNetwork = CreateObject("WScript.Network")

'zjisti uzivatelske jmeno a jmeno PC'
strUser = LCase(wshNetwork.UserName)
strComputer = LCase(wshNetwork.ComputerName)

'zrusi vsechny namapovane disky'
Set cDrives = wshNetwork.EnumNetworkDrives
For i = 0 to cDrives.Count -1 Step 2
wshNetwork.RemoveNetworkDrive cDrives.Item(i), True, True
Next

'cas na odpojeni namapovanych disku 300 milisekund'
wscript.sleep 300

'namapuje zakladni disky'
wshNetwork.MapNetworkDrive "H:", "\\server\shared", True
wshNetwork.MapNetworkDrive "G:", "\\server\shared\" & strUser, True

'namapuje disky dle pravidel'
Select Case strUser
'namapuje disk z jiného serveru pokud je uzivatel prihlasen na urcitem pocitaci'
Case "uzivatel"
If strComputer = "pocitac" Then
Set objNetwork = WScript.CreateObject("WScript.Network")
strLocalDrive = "I:"
strRemoteShare = "\\server\shared"
strPer = "FALSE"
strUsr = "domena\uzivatel"
strPass = "heslo"
objNetwork.MapNetworkDrive strLocalDrive, strRemoteShare, strPer, strUsr, strPass
End If
End Select

'vycisti pouzivanou pamet'
set wshNetwork = Nothing
set strUser = Nothing
set strComputer = Nothing
set objNetwork = Nothing

'ukonci script'
wscript.quit