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. ## 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. 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. Thanks working great now (thanks button has disappeared for me atm)

4. Lol, dont worry, nobody ever thanks me

5. 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. 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..

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: