Recommended Posts

I need to create a script that is basically mapping drives and printers. However there is one PC (a terminal server) which I do not want to map printers to as client's already have printer redirection enabled on their TS Clients.

I have a vbscript which currently specifies

WSHNetwork.AddWindowsPrinterConnection "\\USR-SV001\PR001"
WSHNetwork.AddWindowsPrinterConnection "\\USR-SV001\PR002"
WSHNetwork.AddWindowsPrinterConnection "\\USR-SV001\PR003"

I need something that will baslically do

IF COMPUTERNAME = USR-TS001 THEN

  GOTO END

ELSE

WSHNetwork.AddWindowsPrinterConnection "\\USR-SV001\PR001"
WSHNetwork.AddWindowsPrinterConnection "\\USR-SV001\PR002"
WSHNetwork.AddWindowsPrinterConnection "\\USR-SV001\PR003"

END

I have seen example scripts for batch files but I would sooner be using a vbscript.

I am far from being any use at coding. Any help would highly appreciated.

Link to comment
https://www.neowin.net/forum/topic/624009-vbscript-if-computername-then/
Share on other sites

does this help?

Dim obj
 set obj = CreateObject("Wscript.Network")

wscript.echo obj.ComputerName 'for testing

If obj.ComputerName = "USR-TS001" Then
	'do nothing
Else
	WSHNetwork.AddWindowsPrinterConnection "\\USR-SV001\PR001"
	WSHNetwork.AddWindowsPrinterConnection "\\USR-SV001\PR002"
	WSHNetwork.AddWindowsPrinterConnection "\\USR-SV001\PR003"
End if

the machine name test does seem to be case sensitive too, so you might want to sort that, i.e.

ucase(obj.ComputerName)

Edited by BGM

Dim objNet
Set objNet = CreateObject("WScript.NetWork")

If objNet.ComputerName <> "USR-TS001" Then
	WSHNetwork.AddWindowsPrinterConnection "\\USR-SV001\PR001"
	WSHNetwork.AddWindowsPrinterConnection "\\USR-SV001\PR002"
	WSHNetwork.AddWindowsPrinterConnection "\\USR-SV001\PR003"
End If

I don't know how you declared WSHNetwork, but if it's the same as objNet, you can just use WSHNetwork.ComputerName and get rid of the objNet object.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.