hey Morten...
Jeg fandt løsningen (for tre uger siden) og din hjælp var ganske fin. Løsningen blev som følger:
' Test program for the IncludeFile and ReadConfigFile functions.
' Author: Christian d'Heureuse (
www.source-code.biz)
' License: GNU/LGPL (
http://www.gnu.org/licenses/lgpl.html)
Option Explicit
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Importscript
Dim fso, i, ScriptDir, colDrives, WshNetwork, FileName, objConnection, objCommand, FindUser, strUser, objRecordSet, strDN, intLength, intNameLength, arrPath, OUName
set fso = CreateObject("Scripting.FileSystemObject")
Set WshNetwork = CreateObject("WScript.Network")
' Includes a file in the global namespace of the current script.
' The file can contain any VBScript source code.
' The path of the file name must be specified relative to the
' directory of the main script file.
Private Sub IncludeFile (ByVal RelativeFileName, ByVal filePath)
If filePath = "" Then
ScriptDir = fso.GetParentFolderName(WScript.ScriptFullName)
Else
ScriptDir = filePath
End If
FileName = fso.BuildPath(ScriptDir,RelativeFileName)
IncludeFileAbs FileName
End Sub
' Includes a file in the global namespace of the current script.
' The file can contain any VBScript source code.
' The path of the file name must be specified absolute (or
' relative to the current directory).
Private Sub IncludeFileAbs (ByVal FileName)
Const ForReading = 1
Dim f
set f = fso.OpenTextFile(FileName, ForReading)
Dim s
s = f.ReadAll()
ExecuteGlobal s
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''' reading the configfiles
' Includes the configuration file.
' The configiguration file has the name of the main script
' with the extension ".config".
Private Sub ReadConfigFile
Dim ConfigFileName
ConfigFileName = fso.GetBaseName(WScript.ScriptName) & ".config"
IncludeFile ConfigFileName, "\\emw2003dc\scripts$\"
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''' getting the current username
Public Function getCurrentUserName ()
Set WshNetwork = WScript.CreateObject("WScript.Network")
getCurrentUserName = WshNetwork.UserName
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Netværkdrevs-mounting
Public Sub mountingDevices()
Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
'FindUser = InputBox("Please Enter A UserName", "Find User OU")
FindUser = getCurrentUserName
If FindUser = "" Then
MsgBox("No UserName Was Added")
WScript.Quit
Else
strUser = FindUser
End If
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.CommandText = _
"SELECT distinguishedName FROM '
LDAP://dc=DOMÆNE,dc=dk' WHERE objectCategory='user'AND sAMAccountName='" & strUser & "'"
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
strDN = objRecordSet.Fields("distinguishedName").Value
arrPath = Split(strDN, ",")
intLength = Len(arrPath(1))
intNameLength = intLength - 3
OUName = Right(arrPath(1), intNameLength)
'Wscript.Echo "User :" & strUser & "_OU_" &OUName
objRecordSet.MoveNext
Loop
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''' removing existing mapped devices
On Error Resume Next
Set colDrives = WshNetwork.EnumNetworkDrives
For i = 0 to colDrives.Count-1 Step 2
WshNetwork.RemoveNetworkDrive colDrives.Item(i)
Next
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Default mounting new devices
If OUName <> "" Then
WshNetwork.MapNetworkDrive privateFolderLetter, (privateFolder & getCurrentUserName), True
WshNetwork.MapNetworkDrive publicFolderLetter, (publicFolders), True
End If
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Extra mounting for different OU Groups
If OUName = OULevel2 Then
'WshNetwork.MapNetworkDrive privateFolderLetter, (privateFolder & getCurrentUserName), True
'WshNetwork.MapNetworkDrive publicFolderLetter, (publicFolders), True
End If
If OUName = OULevel3 Then
'WshNetwork.MapNetworkDrive privateFolderLetter, (privateFolder & getCurrentUserName), True
'WshNetwork.MapNetworkDrive publicFolderLetter, (publicFolders), True
End If
If OUName = OULevel4 Then
'WshNetwork.MapNetworkDrive privateFolderLetter, (privateFolder & getCurrentUserName), True
'WshNetwork.MapNetworkDrive publicFolderLetter, (publicFolders), True
End If
If OUName = OULevel5 Then
'WshNetwork.MapNetworkDrive privateFolderLetter, (privateFolder & getCurrentUserName), True
'WshNetwork.MapNetworkDrive publicFolderLetter, (publicFolders), True
End If
If OUName = OULevel6 Then
'WshNetwork.MapNetworkDrive privateFolderLetter, (privateFolder & getCurrentUserName), True
'WshNetwork.MapNetworkDrive publicFolderLetter, (publicFolders), True
End If
If OUName = OULevel7 Then
'WshNetwork.MapNetworkDrive privateFolderLetter, (privateFolder & getCurrentUserName), True
'WshNetwork.MapNetworkDrive PublicFolderLetter, (publicFolders), True
End If
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Start!
ReadConfigFile
mountingDevices
WScript.Quit
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''' END
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''' .config-filen med samme fornavn som scriptfilen og placeret samme sted som scriptfilen
' This is a sample configuration file.
' Defining Libraries
Const privateFolder = "\\emw2003dc\usersmydocuments$\"
Const publicFolders = "\\emw2003dc\publicFolders$"
Const privateFolderLetter = "X:"
Const publicFolderLetter = "Y:"
' Defining OU-levels
Const OULevel1 = "Entire Up-Site"
Const OULevel2 = "Administration"
Const OULevel3 = "Backend"
Const OULevel4 = "Developer"
Const OULevel5 = "Freelancer"
Const OULevel6 = "Graphic"
Const OULevel7 = "Support"
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''' END SCRIPT
Hvis du vil ha point så smid et svar!