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!

Yet Another Logon Script Question 3

Status
Not open for further replies.

HessA

MIS
Mar 17, 2005
176
US
I have Markdmac's logon script edited for my use and I love it. However there are at least 2 things right now I would like to add.

How do I add a line to map a user's home directory as H: drive in Vbscript?

Is there a way to choose which printer that is connected via the logon script becomes the default? (at the moment whichever printer I have set to connect first is the one that becomes the default)

Thanks in advance,

Aaron

 
Okay, so here's what I did, I may have deleted some of the scripts needed, but I didn't want some of the scripts running that you had in your template.

Here is the modified one I kept

'==========================================================================
'
' 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")

'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)

If Ucase(UserString) = "seanj" Then
WSHNetwork.MapNetworkDrive "L:", "\\server4\" & UserString,True
WSHNetwork.MapNetworkDrive "M:", "\\server4\Employee\" & UserString,True
WSHNetwork.MapNetworkDrive "N:", "\\Server4\Corporate Information System\" & UserString,True
WSHNetwork.MapNetworkDrive "P:", "\\Server4\Temp Share\" & UserString,True
WSHNetwork.MapNetworkDrive "Q:", "\\Server4\Programs\" & UserString,True

End If



'Add On Code goes below this line
'=====================================



'=====================================
'Add On Code goes above this line

'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

And I'm sure you'll find it easily, but the script is not executing for my user account.

Appreciate it
 
try changing this:
If Ucase(UserString) = "seanj" Then

to this:
If Ucase(UserString) = "[red]SEANJ[/red]" Then

You don't need these lines since you are not using them:
'Bind to the user object to get user name and check for group memberships later
Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)


I hope you find this post helpful.

Regards,

Mark
 
No go, Changed the Uname to caps (I assumed the Ucase was to counter act any case-sensativity)

Still just a login, no mapped drives
 
What happens if you take out the if then with your username and just run the script from your desktop does it map the drives then?

Aaron
 
An excellent suggestion. Additionally I would add a line before the mappings that says

Wscript.Echo UserString

You should get a pop up with information on who the script thinks you are. That might help identify the issue.

I hope you find this post helpful.

Regards,

Mark
 
Wasn't paying attention here on my end, my fault.

The & UserString was the problem, as none of the Dir's have employee files, except for one, which often the username isn't the same as the file name


Corrected it, and it works, appreciate the help/template.
 
question is,

do you know of any software that will scan all my folders in my drive structure and send them to an image for easy viewing. I suppose like a visio style image.

Cheers in advance
 
David I don't mind that your post is in the thread that started. However for a quicker Answer you may want to start a new thread and maybe put Markdmac in the subject. He has always responded to me quickly with very good help I might add. But since it's a different subject it might get buried in this thread and never read.

Aaron
 
David, I would agree, this thread has kind of been hijacked here.

It would be a fairly easy task to script this to give a textual report of all of the folders and sub folders, but a graphical representation would be more difficult.

Here is a script I have for reporting folder sizes. Should get you on your way.

If you need a graphical layout you might want to post a new thread to see if anyone has any other ideas.

Code:
'==========================================================================
'
' NAME: <filename>
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL: [URL unfurl="true"]http://www.thespidersparlor.com[/URL]
' DATE  : 12/23/2003
'
' COMMENT: <comment>
'
'==========================================================================

'Check all subfolders below given folder for size over a minimum size.
Dim FolderPath
Dim FolderSize
Dim MinSize

Set objArgs=WScript.Arguments
FolderPath=objArgs(0)
MinSize=CLng(objArgs(1)) 

Const CONVERSION_FACTOR = 1048576 'converts folder size to MB
'Const MinSize = 100 'set minimum folder size in MB.
If Wscript.Arguments.count = 0 Then
    Wscript.Echo "Usage: foldersize.vbs [folder][minimum size]"
    Wscript.Echo "Example: foldersize.vbs c:\myfolder 50"
    Wscript.Quit
End If

'FolderPath = Wscript.Arguments(0)
'MinSize = Wscript.Arguments(1)
report = "Folder Size" & vbTab &"Folder Name" & vbCrLf
Set FSO = CreateObject ("Scripting.FileSystemObject")
ShowSubFolders FSO.GetFolder(FolderPath)
MsgBox Report
Sub ShowSubFolders (Folder)
    For Each SubFolder In Folder.SubFolders 
    FolderSize = SubFolder.Size / CONVERSION_FACTOR
        If FolderSize >  MinSize Then
            report = report & int(FolderSize) & vbTab & vbTab & SubFolder.Path & vbCrLf
        End If
        ShowSubFolders SubFolder
    Next

End Sub

I hope you find this post helpful.

Regards,

Mark
 
No need to be sorry David. I wasn't bitching about you hijacking the thread I was genuinely concerned that you get an answer for your question and because it was buried so deep in this thread I thought maybe it would get missed.

Aaron
 
cool

chat to you later and thanks for concern, i understand what you mean.

Ragards
David
 
Hate to beat a dead horse...but this is striking me as odd.

Working with group policies, I created a small map login script using your template.

I tested this on a group that contained like 5 users, and it executed fine.

After verifying it worked, I changed the group to be one that would include a majority of the AD users, and it won't execute.

Here is the script.

'==========================================================================
'
' 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")


UserString = WSHNetwork.UserName
Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)


For Each GroupObj In UserObj.Groups
Select Case GroupObj.Name

