call a batch file based on pc name

Discussion in 'Scripting' started by GC, Nov 24, 2004.

  1. GC

    GC Guest

    Hi,
    Is there any way in a logon script to call a batch file only if the first 2
    letters of the computer name is a certain value? Like for all computers
    starting with SP it'll run a certain script? Thanks!
     
    GC, Nov 24, 2004
    #1
    1. Advertisements

  2. Hi,

    If the logon script is VBScript, you can retrieve the computer name and
    parse the first 2 letters. You can use the Run method of the WshShell object
    to run a batch file.

    Dim objNetwork, strComputer, objShell

    Set objShell = CreateObject("Wscript.Shell")
    Set objNetwork = CreateObject("Wscript.Network")

    ' Retrieve NetBIOS computer name.
    strComputer = objNetwork.ComputerName

    ' Make comparison case insensitive.
    If Left(LCase(strComputer), 2) = "sp" Then
    objShell.Run("%COMSPEC% /c Update.bat")
    End If

    Look up documentation on the Run method. It has parameters to make it wait
    until the program ends before continuing (usually) if that is necessary.

    If you are using a batch file logon script and the clients are at least NT,
    you can parse the COMPUTERNAME environment variable.
     
    Richard Mueller [MVP], Nov 24, 2004
    #2
    1. Advertisements

  3. Likewise Kixtart (http://kixtart.org kixtart is CareWare) can be used to parse the @wksta
    macro.

    Such as...

    left("@wksta",2)

    Dave



    | GC wrote:
    |
    | > Is there any way in a logon script to call a batch file only if the first
    | 2
    | > letters of the computer name is a certain value? Like for all computers
    | > starting with SP it'll run a certain script? Thanks!
    |
    | Hi,
    |
    | If the logon script is VBScript, you can retrieve the computer name and
    | parse the first 2 letters. You can use the Run method of the WshShell object
    | to run a batch file.
    |
    | Dim objNetwork, strComputer, objShell
    |
    | Set objShell = CreateObject("Wscript.Shell")
    | Set objNetwork = CreateObject("Wscript.Network")
    |
    | ' Retrieve NetBIOS computer name.
    | strComputer = objNetwork.ComputerName
    |
    | ' Make comparison case insensitive.
    | If Left(LCase(strComputer), 2) = "sp" Then
    | objShell.Run("%COMSPEC% /c Update.bat")
    | End If
    |
    | Look up documentation on the Run method. It has parameters to make it wait
    | until the program ends before continuing (usually) if that is necessary.
    |
    | If you are using a batch file logon script and the clients are at least NT,
    | you can parse the COMPUTERNAME environment variable.
    |
    | --
    | Richard
    | Microsoft MVP Scripting and ADSI
    | HilltopLab web site - http://www.rlmueller.net
    | --
    |
    |
     
    David H. Lipman, Nov 25, 2004
    #3
  4. GC

    Clay Calvert Guest

    Yes.

    if /i "%computername:~0,2%" EQU "SP" start script

    Clay Calvert

    Replace "W" with "L"
     
    Clay Calvert, Nov 25, 2004
    #4
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.