Page 1 of 1 1
Topic Options
#116937 - 2004-03-26 11:18 PM Stripping lines and chars from an array
Little_John Offline
Fresh Scripter

Registered: 2004-03-23
Posts: 12
Well, from my previous post (regarding finding user names and resolving them to host and IP) I delve deeper into the maddness.

Code:

$=RedirectOutput("error.txt")

$nFndID=insert username here

$nView=WshPipe('net view')
If @ERROR Exit @ERROR EndIf
For Each $nCPU In $nView
Join(Split($nCPU,"\"),"") = $nHost
$nHost

$nUser=WshPipe('nbtstat -a' +$nHost+' ""',1)
If InStr($nUser, $nFndId)
$nfnd=Split($nUser, "")
For Each $aFnd In $nfnd
If InStr($nfnd, $nFndId)
blah, blah, blah...



I know, know...it's a meager start (very meager), but cut me some slack I'm a newbie(thank you very much). So here's what happens...I'm running a 'net view' from a cmd line and putting the output into $nView then I'm creating a variable on the fly called $nCPU (I know, OPTION EXPLICIT ON, but still). What I'm attempting after that is what has me stumpped. I'm trying to remove the "\\" from the front of the computer name and then call that $nHost so I can do an nbtstat -a on it, but it keeps failing. Here's what my error.txt file says...

[not code]
Server Name Remark

-------------------------------------------------------------------------------
\\ID6042
\\ID6495
The command completed successfully.

0

[/not code] couldn't resist---hehe

It's all that space I don't know what to do with, and the dashes, and why is $nHost = 0.

HELP OH GREAT ONES, FOR I'VE LOST MY WAY. Not really, I've just got no clue what I'm doing.
Thanks in advance.
_________________________
I don't know SH!$, so don't ask me questions and I won't have to lie to you.

Top
#116938 - 2004-03-26 11:57 PM Re: Stripping lines and chars from an array
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Well, if you have a string that looks like... \\ID6042 and you want it to look like this... ID6042 you could do this...

Code:

If InStr($nCPU,"\\")
$nHost = Split(Split($nCPU," ")[0],"\\")[1]
EndIf



Top
#116939 - 2004-03-27 12:53 AM Re: Stripping lines and chars from an array
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4403
Loc: New Jersey
I have a simple UDF to either insure that a system name has the leading/trailing slashes, or doesn't. If you use this, you'd want to specify the REVERSE flag to remove the slashes.

Glenn


Code:

Function SNVerify($System, Optional $Reverse)

; start by stripping all '\' characters
$SNVerify = Join(Split($System, '\'), '', 3)

; add leading & trailing slashes if needed
$SNVerify = IIf(Not $Reverse And $SNVerify <> '', '\\' + $SNVerify + '\', $SNVerify)

Exit 0

EndFunction

_________________________
Actually I am a Rocket Scientist! \:D

Top
#116940 - 2004-03-29 08:15 PM Re: Stripping lines and chars from an array
Little_John Offline
Fresh Scripter

Registered: 2004-03-23
Posts: 12
Great, thanks. Will that bypass the first few lines and go straight to the CPU names or do I still need to strip those.

Server Name Remark

-------------------------------------------------------------------------------
\\ID6042
\\ID6495


The server name remark line the spaces and the dash line. Do I use a read line to jump to line 5 or whatever, or how would I do it?
_________________________
I don't know SH!$, so don't ask me questions and I won't have to lie to you.

Top
#116941 - 2004-03-29 08:18 PM Re: Stripping lines and chars from an array
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Did you try my example within your For...Each...Next loop?
Top
#116942 - 2004-03-29 08:20 PM Re: Stripping lines and chars from an array
Little_John Offline
Fresh Scripter

Registered: 2004-03-23
Posts: 12
Quote:

Did you try my example within your For...Each...Next loop?




What example. This post or the other?
_________________________
I don't know SH!$, so don't ask me questions and I won't have to lie to you.

Top
#116943 - 2004-03-29 08:29 PM Re: Stripping lines and chars from an array
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
This post.

Better example...

Code:

$nView=WshPipe('net view')
For Each $nCPU In $nView
If InStr($nCPU,"\\")
$nHost = Split(Split($nCPU," ")[0],"\\")[1]
$nHost ?
EndIf
Next



Edited by Chris S. (2004-03-29 08:33 PM)

Top
#116944 - 2004-03-30 03:28 PM Re: Stripping lines and chars from an array
Little_John Offline
Fresh Scripter

Registered: 2004-03-23
Posts: 12
Yes, I did add that, but I think I like the this new example better, seems a bit more clear to my befuddled mind.
About the other question...will this skip the dashed line and the other b.s. at the top of the text doc, or do I need a readline statement?
Sorry to be a pest, but I'm out of the office and only have limited access to the net. Also, being that I'm away from my beloved LAN I'm not able to continue testing. Thanks for your patience.
_________________________
I don't know SH!$, so don't ask me questions and I won't have to lie to you.

Top
#116945 - 2004-03-30 03:56 PM Re: Stripping lines and chars from an array
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
I have a few UDFs in the forum to do much of this..

see ReadFile() and FilterArray()

use readfile() to read the file into an array
use filterarray() to return lines with '\\'
then do a for each loop with elements of the array
and then joinsplit them on '\'
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#116946 - 2004-03-31 10:21 PM Re: Stripping lines and chars from an array
Little_John Offline
Fresh Scripter

Registered: 2004-03-23
Posts: 12
Thanks for all the help folks. I'll try this again when I'm back on my LAN.

Thanks again.

Little John
_________________________
I don't know SH!$, so don't ask me questions and I won't have to lie to you.

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 1046 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.077 seconds in which 0.048 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