Jump to content
EduGeek EdSec 2026 is Go! 27th Oct in Derby! Join us for a day of EdTech security focused talks, networking, and an evening social ×

Recommended Posts

Posted (edited)

Hi, we currently have a login script which is needed for our XP environment but isn't needed for our new Windows 7 machines, is there a way to only run the script if the machine is XP? The script is a login script that is a .cmd that runs an application on logon if that helps?

 

Thanks!

Edited by CallumCatterall
Posted (edited)

Been a while since I have done VBSCRIPT but this may help!

 

'OS is Windows XP
'with at least SP2 or higher
If InStr(strOSLongName, "XP") > 0 _
       And intSPMajorVersion >= 2 _
' Do load up script here
dim shell
set shell=createobject("wscript.shell")
shell.run "batchfile.bat"
set shell=nothing
End If 

 

This will work when running W7 and XP and it will slot nicely in. If it doesn't find Windows XP, it won't run the batch file (tested on my home network)

 

*edit*

 

Replace "batchfile.bat" with the location and name of your batch file.

Edited by featured_spectre
  • Thanks 1
Posted (edited)
Not to worry, my vbscript should slot nicely in and in theory have no issues (tried on my home network of an xp laptop, my w7 laptop and windows server 2k8r2)

Wow! Thanks for the speedy reply, shall test it tomorrow.

Thanks again!

Edited by CallumCatterall
Posted

Not to worry, if it doesn't work let me know. Like I said it works fine on my home network (of a couple of machines) so how well it will do on a large scale I don't know.

 

And as for the speediness..thats what we are known for :D

Posted

If you want to check the OS version from within the batch file itself, try this...

 

LoginScript.cmd

@echo off
:: Get Windows version numbers
FOR /f "tokens=2 delims=[]" %%G IN ('ver') DO (Set VERSION=%%G)
FOR /f "tokens=2,3,4 delims=. " %%G IN ('ECHO %VERSION%') DO (Set MAJOR=%%G& Set MINOR=%%H& Set BUILD=%%I) 

IF "%MAJOR%" GEQ "6" (
  :: If OS is Vista/7 or newer do this...
  GOTO :EOF
) ELSE (
  :: If OS is NOT Vista/7 (i.e. XP) do this...
  START "" %SystemRoot%\System32\Calc.exe
)

Posted (edited)

SELECT Version, ProductType from Win32_OperatingSystem WHERE Version LIKE '5.1.%' AND ProductType = '1'

 

or

 

SELECT Version FROM Win32_OperatingSystem WHERE Version < "6"

 

... or you could use GPP. :)

Edited by Arthur
  • Thanks 1
Posted
SELECT Version, ProductType from Win32_OperatingSystem WHERE Version LIKE '5.1.%' AND ProductType = '1'

 

... or you could use GPP. :)

Thanks, so just paste that in the WMI query box and all should be good? And this is so it'll just run on XP?

 

Thanks again!

Posted
Correct. Windows 7 is "6.1.%", but if for example you wanted to specifically target Windows 7 with SP1 you would replace the % symbol with the actual build number i.e. "6.1.7601"
  • Thanks 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...