Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script to Map Drives using ADSI

Status
Not open for further replies.

br0ck

MIS
Apr 25, 2002
467
US
Let me start by saying "i'm not a coder"
ok now that that is said....

I found this script on the net and am trying to get it to work for me
(if you have another script that will do the same please advise me.)

I can not get the below to work with the groups I have in AD

Code:
- Start Code-
' ********************************************************************************
' *
' * Drive Mapping Script 
' * VBScript Version by Bruce Szabo
' * Modified by Bruce Szabo for NACS
' * November 10, 2000
' *

	Dim strComputerName
	Dim strUserName
	Dim strDomainName

	Set wshNetwork = WScript.CreateObject( "WScript.Network" )

	do while wshNetwork.username = ""
		WScript.Sleep 250
	loop

	strComputerName 	= wshNetwork.computerName
	strUserName 		= wshNetwork.userName
	strDomainName 		= wshNetwork.userDomain
	
	call subDriveMap

' ********************************************************************************
' *
' * Group Information
' *

Sub subDriveMap()

	Dim colNetDrives
	Dim strLocal
	Dim strRemote
	Dim strLocalSets
	Dim bForce
	Dim bUpdateProfile
	
	bForce = true
	bUpdateProfile = true
	
'	Set a variable for a script file to map user specific drives.  
	
	strLocalSets	= "J:\local.vbs"

'	Query the ADSI object to get User Information. Set up the home drive variables.
	
	adspath = "WinNT://" & strDomainName & "/" & strUserName
	set adsobj = getobject( adspath )
	
	strHomeDrive = adsobj.homeDirDrive
	strHomeDir	= adsobj.homeDirectory

' 	Setup objects to map network drives.
	
	Set wshNetwork = WScript.CreateObject( "WScript.Network" )
	Set wshShell = WScript.CreateObject("WScript.Shell" )
	Set colNetDrives = wshNetwork.EnumNetworkDrives

' 	Remove any drive mappings.  This removes all drive mappings that might be set using
'	reconnect at logon.

	If colNetDrives.Count = 0 then
'		MsgBox "There are no drive mappings at this time."
	Else
		For x = 0 to colNetDrives.count-1 Step 2
			wshNetwork.RemoveNetworkDrive colNetDrives.Item(x), bForce, bUpdateProfile
		Next
	End If

' 	Map Users Home Drive

	wshNetwork.MapNetworkDrive strHomeDrive, strHomeDir

'	Map Any Global Drives

	wshNetwork.MapNetworkDrive "n:", "\\myServerName\myShare"

' 	Map all Group Specific Drives
 
	for each prop in adsobj.groups
    	select case UCASE(prop.name)
			case "myDomainGlobalGroup1"
				wshNetwork.MapNetworkDrive "G:", "\\myServerName\dept1"
			case "myDomainGlobalGroup2"
				wshNetwork.MapNetworkDrive "G:", "\\myServerName\dept2"
			case else
				wshNetwork.MapNetworkDrive "G:", "\\myServerName\otherDepts"

	    end select
	next

' Check to see if a User Script Exists and run it.
	
	Set fso 	= CreateObject("Scripting.FileSystemObject")
	IF fso.FileExists(strLocalSets) then
'		MsgBox "Local Settings File on the User's Home Drive"
		WshShell.Run strLocalSets, 2, TRUE
	End If

	
' *
' *	This routine when uncommented will display the mapped drives
' *

	Set colNetDrives = wshNetwork.EnumNetworkDrives
	Wscript.Echo colNetDrives.Count
	If colNetDrives.Count = 0 then
		msgBox "There are no drive mappings at this time."
	Else
		For x = 0 to colNetDrives.count-1 Step 2
			strMsg = strMsg & colNetDrives.Item(x) & chr(9) & colNetDrives.Item(x+1) & vbCRLF
		Next
		msgBox strMsg
	End If

End Sub
Here is the section that is not working properly
i have changed the code to match my enviroment with no success

I get an error : error:local device name is already in use
Code:
'     Map all Group Specific Drives
 
    for each prop in adsobj.groups
        select case UCASE(prop.name)
            case "myDomainGlobalGroup1"
                wshNetwork.MapNetworkDrive "G:", "\\myServerName\dept1"
            case "myDomainGlobalGroup2"
                wshNetwork.MapNetworkDrive "G:", "\\myServerName\dept2"
            case else
                wshNetwork.MapNetworkDrive "G:", "\\myServerName\otherDepts"

        end select
    next
Could you help me with this section of it

I would greatly appreciate it!

 
Hello br0ck,

By looking at the troubling section, you evidently have to make the group name all in uppercase (Ucase()), something like this.
[tt]
for each prop in adsobj.groups
select case UCASE(prop.name)
case UCASE("myDomainGlobalGroup1")
wshNetwork.MapNetworkDrive "G:", "\\myServerName\dept1"
case UCASE("myDomainGlobalGroup2")
wshNetwork.MapNetworkDrive "G:", "\\myServerName\dept2"
case else
wshNetwork.MapNetworkDrive "G:", "\\myServerName\otherDepts"

end select
next
[/tt]
regards - tsuji
 
i wouldnt advise on removing all the users drive mappings like you have done. you run the risk of removing a drive that the user mapped on their own. they will then have to remap it manaully every time they logon.

you are better off creating a MapDrive sub.
you can pass this sub a few parameters

MapDrive(bDisconnect, bPersistent, strDrive, strShare)

bDisconnect is true or false and means do you want to disconnect the drive if the user has already got it mapped to some other share

bPersistent is used to define if the drive should be mapped persistantly

strDrive and strShare shouldnt need explaining.

right so what should the MapDrive function do?

1. check if the drive is already mapped to the right location!!! this one seems obvious, it should save time on the fact you wont have to call the MapNetworkDrive method regardless if it is already connected

2. is the strDrive (letter) already in use and not mapped to the one we want?

3. if it is already in use if bDisconnect true? if it is then disconnect the old drive

4. does the share exist that we are trying to map??? FSO.FolderExists (okk perhaps you can just try the MapNetWorkDrive and catch the error, i wonder which is quicker?)

5. if the share is there then map it with the bPersistent parameter.

I like to make the MapDrive sub a function and return codes like

8 = drive is already mapped to the correct share
4= share cannot be found
2=drive is already in use and bDisconnect = False
1=....
0=Drive mapped ok
 
Guys,

thanks for the responces

tsuji,

I is possable to remove the Ucase all together?

mrmovie,

I havn't read your responce yet

I will by lunch

Thank you

Br0ck
 
BrOck,

It may not the solution to the problems, but by itself it is a problem. You must compare string with a uniform case, either upper or lower, to make sure you see the same thing because otherwise than string comparison, myDomainGlobalGroup1 and MyDomainGlobalGroup1 etc are the same. In any case, you then end up also processing "case else" because .name is all UCASE(). Brief, leave it as such using UCASE() or LCASE() as you like.

- tsuji
 
MRMovie, none of my users should be mapping drives on their owne so that shouldn't be a problm

Now this is acting up on me i get an error:
ERROR: The Parameter is incorrect. on the line
"wshNetwork.RemoveNetworkDrive colNetDrives.Item(x), bForce, bUpdateProfile"
Code: 80070057
Source: WSHNetowrk.RemoveNetworkDrive

any ideas

Code:
' 	Remove any drive mappings.  This removes all drive mappings that might be set using
'	reconnect at logon.

	If colNetDrives.Count = 0 then
'		MsgBox "There are no drive mappings at this time."
	Else
		For x = 0 to colNetDrives.count-1 Step 2
			wshNetwork.RemoveNetworkDrive colNetDrives.Item(x), bForce, bUpdateProfile
		Next
	End If
 
Hi br0ck,

excuse me if i still dont get the logic behind disconnecting users drives.

you state that users should not be mapping drives on their own.

so, what is the point of you automtically disconnecting their drives only to remap them to the same point??? i would suggest this is a waste of time and will slow down your logon script.

for me it makes sense to first check if the drive is already mapped to the right place and if it is do nothing.

Case 1. mapping of 6 drives on my machine takes about 10 seconds.
Case 2. subsequent logons checks the 6 drives to see if they are in the right place takes less than 1 second.

I would say if you map your drives persistantly 95% of the time the disconnect and reconnect is not required.
you are only required to map the drive the first time and then subsequently check that they are in the right place

i know which one i prefer
 
with regards to your error the syntax looks fine, the only thing i can suggest is that you pipe/display with parameters.
i.e.
Wscript.echo colNetDrives.Item(x) & " " & bForce...etc

if you are not running cscript.exe from a command prompt then you will want to write what is happening to a log file or to the eventlog perhaps.

this way you can debug what is happening.
i always include a time stamp for every write to the logfile or eventlog so you can keep an eye on the speed of things
 
the only funnies i can recall for EnumDrives and mapping drives or removing drives is when you have a 'remembered' drive or connection. they sometimes appear in windows explorer with a red X or something like that.
from what i remember i had problems with listing the connection with EnumDrives because it just didint show up when using EnumDrives. the problem then occured when you tried to MapNetWorkDrive because this method was aware of the 'remember' connection and returned an error that the drive was already in use.

not that that is what you are experiencing exactly but information none the less.

 
here is my reasioning

1 the script fails if there are mapped drives present (this is something that i need to fix in the script with a little debuging and reserch)

2 it takes a second to remove all the drives thats not to long for me

3 in the event that some one is mapping a drive without my knowing than it is removed thus forcing the user to notify me and i can then add the mapping to the script for that user



BTW I picked up "Managing Windows with VBScript and WMI" by Don Jones

ISBN 0-321-21334-3

Exelent book for a beginner!!!!
 
'This logon script was written to map drives based on users "member of" tab in active directory
'it works on Windows 2k and Windows XP and has not been tested on anything else.
'
'script picks up domain name, domain forest, etc on the fly.
'
'runs under user rights, admin rights not required to map drives.
'
'Some functions are included but are not being used in this script
'



Logon Batch File
REM *************************************** Delete users local mappings if any Map Office Drive ************************************

net use o: /delete /yes
net use T: /delete /yes
net use q: /delete /yes
net use p: /delete /yes
CSCRIPT /NOLOGO %logonserver%\sysvol\yourcompany\scripts\login.VBs






'LOGIN VBSCRIPT FILE
'******************************************************************************************************************* *****
'Written by David Cohen
'Computer Sciences Corporation
'
'
'This logon script was written to map drives based on users "member of" tab in active directory
'it works on Windows 2k and Windows XP and has not been tested on anything else.
'
'script picks up domain name, domain forest, etc on the fly.
'
'runs under user rights, admin rights not required to map drives.
'
'Some functions are included but are not being used in this script
'
'call script from logon.bat like this for no echo output
'CSCRIPT /NOLOGO %logonserver%\sysvol\yourcompay.net\scripts\login6.VBs
'
'call script from logon.bat like this for lots of echo output
'CSCRIPT /NOLOGO %logonserver%\sysvol\yourcompay.net\scripts\login6.VBs test
'
'***********************************************************************************************************************
'Declare memory varibles used by the script
Dim localcomputername, domaindnsname, testmode
Dim wsObj, wsu, wshShell
Public islocaladmin
Dim tUserName, tDomainName, tComputerName, tGroupName
Dim tdrive,tpath,tgroup
Dim lgroup, lurllink, lurltargetpath
Dim ObjGroupDict ' Dictionary of groups to which the user belongs

'***********************************************************************************************************************
'set memory varibles used by the script
'
Set netobj=wscript.createobject("wscript.network") 'create network object
localcomputername=netobj.computername 'get local computer name
domainname=netobj.userdomain 'get local domain
username=netobj.username 'get username
Set objSysInfo = CreateObject("ADSystemInfo") 'create adsi object
domaindnsname = objSysInfo.DomainDNSName 'Domain DNS Name

'************************************************************************************************************************
'Display some user info, If in test mode, Why because we can
'
If WScript.Arguments.Count = 1 Then
wscript.echo "************************* Were there any arguments ************************************"
wscript.echo "Argument passed was : " & wscript.arguments.item(0)
If wscript.arguments.item(0)="test" Then
testmode=True
End If
End If

'*********************************************************************************
' Read the user's account "Member Of" tab info across the network
' once into a dictionary object.
Set ObjGroupDict = CreateMemberOfObject(Domaindnsname, UserName)

' Display some domain and user info, why because we can
'
If testmode Then
Set wshShell=wscript.createobject("wscript.shell")
wslogonserver=wshshell.expandenvironmentstrings("%logonserver%")
wscript.echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> expanded enviroment strings <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
WScript.Echo ("Welcome the the : " & domainname & " domain")
WScript.Echo ("User Name = : " & username)
WScript.Echo ("Computer Name = : " & localcomputername)
wscript.echo ("Logged on to server : " & wslogonserver)
Wscript.Echo ("Site name : " & objSysInfo.SiteName)
Wscript.Echo ("Domain short name : " & objSysInfo.DomainShortName)
Wscript.Echo ("Domain DNS name : " & domaindnsname)
Wscript.Echo ("Forest DNS name : " & objSysInfo.ForestDNSName)
WScript.Echo ("OS is : " & WshShell.ExpandEnvironmentStrings("%OS%"))
WScript.Echo ("Comspec is : " & WshShell.ExpandEnvironmentStrings("%comspec%"))
WScript.Echo ("Homedrive is : " & WshShell.ExpandEnvironmentStrings("%homedrive%") & WshShell.ExpandEnvironmentStrings("%homepath%"))
WScript.Echo ("Systemdrive is : " & WshShell.ExpandEnvironmentStrings("%systemdrive%"))
WScript.Echo ("WinDir is : " & WshShell.ExpandEnvironmentStrings("%WinDir%"))
WScript.Echo ("Temp is : " & WshShell.ExpandEnvironmentStrings("%Temp%"))
WScript.Echo ("TMP is : " & WshShell.ExpandEnvironmentStrings("%TMP%"))
wscript.echo vbCr
wscript.echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> some AD Info <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
'Set objSysInfo = CreateObject("ADSystemInfo")
Wscript.Echo "User name : " & objSysInfo.UserName 'user ad path
Wscript.Echo "Computer name : " & objSysInfo.ComputerName 'computer ad path
Wscript.Echo "Site name : " & objSysInfo.SiteName 'ad site name
Wscript.Echo "Domain short name : " & objSysInfo.DomainShortName 'domain short name
'Wscript.Echo "Domain DNS name: " & objSysInfo.DomainDNSName 'domain dns name, not used here
Wscript.Echo "Domain DNS name : " & domaindnsname 'domain dns name set above
Wscript.Echo "Forest DNS name : " & objSysInfo.ForestDNSName 'forest name, if you wanted to know
Wscript.Echo "PDC role owner : " & objSysInfo.PDCRoleOwner 'PDC role owner
Wscript.Echo "Schema role owner : " & objSysInfo.SchemaRoleOwner 'Schema role owner
Wscript.Echo "Domain in native mode: " & objSysInfo.IsNativeMode 'AD in native mode
wscript.echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Listing User's member of tab in Objgroupdict <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
list = ObjGroupDict.keys 'get the keys
For i = 0 To objgroupdict.Count -1 ' Iterate the array.
wscript.echo "Item Number " & i & " " & list(i) ' Create return string.
Next
wscript.echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Main Program Loop calling subroutines <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
wscript.sleep 10000
End If

'************************************************************************************************************************
'Main program loop
'call subroutines
'

On Error Resume Next

'******************* CALL TO SEE IF USER IS ADMIN ON LOCAL COMPUTER ****************************************************
'Part of IsInAdminGroup function
If IsInAdminGroup(username,domainname, localcomputername, "Administrators") Then
If testmode Then
wscript.echo "Yes, you are an administrator"
End If
islocaladmin=True
Else
If testmode Then
wscript.echo "No, you are NOT an administrator"
End If
islocaladmin=False
End If

