Avatar of Mohamed Abdelmawla
Mohamed Abdelmawla
 asked on

Prevent a VBS script from running on servers

Hello Everyone,

I have a VBScript that I use as a GPO logon script for users, I need to prevent the script from running on server in the event of one of the users logs in to a server. So I just need help writing an IF statement that determines the OS version and run it on Windows 7 or Windows 10 only.

Thanks in advance.
VB ScriptWindows OSScripting Languages

Avatar of undefined
Last Comment
slightwv (䄆 Netminder)

8/22/2022 - Mon

You can use this
systeminfo | findstr /C:"OS Name:"

Open in new window

slightwv (䄆 Netminder)

Start here:

Then look up additional Members in the Win32_OperatingSystem class:

I think what you want is:

    Data type: uint32
    Access type: Read-only

    Additional system information.

    Work Station (1)
    Domain Controller (2)
    Server (3)

Putting it together:
strComputer = "." 
Set objWMIService = GetObject("winmgmts:" _ 
 & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 
Set colOSes = objWMIService.ExecQuery("Select * from Win32_OperatingSystem") 
For Each objOS in colOSes 
  Wscript.Echo "Prduct Type: " & objOS.ProductType 

Open in new window


I would handle this with a new GPO and move the logon script to this new GPO.
From there I would leverage WMI filtering.
Here are two screenshots that highlight what I am talking about.

Your help has saved me hundreds of hours of internet surfing.
Ben Personick (Previously QCubed)

I would just put a simple exclusion in by using item level targeting, or put a simple WMI filter in place and have the GPO use that WMI filter for where it applies.

You can use server name, or group membership, or OS to makw the exclusion directly in the group policy.

  of course you can put it in your script as well, whichever you prefer.
Ben Personick (Previously QCubed)

@ Yo Bee,  I am on mobile, and when I wrote that 4 hours ago, there was no posr by you, it just posted now. phpht.

in any case you saidwhat I came to say, and included screenshots I couldn't while mobile, so I certainly defer to you and would edit my post to note you dorectly if I could but, I'm on mobile.

have good mosh pitting.😃


1: Please take the time to read previous replies before posting any of your suggestion. This will avoid any duplicative suggestion.  
2: GPP will not work here since the asker has a Logon Script and not applying a GPP.
3: The asker never mentioned what his script does. He just asked how to exclude it from running is the user logs onto a server.
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Ben Personick (Previously QCubed)

@yo bee,

  Please see above.


I was typing my reply before you posted your second comment.
That makes sense now.  Sorry if I offended you in anyway.
David Johnson, CD

View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Mohamed Abdelmawla

@David Johnson

Thanks a lot, that's exactly what I want :)
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
slightwv (䄆 Netminder)

>>Thanks a lot, that's exactly what I want :)

And pretty much what was posted 4 hours before?
David Johnson, CD

@netminder all your script does is display the product type. My answer goes one step further and checks if the product type is 1 which is a non-server OS
slightwv (䄆 Netminder)

I understand you added the additional IF statement.

I figured the OP had a certain level of knowledge and only needed to figure out how to determine if the script was running on a Workstation or not.

ProductType was the hard part.  IF statements should be simple.

If you want the points for an IF statement, enjoy.
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.