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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Logon Script

Status
Not open for further replies.

FROGGYJ

IS-IT--Management
Nov 12, 2002
200
0
0
CA
I'm testing using Mark's logon script and everything is going great except in AD we have the home folder mapped to H: \\server\username$ ($ for hidden).

When I run the logon script everything maps properly, except now that home folder doesn't get mapped. There is nothing else conflicting with H: so I don't understand the problem. If I use a batch file to map drives everything works fine.

I see in the script to use "UserString" but how do you attach a $ to that? since the share is actually UserString$ (make sense?)

Thanks in advance.

FROGGYJ
A+,N+,CST,CNCT,MCP
 
by the way I'm thinking it would be better for me to use the AD home folder redirection as it is that way currently. I just don't understand why a vbscript would stop it from mapping and a bat file works fine.

FROGGYJ
A+,N+,CST,CNCT,MCP
 
ok so I have found my problem. In the script it is disconnecting all drives, hence why my H was never showing up. Now I just need to tell it to disconnect everything except for H!

FROGGYJ
A+,N+,CST,CNCT,MCP
 
froggyj, I'd need to take a look at your code. Can you post it?

Hope This Helps,

Good Luck!
 
You could do something like this to skip the H: drive.

Code:
Set oNetwork = CreateObject("WScript.Network")
Set oEnumerate = oNetwork.EnumNetworkDrives
For i = 0 to oEnumerate.Count - 1 Step 2
  Select Case Trim(oEnumerate.Item(i) & "")
  Case "H:" 'Skip Drive
  Case ""
    oNetwork.RemoveNetworkDrive oEnumerate.Item(i+1), True, True
  Case Else
    oNetwork.RemoveNetworkDrive oEnumerate.Item(i), True, True
  End Select
Next

I recycled this from another post a while back. I think it was PHV who initially posted.

Hope This Helps,

Good Luck!
 
Here it is

<code>'==========================================================================
'
' NAME: LogonScript.vbs
'
' AUTHOR: Mark D. MacLachlan, The Spider's Parlor
' URL : ' DATE : 4/10/2003
'
' COMMENT: Enumerates current users' group memberships in given domain.
' Maps and disconnects drives and printers
'
'==========================================================================

ON ERROR RESUME NEXT

Dim WSHShell, WSHNetwork, objDomain, DomainString, UserString, UserObj, Path


Set WSHShell = CreateObject("WScript.Shell")
Set WSHNetwork = CreateObject("WScript.Network")
'Automatically find the domain name
Set objDomain = getObject("LDAP://rootDse")
DomainString = objDomain.Get("dnsHostName")

'Find the Windows Directory
WinDir = WshShell.ExpandEnvironmentStrings("%WinDir%")

'Grab the user name
UserString = WSHNetwork.UserName
'Bind to the user object to get user name and check for group memberships later
Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)

'Grab the computer name for use in add-on code later
strComputer = WSHNetwork.ComputerName


'Disconnect any drive mappings as needed.
'WSHNetwork.RemoveNetworkDrive "F:", True, True

'Disconnect ALL mapped drives except H:
Set clDrives = WshNetwork.EnumNetworkDrives
For i = 0 to clDrives.Count -1 Step 2
If clDrives.Item(i) <> "H:" Then
showIE "",clDrives.Item(i) & " "
WSHNetwork.RemoveNetworkDrive clDrives.Item(i), Force, UpdateProfile
WScript.sleep 100
End If

NEXT

'Give the PC time to do the disconnect, wait 300 milliseconds
wscript.sleep 300

'Map drives needed by all
'Note the first command uses the user name as a variable to map to a user share.
WSHNetwork.MapNetworkDrive "H:", "\\server\" & UserString,True
WSHNetwork.MapNetworkDrive "G:", "\\server",True

'Now check for group memberships and map appropriate drives
'Note that this checks Global Groups and not domain local groups.
For Each GroupObj In UserObj.Groups
'Force upper case comparison of the group names, otherwise this is case sensitive.

Select Case(GroupObj.Name)

Case "_UserGroup"
WSHNetwork.MapNetworkDrive "J:", "\\server",True
WSHNetwork.MapNetworkDrive "V:", "\\server",True
WSHNetwork.AddWindowsPrinterConnection "\\server"


End Select


'Remove ALL old printers
'Enumerate all printers first, after that you can select the printers you want by performing some string checks
'Set WSHPrinters = WSHNetwork.EnumPrinterConnections
'For LOOP_COUNTER = 0 To WSHPrinters.Count - 1 Step 2
'To remove only networked printers use this If Statement
' If Left(WSHPrinters.Item(LOOP_COUNTER +1),2) = "\\" Then
' WSHNetwork.RemovePrinterConnection WSHPrinters.Item(LOOP_COUNTER +1),True,True
' End If
'To remove all printers incuding LOCAL printers use this statement and comment out the If Statement above
'WSHNetwork.RemovePrinterConnection WSHPrinters.Item(LOOP_COUNTER +1),True,True
Next

'Remove a specific printer
'WSHNetwork.RemovePrinterConnection "\\ServerOld\HP5si",True,True

'Install Printers
'WSHNetwork.AddWindowsPrinterConnection "\\Server\HP5si"


'Clean Up Memory We Used
set UserObj = Nothing
set GroupObj = Nothing
set WSHNetwork = Nothing
set DomainString = Nothing
set WSHSHell = Nothing
Set WSHPrinters = Nothing


'Quit the Script
wscript.quit</code>

I have tried entering your code and nothing. I also tried this code to disconnect everything but H

<code>Set clDrives = WshNetwork.EnumNetworkDrives
For i = 0 to clDrives.Count -1 Step 2
If clDrives.Item(i) <> "H:" Then
showIE "",clDrives.Item(i) & " "
WSHNetwork.RemoveNetworkDrive clDrives.Item(i), Force, UpdateProfile
WScript.sleep 100
End If</code>

but didn't work either.

FROGGYJ
A+,N+,CST,CNCT,MCP
 
let me rephrase....it is skipping the H drive, except its actually skipping everyting. If I manually map say a Z drive and then reboot or log off and on, the Z doesn't get disconnected.

FROGGYJ
A+,N+,CST,CNCT,MCP
 
if I look in my computer there are the drives I have in the script listed as "network drive" and then this Z drive I manually mapped is still listed for some reason, but says "disconnected network drive" until you double click it of course, so perhaps the script is doing what I am asking? in reality I want to remove the drive from my computer so it doesn't show up.

FROGGYJ
A+,N+,CST,CNCT,MCP
 
Try turning off error checking just before you go into your drive disconnect. Any errors?

Hope This Helps,

Good Luck!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top