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

    • I can't believe it was only two years since the last time MS raised their prices and now they think they can do it again so soon. Of course they needed to backtrack on this. I hope Nintendo is next.
    • I guess I gotta be even more specific then since I'm looking for an absolute confirmation.  The mini PC has never booted up or powered on by me. I'm assuming it'll be like buying a new PC from a store. Nothing is set up. Like absolutely nothing on the mini PC because I can't emphasize this enough. My USB drive already has Windows set up on it from my other desktop so I know it's clean. So now I connect it to the mini PC before it's even booted up or go to the desktop. I then turn on the mini PC and boot into the USB drive. I should see an existing partition. I'll delete it and then install Windows again over the entire drive. I don't necessarily want to create a separate partition. Once it installs and boots to the desktop, I'm assuming the drive is "clean" and free of any malware/viruses. Basically, this process will eliminate any potential for malware/viruses to still somehow hide in the SSD and then potentially affect me later.  I'm being very anal about this because I really don't trust anything bought from AliExpress, but the price was very tempting.  Is Windows Defender reliable? Afterwards, if I do a full scan and it doesn't find anything in the SSD and the USB drive, can I be confident the mini PC is now safe and secured to enter my banking credentials? If not, what else can I do to be absolutely certain?
    • I got an ESR Qi2 vent charger for my car and it's fantastic. It's very strong magnet and holds the phone securely over the worst potholes/roads, and my iPhone does charge. In Summer, the AC blows on the vent keeps and keeps the phone cold. In winter, I just close that vent, so it still stays cold. I agree with you on the Android front. Why not just build in the magnets like Apple does? It's frustrating to buy a case that adds magnets.
    • Hey, I've been using Windows since I was a little tyke. But for the last 15 years, I have been using Linux. I'm using EndeavourOS/Arch atm. wipe it, as in deleting anything from the SSD in the computer. Make a new partition. USB booting device should be free of malware, as long as you download it directly friom MS. Not some XYZ company.
    • "Nuking it" is slang for doing a clean install. USB installation media... delete the partition... start fresh.
  • Recent Achievements

    • Collaborator
      fernan99 earned a badge
      Collaborator
    • Collaborator
      MikeK13 earned a badge
      Collaborator
    • One Month Later
      Alexander 001 earned a badge
      One Month Later
    • One Month Later
      Antonio Barboza earned a badge
      One Month Later
    • Week One Done
      Antonio Barboza earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      584
    2. 2
      ATLien_0
      219
    3. 3
      Michael Scrip
      173
    4. 4
      Xenon
      138
    5. 5
      +FloatingFatMan
      127
  • Tell a friend

    Love Neowin? Tell a friend!