Windows 2008 Logon Script - VBS

I have a windows logon script been using it for a few year. Can someone please take a look at it. This is what I want it to do
1 - all mapped drives should be removed and mapped according to the new information in the script. I am moving all mapped data to a new server this weekend.
2 - it never uninstalls the printers from \\OLDPRINTSERVER - what is wrong here. The new printer connections work fine.

I have attached the .txt that we use in the script. It is basically simple.
Step 1 - remove and mapped drives
step 2 - mapp drive
step 3 - remove any network printers
step 4 - add network printers.

I dont have a problem with the drive mapping or adding the network printers. I just want to make sure when I migrate my file server from fs01 to fs02 (and will update the script using the same drive letters) that it doesnt cause a conflict.

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hi sparkis

I think your issue with the removing of the printers is because on that perticular line it reads:

WSHNetwork.RemovePrinterConnection WSHPrinters.Item(LOOP_COUNTER +1),True,True

Note the highlighted WSHNetwork! this is not SET to CreateObject("Wscript.Network") anywhere in the script, however at the very top you have set-up:

Dim WSHNet

Set WSHNet = CreateObject("Wscript.Network")

Should the remove printer line read:

WSHNet.RemovePrinterConnection WSHPrinters.Item(LOOP_COUNTER +1),True,True

Also another thing to note is how many times you SET something to CreateObject("Wscript.Netwrok"), you really only need one of these at the very top then it can be used all the way through the script.

Hope this helps


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sparkisAuthor Commented:
Everything else looks good?

The script will remove the network mapped drives and replace them with the info provided?

I have amended the code to do the disconnecting of mapped drives, the code you had didn't have this in. I've also cleaned it up a bit for you.

Option Explicit
On Error Resume Next

Dim strDriveLetter1, strDriveLetter2, strDriveLetter3, strDriveLetter4
Dim strRemotePath1, strRemotePath2, strRemotePath3, strRemotePath4
Dim bForce, bUpdateProfile

Set objNetwork = CreateObject("Wscript.Network")

strDriveLetter1 = "G:" 
strDriveLetter2 = "S:"
strDriveLetter3 = "T:"
strDriveLetter4 = "U:"
bForce = "True"
bUpdateProfile = "True"

objNetwork.RemoveNetworkDrive strDriveLetter1, bForce, bUpdateProfile
objNetwork.RemoveNetworkDrive strDriveLetter2, bForce, bUpdateProfile
objNetwork.RemoveNetworkDrive strDriveLetter3, bForce, bUpdateProfile
objNetwork.RemoveNetworkDrive strDriveLetter4, bForce, bUpdateProfile

strRemotePath1 = "\\fs\Data" 
strRemotePath2 = "\\fs01\Shared" 
strRemotePath3 = "\\fs01\Dead" 
strRemotePath4 = "\\fs01\Portfolio" 

' Section which maps, G: S: T: and U:
objNetwork.MapNetworkDrive strDriveLetter1, strRemotePath1
objNetwork.MapNetworkDrive strDriveLetter2, strRemotePath2
objNetwork.MapNetworkDrive strDriveLetter3, strRemotePath3
objNetwork.MapNetworkDrive strDriveLetter4, strRemotePath4

'Remove ALL old printers
'Enumerate all printers first, after that you can select the printers you want by performing some string checks
Set WSHPrinters = objNetwork.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) = "\\OLDPRINTSERVER" Then
		objNetwork.RemovePrinterConnection WSHPrinters.Item(LOOP_COUNTER +1),True,True
	End If

objNetwork.AddWindowsPrinterConnection "\\printserver\Dprinter"
objNetwork.AddWindowsPrinterConnection "\\printserver\JPrint"
objNetwork.AddWindowsPrinterConnection "\\printserver\Bprint"
objNetwork.AddWindowsPrinterConnection "\\printserver\Sprint"
objNetwork.AddWindowsPrinterConnection "\\printserver\Server Room Canon Copier"
objNetwork.AddWindowsPrinterConnection "\\printserver\Canon Color File Room"
objNetwork.AddWindowsPrinterConnection "\\printserver\Server Room HP Printer"
objNetwork.AddWindowsPrinterConnection "\\printserver\Canon Color Back Office"


Open in new window

sparkisAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.