+ Post New Thread
Results 1 to 6 of 6
Scripts Thread, Script to call another based on machine name in Coding and Web Development; Hey all, I've a question on how it could be made that a script .vbs or .bat that runs on ...
  1. #1
    originofsymmetry's Avatar
    Join Date
    Jun 2007
    Posts
    186
    Thank Post
    9
    Thanked 14 Times in 11 Posts
    Rep Power
    17

    Script to call another based on machine name

    Hey all, I've a question on how it could be made that a script .vbs or .bat that runs on longon, checks the name of the computer and based on that calls another script. I think this can be done along with the custom start menu .adm file i found on this site ages ago (sorry can't give credit) to map an appropiate start menu to the user. This drive can then be hidden using Hidecalc and with a slight modification to the .adm it creates restrict it to. this means that all shortcuts can be stored on the server without the common problem of users being able to browse the network throught double clicking. I assume some case statements may be made but I've no idea how to piece such a script together. Any help would be greeatly appreciated.

  2. #2

    Join Date
    Nov 2007
    Location
    Preston
    Posts
    98
    Thank Post
    2
    Thanked 4 Times in 4 Posts
    Rep Power
    14
    IF %COMPUTERNAME%==ITROOM1-01 GOTO IT1
    IF %COMPUTERNAME%==ITROOM2-01 GOTO IT2

    :IT1
    call \\server1\netlogon\it1.bat
    :IT2
    call \\server1\netlogon\it2.bat


    etc etc, you get the jist

    %computername% is an environment variable, you can do echo %computername% in cmd.exe to see how it works.

  3. #3
    originofsymmetry's Avatar
    Join Date
    Jun 2007
    Posts
    186
    Thank Post
    9
    Thanked 14 Times in 11 Posts
    Rep Power
    17
    Thanks working great now (thanks button has disappeared for me atm)

  4. #4

    Join Date
    Nov 2007
    Location
    Preston
    Posts
    98
    Thank Post
    2
    Thanked 4 Times in 4 Posts
    Rep Power
    14
    Lol, dont worry, nobody ever thanks me

  5. #5

    Join Date
    Mar 2008
    Location
    Norfolk
    Posts
    227
    Thank Post
    5
    Thanked 10 Times in 8 Posts
    Rep Power
    20

    Cool

    Oldish thread i know, but this tickled my fancy. I wondered if you could do a wildcard type thing with this to test against multiple computers without having to list each one in the script - so the script runs a command for all
    ICT1-xx computers, but not ICT2-xx computers, for example.

    Turns out wildcards aren't supported, but a work around is possible as long as you have a specific and regular naming system for your suites:

    Code:
    set part_name_ict1=%computername:~0,3%1%computername:~4,3%
    set part_name_ict2=%computername:~0,3%2%computername:~4,3%
    
    if %part_name_ict1%==%computername% goto test1
    if %part_name_ict2%==%computername% goto test2
    goto broke
    
    :test1
    echo It works! ICT1 set
    goto end
    
    :test2
    echo It works! ICT set!
    goto end
    
    :broke
    echo broke!
    goto end
    
    :end
    exit
    For example computer name ICT1-01, the set commands pick out the first three characters (ICT) and the last three characters (-01), and fasten them together with a digit specified in the code specific to that variable.
    So, part_name_ict1 would generate ICT1-01, but part_name_ict2 would generate ICT2-01.

    The script goes on to compare the constructed part_name variables against the actual computer name, redirecting accordingly. This can then be used to run specific commands for individual rooms, without having to have multiple different scripts. You could do all this through setting logon scripts in group policy, i realise, or using Kixtart, but maybe someone can find a use for this!

  6. #6
    Unvalidated User
    Join Date
    Nov 2007
    Location
    the Pub
    Posts
    255
    Thank Post
    7
    Thanked 11 Times in 10 Posts
    Rep Power
    0
    May be of interest, - also useful stuff you can do in vb (I wish I could do everything in batch files but they are not poweful enough). I setup printer, add shortcuts etc..

    ie quick script to jump to other vb in case statement..

    Here I have capitalised the characters of the machine name, and then used the first 3 characters to make case checks. Useful for setting up whole rooms, as I name machines with with room-machine# ie. R13-01 R13-02

    Dim wshshell,
    On Error Resume Next
    Set wshshell = WScript.CreateObject("WScript.Shell")
    Select Case Left(Ucase(wshnet.ComputerName),3)
    Case "R16" ie. (all machines in Room 16)
    setup_r16
    Case "LIB"
    setup_Library
    End Select

SHARE:
+ Post New Thread

Similar Threads

  1. Call Parents/Truancy Call
    By webman in forum MIS Systems
    Replies: 8
    Last Post: 7th March 2009, 06:10 PM
  2. Redirected desktop based on machine
    By Jobos in forum Windows
    Replies: 8
    Last Post: 15th June 2007, 11:18 AM
  3. Last call for interest
    By GrumbleDook in forum Courses and Training
    Replies: 0
    Last Post: 20th March 2007, 11:47 AM
  4. Call Logging
    By garibaldi in forum General Chat
    Replies: 5
    Last Post: 13th March 2006, 10:18 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
  •