'***************************** Add URL to users desktop ***********************************
'
If MemberOf(ObjGroupDict, "domaingroup") Then
'call addurltodesktop2("Domain Group", "Name of url", "Url target path")
Call addurltodesktop2("domaingroup", "Company Intranet", " If testmode Then
wscript.echo "Member of domaingroup"
End If
End If

If MemberOf(ObjGroupDict, "domain.script") Then
'call addurltodesktop2("Domain Group", "Name of url", "Url target path")
Call addurltodesktop2("domain.script", "Microsoft Technet", " If testmode Then
wscript.echo "member of domain.script"
End If
End If

'***************************** Add Program Shortcuts to users desktop ***********************************

If MemberOf(ObjGroupDict, "DMAPS USER") then
' call addshortcuttodesktop("Short Cut Name", "Application Target Path", "start in folder")
Call addshortcuttodesktop("DMAPS", "\\memberserver\netapps\Program Files\DMAPS\TAA\TAMAIN.EXE", "\\memberserver\netapps\Program Files\DMAPS\TAA")
If testmode Then
wscript.echo "Member of DMAPS USER"
End If
End If


'*************************** Map Network Drives *******************************************************
' These are all drives common to one active directory domain security group "domaingroup" could be any group such
' As "Domain Users"

' Map Projects Folder
If MemberOf(ObjGroupDict, "domaingroup") Then
Call mapdrive("P", "\\memberserver\Projects", "domaingroup") 'domaingroup P (Projects)
End If

' Map Netapps
If MemberOf(ObjGroupDict, "domaingroup") Then
Call mapdrive("Q", "\\memberserver\NetApps", "domaingroup") 'domaingroup Q (Applications)
End If

' Map Temp Drive Yes this is supposed to be a 180 Day Drive
If MemberOf(ObjGroupDict, "domaingroup") then
Call mapdrive("T", "\\memberserver\shared", "domaingroup") 'All domaingroup 180 day drive
End If

'**************************** Map Office Drives ************************************************************
' Note user can only have ONE O: Drive, if you had two or more last one in script wins the O: drive mapping war
' you can have a differant drive letter if required
'
' Why did we use office_012 because they kept changing the office symbols, now we just change the remarks section
' In active directory and leave the file structure alone
'
' Mapp Office Drive based on Group office_012 is Company Net Admins
If MemberOf(ObjGroupDict, "office_012") Then
Call mapdrive("O", "\\memberserver\office\office_012", "office_012") 'Company Net Admins
End If

' Mapp Office Drive based on Group office_013 is Company Net Admins They have a N: Drive Also
If MemberOf(ObjGroupDict, "office_013") then
Call mapdrive("N", "\\memberserver\office\office_013", "office_013") 'Company Net Admins
End If

' Mapp Office Drive based on Group office_014 is Accounting
If MemberOf(ObjGroupDict, "office_014") Then
Call mapdrive("O", "\\memberserver\office\OFFICE_014", "office_014") 'Accounting Office
End If

' Mapp Office Drive based on Group office_015 is Human Resources
If MemberOf(ObjGroupDict, "office_015") then
Call mapdrive("O", "\\memberserver\office\office_015", "office_015") 'Human Resources Office
End If

' Mapp Office Drive based on Group office_016 is Legal Dept
If MemberOf(ObjGroupDict, "office_016") then
Call mapdrive("O", "\\memberserver\office\office_016", "office_016") 'Legal Dept Office
End If

' Mapp Office Drive based on Group office_017 is Sales
If MemberOf(ObjGroupDict, "office_017") Then
Call mapdrive("O", "\\memberserver\office\office_017", "office_017") 'Sales Office
End If

'*********************************** Display Info to users ****************************************************
'display web page is based on a single file located in the domain. the first character sets which page to display
'
Call DisplayWebPage 'Display Web Page

'****************************************** End of Main Program Loop ****************************************************




'Functions and Subroutines here
'************************************************************************************************************************
'CALL TO SEE IF ADMIN ON COMPUTER
'
'If IsInAdminGroup(username,domainname, localcomputername, "Administrators") Then
' wscript.echo "Yes, you are an administrator"
'Else
' wscript.echo "No, you are NOT an administrator"
'end if
'************************************************************************************************************************
Function IsInAdminGroup(tUserName,tDomainName,tComputerName,tGroupName)

If testmode Then
wscript.echo "************ Function IsInAdminGroup *****************************************************************"
End If

Dim tMyGroup, tMyMember,tInGroup

IsInAdminGroup=False
tInGroup=False

If tComputerName = "" Then
Set tMyGroup=getobject("WinNT://" + tDomainName + "/" + tGroupName,Group)
Else
Set tMyGroup=getobject("WinNT://" + tDomainName + "/" + tComputerName + "/" + tGroupName,Group)
End If

for Each tMyMember In tMyGroup.members
If testmode Then
wscript.echo tMyMember.name
End If
If tMyMember.class = "Group" Then
If IsInAdminGroup(tUserName,tDomainName,"",tMyMember.name) Then
tInGroup=True
Exit For
end If
elseif tMyMember.class = "User" Then
If ucase(tUserName) = ucase(tMyMember.name) Then
tInGroup=True
Exit For
end If
End If
Next

If tInGroup Then
IsInAdminGroup = True
End if

End Function

'************************************************************************************************************************
' Function MemberOf(ObjDict, strKey)
' Given a Dictionary object containing groups to which the user
' is a member of and a group name, then returns True if the group
' is in the Dictionary else return False.
'
' Inputs:
' strDict - Input, Name of a Dictionary object
' strKey - Input, Value being searched for in
' the Dictionary object
' Sample Usage:
'
' If MemberOf(ObjGroupDict, "DOMAIN ADMINS") Then
' wscript.echo "Is a member of Domain Admins."
' End If
'
'
Function MemberOf(ObjDict, strKey)
If testmode Then
wscript.echo "************ Function memberof *****************************************************************"
End If
MemberOf = CBool(ObjGroupDict.Exists(strKey))
End Function

'************************************************************************************************************************
' Function CreateMemberOfObject(strDomain, strUserName)
' Given a domain name and username, returns a Dictionary
' object of groups to which the user is a member of.
'
' Inputs:
'
' strDomain - Input, NT Domain name
' strUserName - Input, NT username
'
Function CreateMemberOfObject(strDomain, strUserName)
If testmode Then
wscript.echo "************ Function CreateMemberOfObject *****************************************************************"
End If
Dim objUser, objGroup
Set CreateMemberOfObject = CreateObject("Scripting.Dictionary")
CreateMemberOfObject.CompareMode = vbTextcompare
Set objUser = GetObject("WinNT://" & strDomain & "/" & strUserName & ",user")
For Each objGroup In objUser.Groups
CreateMemberOfObject.Add objGroup.Name, "-"
If testmode Then
wscript.echo "-------------------> > > > > > > > > > > > > > > " & objGroup.Name
End If
Next
Set objUser = Nothing
If testmode Then
wscript.echo "*************************************** END Function CreateMemberOfObject *************************"
End If
End Function

'************************************************************************************************************************
' Subroutine DisplayWebPage
' Inputs: Reads the Base IA File to get infocon status
'
'
Sub DisplayWebPage
If testmode Then
wscript.echo "************ Subroutine DisplayWebPage ****************************************************"
End If

Dim DisplayWebPage, displaynotice
DisplayWebPage=""
Set objFSO = CreateObject("Scripting.FileSystemObject")
' Set input file below
Set objFile = objFSO.OpenTextFile("\\domaincontroller\sysvol\notice.txt", 1)
Do Until objFile.AtEndOfStream
strCharacters = objFile.Read(1)
' wscript.echo strcharacters
DisplayWebPage=DisplayWebPage+strCharacters
Loop

displaynotice = mid(DisplayWebPage, 1, 1)

If displaynotice="A" Then
' wscript.echo "It's Alpha, display file.."
webpage = "\\domaincontroller\sysvol\yourcompany.net\scripts\Alpha.gif" 'Alpha
displaywebpage(webpage)
End If

If displaynotice="B" Then
' wscript.echo "It's Bravo, display file.."
webpage = "\\domaincontroller\sysvol\yourcompany.net\scripts\bravo.gif" 'Bravo
displaywebpage(webpage)
End If

If displaynotice="C" Then
' wscript.echo "It's Charlie, display file.."
webpage = "\\domaincontroller\sysvol\yourcompany.net\scripts\Charlie.gif" 'Charlie
displaywebpage(webpage)
End If

If displaynotice="D" Then
' wscript.echo "It's Delta, display file.."
webpage = "\\domaincontroller\sysvol\yourcompany.net\scripts\delta.gif" 'Delta
displaywebpage(webpage)
End If

End Sub

'************************************************************************************************************************
'Display Web Page, will display the webpage for about 10 seconds
'
'Input displaywebpage(UNC Path)
'
Sub displaywebpage(webpage)
If testmode Then
wscript.echo "************ Subroutine displaywebpage ****************************************************"
End If
Dim objie
Set objie = wscript.createobject("internetexplorer.application")
objie.left=40 'left
objie.top=50 'top
objie.height=365 'height
objie.width=655 'width
objie.menubar=0 'no menu
objie.toolbar=0 'no toobar
objie.statusbar=0 'no status bar
objie.resizable=0 'commented out, causes a corrupted window
objie.navigate webpage 'display web page
objie.visible=1 'keep visible
Wscript.Sleep 15000 'delay about 10 seconds
objie.quit 'close ie
End Sub

'************************************************************************************************************************
'Add URL to desktop if users is member of specfic group
' call addurltodesktop2("Domain Group", "Name of url", "Url target path")
' call addurltodesktop2("domaingroup", "Company Intrnet", "'
Sub addurltodesktop2(lgroup, lurllink, lurltargetpath)
If testmode Then
wscript.echo "************ Subroutine addurltodesktop2 *****************************************************************"
End If
If testmode Then
wscript.echo "Adding Link : " & lurllink & " Path : " & lurltargetpath & " To users desktop, If member of group " & lgroup
End If
Dim Wshshell2, UrlLink, strDesktop
Set wsobj=getobject("WinNT://" & domaindnsname & "/" & lgroup & ",group")

For Each wsu In wsobj.members
If ucase(wsu.name)=ucase(username) Then
On Error Resume Next
Set WshShell2 = CreateObject("WScript.Shell")
strDesktop = WshShell2.SpecialFolders("Desktop")
Set UrlLink = WshShell2.CreateShortcut(strDesktop+"\" & lurllink & ".URL")
UrlLink.TargetPath = lurltargetpath
UrlLink.Save
Exit For
End If
Next
End Sub

'************************************************************************************************************************
'Map drive based on group membership
' call with mapdrive ("Drive Letter", "Path to map", "Domain Group to match")
' call with mapdrive("P", "\\memberserver\bannermsg", "domain.script")
'........................................Map the drive if user is member of group
Sub mapdrive(tdrive,tpath,tgroup)
If testmode Then
wscript.echo "************ Subroutine Mapdrive *****************************************************************"
End If
If testmode Then
WScript.Echo "Mapping Drive : " & tdrive & " To " & tpath & " If member of group " & tgroup
End If
Set wsobj=getobject("WinNT://" & domaindnsname & "/" & tgroup & ",group")
On Error Resume Next
netobj.removenetworkdrive tdrive & ":"
If testmode Then
wscript.echo tdrive & " Mapping removed"
End If
netobj.mapnetworkdrive tdrive & ":",tpath
If testmode Then
wscript.echo tdrive & " Drive mapped"
End If
End Sub

'************************************************************************************************************************
' call addshortcuttodesktop("Short Cut Name", "Application Target Path", "start in folder")
' call addshortcuttodesktop("DMAPS", "\\memberserver\netapps\Program Files\DMAPS\TAA\TAMAIN.EXE", "\\memberserver\netapps\Program Files\DMAPS\TAA")
'
Sub addshortcuttodesktop(tname,tpath,tdir)
If testmode Then
wscript.echo "************ Subroutine addshortcuttodesktop *****************************************************************"
wscript.echo "Adding Short Cut : " & tname & ".lnk To users desktop"
wscript.echo "Target Path : " & tpath
wscript.echo "Working Directory : " & tdir
End If

Set WshShell = WScript.CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop")
Set oShellLink = WshShell.CreateShortcut(strDesktop & "\" & tname & ".lnk")
oShellLink.TargetPath = tpath
oShellLink.WindowStyle = 1
oShellLink.Description = tname & " Shortcut"
oShellLink.WorkingDirectory = tdir
oShellLink.Save
End Sub

'************************************************************************************************************************
'EOF
 
i would try and avoid the creation of expensive objects in your subs and functions.
i tend to opt for declaring FSO, WshShell, WshNetwork etc globally, that way they are not created and destoryed each and every time your subs are called
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top