Page 1 of 1 1
Topic Options
#159847 - 2006-03-27 04:56 PM Using an array?
Stephen Wintle Offline
Seasoned Scripter

Registered: 2001-04-10
Posts: 444
Loc: England
Hi,

Could anyone give me some pointers on using an array to push out the following command
Code:
 Run "Beyondexecv2 \\" + $wrkid + " -d LockWorkstation -l 0" 


Where $wrkid is passed the netbios name (this works ok), we have approx 32 machines for my array. So I want to repeat the command for every machine name.

Regards

Steve.
_________________________
Dont worry because a rival imitates you. As long as they follow in your tracks they cant pass you!

Top
#159848 - 2006-03-27 05:31 PM Re: Using an array?
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
Assuming that you already know how to get the workstation name into an array....

Code:
For each $wkstn in $arry
Run "Beyondexecv2 \\" + $wrkid + " -d LockWorkstation -l 0"
Next

_________________________
Today is the tomorrow you worried about yesterday.

Top
#159849 - 2006-03-27 07:27 PM Re: Using an array?
eriqjaffe Offline
Hey THIS is FUN

Registered: 2004-06-24
Posts: 214
Loc: Arlington Heights, IL USA
Quote:

Assuming that you already know how to get the workstation name into an array....

Code:
For each $wkstn in $arry
Run "Beyondexecv2 \\" + $wrkid + " -d LockWorkstation -l 0"
Next






Shouldn't that be:

Code:
For each $wrkid in $arry
Run "Beyondexecv2 \\" + $wrkid + " -d LockWorkstation -l 0"
Next


Top
#159850 - 2006-03-27 07:46 PM Re: Using an array?
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
You are correct, not enough coffee is my only excuse...
_________________________
Today is the tomorrow you worried about yesterday.

Top
#159851 - 2006-03-28 10:10 AM Re: Using an array?
Stephen Wintle Offline
Seasoned Scripter

Registered: 2001-04-10
Posts: 444
Loc: England
Ok thanks,
If I have machines numbered LT-01 to LT-32 how might I incorporate this into my array?

Regards

Steve.
_________________________
Dont worry because a rival imitates you. As long as they follow in your tracks they cant pass you!

Top
#159852 - 2006-03-28 10:26 AM Re: Using an array?
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: CA
Create a file with the names of the Computers you want to run it against.
This code does not include code to verify the system is on or reachable.


Code:

$Computers = ReadFile(@ScriptDir+'\'+'computers.txt')
For each $Computer in $Computers
If $Computer
$Computer = Trim($Computer)
Run "Beyondexecv2 \\" + $Computer + " -d LockWorkstation -l 0"
EndIf
Next
 

Function ReadFile($file)
Dim $lf, $f, $_, $t
$lf=CHR(10)
$f=FreeFileHandle
$_=Open($f,$file)
If @ERROR Exit @ERROR EndIf
Do $t=$t+$lf+ReadLine($f) Until @ERROR
$_=Close($f)
$ReadFile=Split(SubStr($t,2),$lf)
EndFunction


Top
#159853 - 2006-03-28 11:09 AM Re: Using an array?
Björn Offline
Korg Regular
*****

Registered: 2005-12-07
Posts: 953
Loc: Stockholm, Sweden.
can't you just do
Code:

$arry = "comp1","comp2","comp3","etc"


if you don't have em in a specific file?
(or did I just make a fool out of myself now?


Edited by ewook (2006-03-28 12:32 PM)
_________________________
as long as it works - why fix it?
If it doesn't work - kix-it!

Top
#159854 - 2006-03-28 12:08 PM Re: Using an array?
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: CA
Yes you can do it that way, but you need quotes around the string.

The ReadFile UDF though is better for larger lists.

Top
#159855 - 2006-03-28 12:46 PM Re: Using an array?
Stephen Wintle Offline
Seasoned Scripter

Registered: 2001-04-10
Posts: 444
Loc: England
Ok,

Should the computer.txt script have machines names with breaklines so that each machine in in a column or do I seperate by comma?

regards

Steve.

Top
#159856 - 2006-03-28 01:16 PM Re: Using an array?
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: CA
1 computer name per line with CRLF after each name

computer01
computer02
computer03
etc...

Top
#159857 - 2006-03-28 01:28 PM Re: Using an array?
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
If you separate them with a command you could read the entire line at once and you would have your array.
If each computer is on a separate line you could do something like this:

Code:

$rc = Open (1, "c:\pcnamefile.txt", 2)
$line = ReadLine (1)
While @ERROR = "0"
$array = $array + $line + ","
$line = ReadLine (1)
Loop
$rc = Close(1)

_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#159858 - 2006-03-28 02:43 PM Re: Using an array?
Stephen Wintle Offline
Seasoned Scripter

Registered: 2001-04-10
Posts: 444
Loc: England
Hi,
Thanks for replies, works fine!
_________________________
Dont worry because a rival imitates you. As long as they follow in your tracks they cant pass you!

Top
#159859 - 2006-03-28 08:26 PM Re: Using an array?
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
Quote:


If I have machines numbered LT-01 to LT-32 how might I incorporate this into my array?




I know you've completed this, but...
If your computers are truly named in this fashion, why use an array at all?
Code:
 For $ID - 1 to 32
Run "Beyondexecv2 \\LT-" + Right('0' + Str($ID), 2) + " -d LockWorkstation -l 0"
Next



Of course, this only works if your computer names have sequential numbers as you indicated.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#159860 - 2006-03-28 10:45 PM Re: Using an array?
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: CA
ROFL - You guys crack me up. Yes there are a ton of methods to skin a cat (so to speak).
Top
#159861 - 2006-03-29 02:43 AM Re: Using an array?
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
Well, you guys are always golfing things down..

Sometimes I wonder about that whole forest / trees thing though...

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#159862 - 2006-03-29 08:03 AM Re: Using an array?
Björn Offline
Korg Regular
*****

Registered: 2005-12-07
Posts: 953
Loc: Stockholm, Sweden.
Quote:


Code:
 For $ID - 1 to 32
Run "Beyondexecv2 \\LT-" + Right('0' + Str($ID), 2) + " -d LockWorkstation -l 0"
Next







Hah! That would be the most code and space efficient way =)
_________________________
as long as it works - why fix it?
If it doesn't work - kix-it!

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 661 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.069 seconds in which 0.025 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org