Case "Employees"
WSHNetwork.MapNetworkDrive "M:", "\\server4\Employee",True
WSHNetwork.MapNetworkDrive "N:", "\\server4\Programs",True
WSHNetwork.MapNetworkDrive "P:", "\\server4\Corporate Information System",True
WSHNetwork.MapNetworkDrive "R:", "\\server4\Departments",True
WSHNetwork.MapNetworkDrive "T:", "\\server4\Temp Share",True

End Select

Next

'Add On Code goes below this line
'=====================================



'=====================================
'Add On Code goes above this line

'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


Any advice is appreciated.
 
Personally I don't know VBscript as well as I would like. Without Markdmac I'd still be in .bat file land. But the first thing I would confirm is security is all good. I am sure these are existing shares you already have the security done on. But for one group to work and not another I would double check it.

Probably little help but what the hell,

Aaron
 
What I'm trying to figure out, is if I execute the script on the local box, it goes fine, but as a domain policy, no response.
 
Yeah all the testing I have done thus far is based on a my account and group membership and I put that account as well as my computer account in a OU I setup for testing. I am applying my policy against the OU I setup for testing and so far everything runs fine. I setup blocking of all the majoy IM programs earlier this morning and I will be duplicating that on the Default Domain Policy later. When I do if I have any issues I may be in the same boat as you.

Aaron
 
Can you possibly email me a sample of your current script?

Realistically I've tried two other VBS scripts that are designed for network drive mapping, and neither are working, which is indicating a problem with the AD to me.
 
HEre you go I only editedd out the actual server names and share names but the rest is as I use it.

' 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.
'
'==========================================================================


ON ERROR RESUME NEXT

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


Set WSHShell = CreateObject("WScript.Shell")
Set WSHNetwork = CreateObject("WScript.Network")
Set objDomain = getObject("LDAP://rootDse")
DomainString = objDomain.Get("dnsHostName")

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

'Synchronizes the time with Server our NTP Server
WSHShell.Run "NET TIME \\servername /set /y"


'Disconnect ALL mapped drives
Set clDrives = WshNetwork.EnumNetworkDrives
For i = 0 to clDrives.Count -1 Step 2
WSHNetwork.RemoveNetworkDrive clDrives.Item(i), True, True
Next

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

'Map drives needed by all
WSHNetwork.MapNetworkDrive "U:", "\\servername\sharename",True
WSHNetwork.MapNetworkDrive "w:", "\\servername\sharename",True
WSHNetwork.MapNetworkDrive "H:", "\\servername\sharename" & UserString,True

'Now check for group memberships and map appropriate drives
For Each GroupObj In UserObj.Groups
Select Case GroupObj.Name
'Check for group memberships and take needed action
'In this example below, ADMIN and WORKERB are groups.
Case "Domain Admins"
WSHNetwork.MapNetworkDrive "m:", "\\servername\sharename",True
'Case "WorkerB"
'WSHNetwork.MapNetworkDrive "w:", "\\servername\sharename",True
WSHNetwork.SetDefaultPrinter "\\servername\sharename"
End Select
Next

'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 "\\servername\printername"
WSHNetwork.AddWindowsPrinterConnection "\\servername\printername"
WSHNetwork.AddWindowsPrinterConnection "\\servername\printername"
WSHNetwork.SetDefaultPrinter "\\servername\printername"

' This section of script will prevent the baloon window that appears when printing
' to a network shared printer after XP Service Pack 2 is installed.
'=====================================

Path = "HKCU\Printers\Settings\EnableBalloonNotificationsRemote"
WshShell.RegWrite Path, 0 ,"REG_DWORD"

'Configure the PC to show the Windows Version and Service Pack
'as an overlay to the desktop above the System Tray
'=====================================
HKEY_CURRENT_USER = &H80000001
strComputer = WSHNetwork.Computername
Set objReg = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
strKeyPath = "Control Panel\Desktop"
objReg.CreateKey HKEY_CURRENT_USER, strKeyPath
ValueName = "PaintDesktopVersion"
dwValue = 1
objReg.SetDWORDValue HKEY_CURRENT_USER, strKeyPath, ValueName, dwValue

' This Add On demonstates the Microsoft Speach API (SAPI)
'=====================================
Dim oVo
Set oVo = Wscript.CreateObject("SAPI.SpVoice")
oVo.speak "Good Morning " & WSHNetwork.username

' This code will empty the Temp Internet Files on Exit
'=====================================
Dim tempiepath
tempiepath = "HKCU\Software\Microsoft\Windows\"

WSHShell.RegWrite tempiepath & "ShellNoRoam\MUICache\@inetcplc.dll,-4750","Empty Temporary Internet Files folder when browser is closed","REG_SZ"

WSHShell.RegWrite tempiepath & "CurrentVersion\Internet Settings\Cache\Persistent","0","REG_DWORD"
Set tempiepath = nothing

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

Call WSHShell.Run("cmd.exe /C \\server\folder\folder\folder\scan32.exe")

'Quit the Script
wscript.quit

Hope it helps (I left Markdmac's name on it as without him for me this script would not be runing)

See if this helps at all,
Aaron
 
Okay so I totally think that the script isn't being enforced.

Basically I've created about 5 or 6 different variations of the script, and tested locally, on both the server and any box.

The scripts all point to the AD to check permissions, then execute an if then or a case...and locally every single one of them works.

So let me verify I'm enforcing it properly here.

I simply went to the AD, right click on domain controller, properties...from there I go down to User Config, Windows settings, scripts, login, and then put the file in the default dir, add it, and okay back until I've closed out all the stuff.

I never have a script "parameters" set, just the script file...

So frustrating
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top