Re: How to do something based on set of workstations by Al
Al
Sun Oct 31 19:43:29 CST 2004
You could avoid the more obvious, and painful set of if statements with case
statements, along these lines:
Set WshNetwork = WScript.CreateObject("WScript.Network")
workstation = ucase( WshNetwork.computername )
select case ucase( workstation )
case "FRED","BARNEY","WILMA","BAMBAM"
' put your "do X" statements here
case "BART","HOMER","LISA"
' put your "do Y" statements here
case default
msgbox "your workstation is not recognized, please contact..."
end select
This is fine if all of the scripting falls into one of the
mutually-exclusive case ranges. But if you need the code to do, for example,
XX for WILMA and LISA and XY for FRED, BARNEY and HOMER, this approach can
still result in more complexity than you might want.
Here is another way this could be done:
Set WshNetwork = WScript.CreateObject("WScript.Network")
callstatement = "call " & ucase( WshNetwork.computername )
executeglobal callstatement
wscript.quit
sub fred
call flintstone_show_tasks
call male_tasks
call adult_tasks
call stupid_person_tasks
end sub
sub marge
call simpson_show_tasks
call female_tasks
call adult_tasks
end sub
sub bart
call simpson_show_tasks
call male_tasks
call kid_tasks
call stupid_person_tasks
end sub
' ... etc.
sub flintstone_show_tasks
' do whatever...
end sub
' ... etc.
In all cases, of course, you have the issue of needing to edit the script to
accommodate new workstations and renamed workstations. If the number of
workstations takes you past a couple of cartoon shows full of character
names, you should probably look at structuring it with a separate data file.
Then the script code itself could remain unchanged, and you'd modify only
the data file, something like:
const ForReading = 1
set fso = wscript.createobject( "scripting.filesystemobject" )
Set WshNetwork = WScript.CreateObject( "WScript.Network" )
extnscriptfolder = fso.getparentfoldername( wscript.scriptfullname )
scriptfile = extnscriptfolder & "\" & ucase( WshNetwork.computername ) &
".vbs"
with fso.opentextfile( scriptfile )
externalscript = .readall
.close
end with
executeglobal externalscript
There would be a number of .vbs files each named for a workstation
containing the vbscript code you wanted executed when the main script was
run on that workstation.
/Al
"Ulf Dornheck Busscher" <ulfdb@web.de> wrote in message
news:eoqfAY5vEHA.2876@TK2MSFTNGP12.phx.gbl...
> Hi Arch,
>
> I'm sure there are many efficent ways to do this ... but first of all ...
> how are these informations specified? (do x with y, ...)
>
> Ulf
>
> Arch Willingham wrote:
> > I want to do something based on the workstation that runs the script.
> > I.E. if is a workstation FRED or BARNEY or WILMA, or BAMBAM I want it
> > to do x, and if it is BART or HORMER or LISA I want it to do y and so
> > on. I could write a ton of if statements but that seems inefficient,
> > is there another way?
>
>