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.

Thanks.
2011.txt
sparkisAsked:
Who is Participating?
 
jawa29Commented:
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

Jawa29
0
 
sparkisAuthor Commented:
Everything else looks good?

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

0
 
jawa29Commented:
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.

Jawa29
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
Next

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"

Wscript.Quit

Open in new window

0
 
sparkisAuthor Commented:
thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.