+ Post New Thread
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
Scripts Thread, Script to run on certain Operating Systems? in Coding and Web Development; Hi, we currently have a login script which is needed for our XP environment but isn't needed for our new ...
  1. #1
    CallumCatterall's Avatar
    Join Date
    Oct 2011
    Location
    United Kingdom
    Posts
    45
    Thank Post
    10
    Thanked 11 Times in 2 Posts
    Rep Power
    7

    Script to run on certain Operating Systems?

    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!
    Last edited by CallumCatterall; 29th November 2011 at 08:43 PM.

  2. #2

    Gatt's Avatar
    Join Date
    Jan 2006
    Posts
    6,660
    Thank Post
    859
    Thanked 646 Times in 429 Posts
    Rep Power
    498
    I used this and its brilliant for logon scripts 0:

    http://www.kixtart.org/

  3. #3

    nephilim's Avatar
    Join Date
    Nov 2008
    Location
    Dunstable
    Posts
    11,925
    Thank Post
    1,626
    Thanked 1,893 Times in 1,407 Posts
    Blog Entries
    2
    Rep Power
    429
    Been a while since I have done VBSCRIPT but this may help!

    Code:
    '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.
    Last edited by nephilim; 29th November 2011 at 08:34 PM.

  4. Thanks to nephilim from:

    CallumCatterall (29th November 2011)

  5. #4

    Gatt's Avatar
    Join Date
    Jan 2006
    Posts
    6,660
    Thank Post
    859
    Thanked 646 Times in 429 Posts
    Rep Power
    498
    D'oh - completely misread the OP

  6. #5

    nephilim's Avatar
    Join Date
    Nov 2008
    Location
    Dunstable
    Posts
    11,925
    Thank Post
    1,626
    Thanked 1,893 Times in 1,407 Posts
    Blog Entries
    2
    Rep Power
    429
    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)

  7. #6
    CallumCatterall's Avatar
    Join Date
    Oct 2011
    Location
    United Kingdom
    Posts
    45
    Thank Post
    10
    Thanked 11 Times in 2 Posts
    Rep Power
    7
    Quote Originally Posted by nephilim View Post
    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!
    Last edited by CallumCatterall; 29th November 2011 at 08:43 PM.

  8. #7

    nephilim's Avatar
    Join Date
    Nov 2008
    Location
    Dunstable
    Posts
    11,925
    Thank Post
    1,626
    Thanked 1,893 Times in 1,407 Posts
    Blog Entries
    2
    Rep Power
    429
    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

  9. #8


    Join Date
    Feb 2007
    Location
    51.403651, -0.515458
    Posts
    8,893
    Thank Post
    226
    Thanked 2,674 Times in 1,971 Posts
    Rep Power
    786
    If you want to check the OS version from within the batch file itself, try this...

    LoginScript.cmd
    Code:
    @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
    )

  10. #9

    plexer's Avatar
    Join Date
    Dec 2005
    Location
    Norfolk
    Posts
    13,610
    Thank Post
    647
    Thanked 1,616 Times in 1,446 Posts
    Rep Power
    421
    Apply a wmi filter to the gpo that runs the script.

    Ben

  11. #10
    CallumCatterall's Avatar
    Join Date
    Oct 2011
    Location
    United Kingdom
    Posts
    45
    Thank Post
    10
    Thanked 11 Times in 2 Posts
    Rep Power
    7
    Quote Originally Posted by plexer View Post
    Apply a wmi filter to the gpo that runs the script.

    Ben
    What would the query be for that?

    Thanks.

  12. #11

    nephilim's Avatar
    Join Date
    Nov 2008
    Location
    Dunstable
    Posts
    11,925
    Thank Post
    1,626
    Thanked 1,893 Times in 1,407 Posts
    Blog Entries
    2
    Rep Power
    429
    That would be done via group policy on your server

  13. #12


    Join Date
    Feb 2007
    Location
    51.403651, -0.515458
    Posts
    8,893
    Thank Post
    226
    Thanked 2,674 Times in 1,971 Posts
    Rep Power
    786
    Code:
    SELECT Version, ProductType from Win32_OperatingSystem WHERE Version LIKE '5.1.%' AND ProductType = '1'
    or

    Code:
    SELECT Version FROM Win32_OperatingSystem WHERE Version < "6"
    ... or you could use GPP.
    Last edited by Arthur; 29th November 2011 at 09:39 PM.

  14. Thanks to Arthur from:

    CallumCatterall (29th November 2011)

  15. #13
    CallumCatterall's Avatar
    Join Date
    Oct 2011
    Location
    United Kingdom
    Posts
    45
    Thank Post
    10
    Thanked 11 Times in 2 Posts
    Rep Power
    7
    Quote Originally Posted by Arthur View Post
    Code:
    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!

  16. #14


    Join Date
    Feb 2007
    Location
    51.403651, -0.515458
    Posts
    8,893
    Thank Post
    226
    Thanked 2,674 Times in 1,971 Posts
    Rep Power
    786
    Yes to both.

  17. #15
    CallumCatterall's Avatar
    Join Date
    Oct 2011
    Location
    United Kingdom
    Posts
    45
    Thank Post
    10
    Thanked 11 Times in 2 Posts
    Rep Power
    7
    Quote Originally Posted by Arthur View Post
    Yes to both.
    Great! Just for future reference, is '5.1.%' the OS type? so if I wanted to create a WMI filter to just go on Windows 7 I would change it to '6.1.%'?
    Thanks.

SHARE:
+ Post New Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. Script to run based on computer name
    By FN-GM in forum Scripts
    Replies: 12
    Last Post: 10th July 2013, 11:39 AM
  2. Replies: 9
    Last Post: 6th October 2010, 03:54 PM
  3. Script to run automaticly
    By Newton in forum Scripts
    Replies: 1
    Last Post: 18th June 2009, 04:24 PM
  4. Replies: 13
    Last Post: 8th November 2007, 02:53 PM
  5. Need a script to run programs
    By timbo343 in forum Scripts
    Replies: 9
    Last Post: 26th September 2007, 12:24 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •