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.
  • Posts

    • Get Microsoft Office 2021 Professional for Windows, now only $44.97 by Steven Parker Get all these essential Microsoft apps for your Windows PC Today's highlighted deal comes via our Apps + Software section of the Neowin Deals store, where you can score a lifetime license to Microsoft Office 2021 for Windows for only $44.97 (buying link below). This bundle is for families and small businesses who want classic Office apps and email. It includes Word, Excel, PowerPoint, Outlook, Teams, and OneNote. A one-time purchase installed on 1 Windows PC for use at home or work. Lifetime license for MS Word, Excel, PowerPoint, Outlook, Teams, & OneNote One-time purchase installed on 1 Windows PC for use at home or work Instant Delivery & Download – access your software license keys and download links instantly Free customer service – only the best support! Microsoft Office Professional 2021 (for Windows) includes: Microsoft Office Word Microsoft Office Excel Microsoft Office PowerPoint Microsoft Office Outlook Microsoft Office Teams Microsoft Office OneNote Microsoft Office Publisher Microsoft Office Access No faffing about with subscriptions, just classic apps that don't expire.Good to Know ONE-TIME PURCHASE INSTALLED ON 1 DEVICE Redemption deadline: redeem your code within 30 days of purchase Access options: desktop Full versions No subscriptions – no monthly/annual fees Version: 2021 Updates included A lifetime subscription to Microsoft Office 2021 Professional normally costs $219.99, but this deal can be yours for just $49.97, that's a saving of $180. For full terms, specifications, and license info, click the link below. Use MSO5 coupon for an additional $5 off. Expires June 29. Get Microsoft Office Professional 2021 deal for just $44.97, or learn more Although priced in U.S. dollars, this deal is available for digital purchase worldwide. We post these because we earn commission on each sale so as not to rely solely on advertising, which many of our readers block. It all helps toward paying staff reporters, servers and hosting costs. Other ways to support Neowin Whitelist Neowin by not blocking our ads Create a free member account to see fewer ads Make a donation to support our day to day running costs Subscribe to Neowin - for $14 a year, or $28 a year for an ad-free experience Disclosure: Neowin benefits from revenue of each sale made through our branded deals site powered by StackCommerce.
    • This is a common misnomer that Intel refuses to correct, E-Cores the E doesn't stand for efficiency in power (although they are more efficient than performance cores) but are actually "space efficient" which means they occupy much less space for same computational power thus allowing more of them in a footprint.
    • If you have top secret documents from the government or your company, you will not use a user cloud service. Pete Hegseth would like a word. I doubt that security fiasco stops at Signal. Stop being so stupid that you think that your useless information on your PC is as important as you think it is. This is just another crude way of saying it shouldn't matter if have nothing to hide. Not everyone wants to become a product, but you do you. If you cared about the content, you would not use these documents and photos on Android and iPhone phones because the telemetry there is 100,000% worse than on Windows 11. I love the telemetry comment. You cannot prove one way or another if it's better or worse on Windows vs. iOS or Android.
  • Recent Achievements

    • Reacting Well
      Cole Multipass earned a badge
      Reacting Well
    • Reacting Well
      JLP earned a badge
      Reacting Well
    • Week One Done
      Rhydderch earned a badge
      Week One Done
    • Experienced
      dismuter went up a rank
      Experienced
    • One Month Later
      mevinyavin earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      693
    2. 2
      ATLien_0
      273
    3. 3
      Michael Scrip
      218
    4. 4
      +FloatingFatMan
      188
    5. 5
      Steven P.
      146
  • Tell a friend

    Love Neowin? Tell a friend!