We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Logon Script Help - VBS

sparkis
sparkis asked
on
Medium Priority
285 Views
Last Modified: 2012-05-11
I am having an impossible time here. We added two new printers. I need to uninstall the two old printers Canon1 and Canon2

And then let the logon script install the two new "Server Room Ricoh Copier" and "Ricoh Color Back Office"

I cannot figure this out, but the logon script does not seem to be working at all. All I did was change the share names. Assuming the Old ones would be removed. Can someone please help me out with this?

I attached the script. It does seem to be working at all. Not mapping drives or fixing the printers?

Please help!

Thanks,

2011.vbs
Comment
Watch Question

Neil RussellTechnical Development Lead

Commented:
Why use a script?  If you are on 2008 server then Use Group Policy Preferences and the Print Server Role. Simples.
Neil RussellTechnical Development Lead

Commented:
Also ALL of your drive mappings could be done using Group Policies too. Much cleaner and simpler.

Author

Commented:
What about mapping drives?
I have not problem using GP to push out Printers - But then do I still need the script for the Drives? And if so, Can you help me edit the current one down?

Author

Commented:
how do you do that?
GlobaLevelProgrammer

Commented:
....you have the experts above...but honestly..I have always had problems with using vbs to switch drives:

strDriveLetter1 = "G:"
strDriveLetter2 = "S:"
strDriveLetter3 = "T:"
strDriveLetter4 = "U:"

It tends to run the first fine..then hangs...I would write 4 separate programs... or use WMI..windows Manangement Instruments...

this has a couple examples to see how it looks..plenty on the internet..
http://motevich.blogspot.com/2007/11/execute-program-on-remote-computer.html

WMI and Printer Tasks:
http://msdn.microsoft.com/en-us/library/aa394598(v=vs.85).aspx

also if you do a google on "wmi remote printer"...TONS!
GlobaLevelProgrammer

Commented:
...opps let me restate..I have had issues using objNetwork.MapNetworkDrive to switch drives..however WMI / VBScript was great..

Author

Commented:
Ok - willing to try the GPO route -

 So I see where I can deploy printers. That I added in User Config / Windows Settings.
Now I see whre I can add the logon script for to map the drives.

My only question since most machines already have the drives mapped via the logon script - will this cause a conflict - assuming I remove the logon script?

And how do I remove the old printers that are still mapped but no longer exist?

Author

Commented:
GlobalLevel - I am not having any issue with the mapped drives in my logon script. I am having an issue with the printers only

Wanted to have the script remove all network printers, and then install the following on the list.

I posted the script if you can take a look.

Thanks SJMP

Author

Commented:
well taking care of the printers via GPO was extraordinarily easy. And it worked.

So I still need a hand removing two printers via the current logon script.

can someone help me with some scipting expertise.

I want to remove \\server\Canon1 and \\server\Canon2

Author

Commented:
Would this work as a .vbs that I put in logons for GPO


Set objNetwork = CreateObject("WScript.Network")
objNetwork.MapNetworkDrive "G:", "\\server\Data"
objNetwork.MapNetworkDrive "S:", "\\server\Shared"
objNetwork.MapNetworkDrive "T:", "\\server\Gead"
objNetwork.MapNetworkDrive "U:", "\\server\test"
Technical Development Lead
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview

Author

Commented:
My script above worked. I just want to make sure that previously mapped printers that no longer exist, will no longer be there. I guess I can confirm further by testing.

Author

Commented:
Guys - I spoke to soon. the script is not working for my users. Any reason based on the script itself?

Option Explicit
On Error Resume Next

Set objNetwork = CreateObject("WScript.Network")
objNetwork.MapNetworkDrive "G:", "\\fs02\Data"
objNetwork.MapNetworkDrive "S:", "\\fs02\Shared"
objNetwork.MapNetworkDrive "T:", "\\server1\Dead"
objNetwork.MapNetworkDrive "U:", "\\server1\Portfolio"

Wscript.Quit
Neil RussellTechnical Development Lead

Commented:
In the time it took you to ask the question you could have configured a New Group poilicy to do all of the network disk mapping for you :P

Like i said....

http://www.msserveradmin.com/using-group-policy-prefernces-to-map-drives/ 

Author

Commented:
ok thanks. I will look into this.

But back to my original questions. How can I add to the script to remove two networked printers names. Printer 1 and Printer 2?

Thanks,

SJMP

Just want to add it to below:
Set objNetwork = CreateObject("WScript.Network")
objNetwork.MapNetworkDrive "G:", "\\server\Data"
objNetwork.MapNetworkDrive "S:", "\\server\Shared"
objNetwork.MapNetworkDrive "T:", "\\server\Gead"
objNetwork.MapNetworkDrive "U:", "\\server\test"

Author

Commented:
Can I just add this to the script?

Set WshNetwork = WScript.CreateObject("WScript.Network")
PrinterPath = "\\printserv\printer1"
WshNetwork.RemovePrinterConnection PrinterPath, true, true
PrinterPath = "\\printserv\printer2"
WshNetwork.RemovePrinterConnection PrinterPath, true, true

Set objNetwork = CreateObject("WScript.Network")
objNetwork.MapNetworkDrive "G:", "\\server\Data"
objNetwork.MapNetworkDrive "S:", "\\server\Shared"
objNetwork.MapNetworkDrive "T:", "\\server\Gead"
objNetwork.MapNetworkDrive "U:", "\\server\test"
Neil RussellTechnical Development Lead

Commented:
From memory removeprinterconnectin has all sorts of problems trying to remove 'stale' network printers. I.e. ones that no longer exist.  If you have changed the share name and are now trying to remove them, this could be an issue.

Author

Commented:
The printers themselves are gone. The Canon's were replaced with Ricoh's.

I just want to remove the two.
GlobaLevelProgrammer

Commented:
If your going the vb route...have you tried running two separate scripts one for each printer?
Neil RussellTechnical Development Lead

Commented:
OK, have a read of this long thread here, should solve your removal problem one way or the other,

https://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_24040284.html

Author

Commented:
did not address logon script but gave decent alternative.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.