Page 1 of 1 1
Topic Options
#195328 - 2009-08-06 09:05 PM IF Exist (some service on remote PC?)
itdaddy Offline
Starting to like KiXtart

Registered: 2006-12-19
Posts: 145
Loc: Wisconsin
Hey guys how do I do this
I want to set up a condition to say something like:

IF Exist (some service on a remote PC)
Do this
DO that
ENDIF

I want it to be a service I can check that doesnt take DOMAIN admin rights to be able to check it. Is this possible?

Thanks
I want to see if a machine is up and ping is way to slow I need to know right away if the PC is up and then if it is, go ahead and do this and do that.
_________________________
Robert
A+, CCNA, MCP
Network Admin
Credit Union Wisconsin

Top
#195330 - 2009-08-06 09:17 PM Re: IF Exist (some service on remote PC?) [Re: itdaddy]
eriqjaffe Offline
Hey THIS is FUN

Registered: 2004-06-24
Posts: 214
Loc: Arlington Heights, IL USA
Try the fnWMIService() UDF.
Top
#195331 - 2009-08-06 10:13 PM Re: IF Exist (some service on remote PC?) [Re: eriqjaffe]
itdaddy Offline
Starting to like KiXtart

Registered: 2006-12-19
Posts: 145
Loc: Wisconsin
thanks will do ;\)
_________________________
Robert
A+, CCNA, MCP
Network Admin
Credit Union Wisconsin

Top
#195336 - 2009-08-07 06:41 AM Re: IF Exist (some service on remote PC?) [Re: itdaddy]
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
ping is about the fastest way of detecting life on a remote PC.

Ping it first (WMIPing)
then check for service if necessary
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#195342 - 2009-08-07 01:20 PM Re: IF Exist (some service on remote PC?) [Re: itdaddy]
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Ping is going to be much faster than just about any other method. A reasonable check for local hosts or remote hosts on uncongested links is two ping probes with a two second timeout. That's about three seconds to check if a machine is down with a good chance of getting it right.

Queries like WMI or checking for RPC connectivity will take a fair old time before they timeout.

Top
#195347 - 2009-08-07 05:33 PM Re: IF Exist (some service on remote PC?) [Re: Richard H.]
itdaddy Offline
Starting to like KiXtart

Registered: 2006-12-19
Posts: 145
Loc: Wisconsin
I usually use ping like this:
 Quote:

shell "cmd.exe /c ping \\$Element -n 1 > hide.txt"
IF @ERROR = 0
(do this stuff)
ENDIF


but what happens is it hangs...it keeps trying..and I want it to try and if nothing witin x milliseconds give up and move on. How can I stop it from trying so much..you know ping just keeps trying even when I say ping 1x only. what do you think I can do to stop it from trying so much? maybe a TCP protocol revamp? ahhahaha


Edited by itdaddy (2009-08-07 05:34 PM)
_________________________
Robert
A+, CCNA, MCP
Network Admin
Credit Union Wisconsin

Top
#195348 - 2009-08-07 06:02 PM Re: IF Exist (some service on remote PC?) [Re: itdaddy]
itdaddy Offline
Starting to like KiXtart

Registered: 2006-12-19
Posts: 145
Loc: Wisconsin
Can this vbs be converted to kix?
this is one of the most simple examples (for me )I could find that works..
 Quote:

strMachines = "10.1.1.3"

' you only need to create this object once, so it is put outside the loop
Set objWMI = GetObject("winmgmts:")

bolIsAlive = False ' init value

Do While True
Set objPing = objWMI._
ExecQuery("select * from Win32_PingStatus where address = '" _
& strMachines & "'")

For Each objPingStatus In objPing
If objPingStatus.StatusCode = 0 Then
bolIsAlive = True
Exit For ' no point in continuing the For loop
End If
Next

If bolIsAlive Then
Exit Do ' Exit the "eternal" loop
Else
WScript.Sleep 5000
End If
Loop
'in kix this can go to the console no biggie
WScript.Echo "Its Alive!!!"




_________________________
Robert
A+, CCNA, MCP
Network Admin
Credit Union Wisconsin

Top
#195349 - 2009-08-07 06:13 PM Re: IF Exist (some service on remote PC?) [Re: itdaddy]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
Robert,

If you keep using Shell commands to perform functions that Kix can do, you might as well simply write a batch file.

Before you write another line of code, write yourself a list of available Kix functions that you can reference. You don't need to list them all, but scan them all and make note of the ones you think might be useful. I have mine as the front page of my hardcopy Kix manual.

The entire list of KORG UDFs can be viewed here and then there is my complete development UDF library on my web site.

Study the lists and learn what is available to you. Download and include them in your code - you'd be surprised how much faster the WSHPing is, or how flexible WMI queries can be.

As you compile a library of UDFs, consider looking at KGen, which allows you to reference UDFs in your core script. It will then resolve and include all dependencies to create a finished script.

Couple of other points -
  • Using "cmd.exe" is bad form - use "%COMSPEC%", which is more portable and will always point to the correct interpreter.
  • Don't use double-quotes in Kix, especially in Shell or Run commands. The interpreter usually requires double quotes, so using single quotes within Kix allows you to easily embed double quotes in the command string when needed. (but watch out for message strings with contractions, like "can't"!)
  • It's "ping.exe" - get in the habit of qualifying your commands. This eliminates any confusion between batch files, executables, and other scripts.
You might get other advice, as some of this is programming style, but PICK ONE STYLE and stick to it. You have problems because your code is "all over the place". Define your objectives by commenting your code. Plan the execution and logic by commenting your code. THEN, insert the code based on the comments. Your code will be smoother and less problematic.

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

Top
#195350 - 2009-08-07 06:31 PM Re: IF Exist (some service on remote PC?) [Re: Glenn Barnas]
itdaddy Offline
Starting to like KiXtart

Registered: 2006-12-19
Posts: 145
Loc: Wisconsin
Glenn
you are right....OUCH! but very good points..yeah I need to commit to it
my scripts work but could work better and yeah I am sure much smoother..
thanks for all the tips...you the man! Yeah this is a kix forum and I need to really learn kix and vbscript for that matter. I am trying but I guess I need to step it up a notch! huh? thanks a lot for the tips! I guess it has always worked for me but I can see I need to completely step on the other side....

gulp! swallow! \:\)
_________________________
Robert
A+, CCNA, MCP
Network Admin
Credit Union Wisconsin

Top
#195351 - 2009-08-07 06:40 PM Re: IF Exist (some service on remote PC?) [Re: itdaddy]
itdaddy Offline
Starting to like KiXtart

Registered: 2006-12-19
Posts: 145
Loc: Wisconsin
Glenn,
wow I love that UDF site wow what a gold mine! yeah
will work on my kixtart to get better and use more pure kix
vs my cheesy hybrids! hee hee ;\) thanks for the
admonishment ;\) yeh, you are right to run pure kix
vs the hodge podge of shell and kix..yeah thank you.


wow found this udf; yeah what a gold mine...
 Quote:

$Branch = "pc1", "pc2", "pc3"

For Each $Element in $Branch

Ping($Element, 0)

Next
;FUNCTION Ping($Element)
;
;AUTHOR Jochen Polster (jochenDOTpolsterATgmxDOTnet)
;
;VERSION HISTORY 1.0 - 11/24/2001 Initial Release
; 1.1 - 11/11/2004 Fixed problems regarding spaces in folder names
; of script directory (thanks to Alistair)
; 1.2 - 12/07/2004 Fixed for NoVarsInStrings and Explicit on
;
;ACTION Pings the Computer specified, or returns its ip address (Wins Resolved)
;
;SYNTAX Ping(Computer,GetIP,[LoopCount],[Timeout])
;
;PARAMETERS Computer (Required)
; - String value representing the Computer to ping
;
; GetIp (Required)
; - If specified (1), the function will return the ip-address
; of specified Computer rather than pinging it ...
; Has to be 0 if you want to check for reply !
;
; LoopCount (Optional but useful !)
; - Integer value representing the number of times
; the Computer shall be pinged
;
; Timeout (Optional)
; - if ommited the Computer gets pinged with the default
; timeout (1s) and default retries (4)
;
;REMARKS If there is a reply the function will return immediately with 1
; so it could be faster not specifiying a timeout.
;
;RETURNS 0 - No reply
; 1 - Ping reply
; Optional - ip address of specified Computer
;
;DEPENDENCIES None
;
;EXAMPLES call "path\Ping.udf"
; if Ping("www.microsoft.com",0,12,5000) ;pings for max. 60 seconds
; run "%ComSpec% /c start http://www.microsoft.com"
; else
; 'Site isn't available ' ?
; endif
; if Ping("www.microsoft.com",0,15) ;pings also for max. 60 seconds
; run "%ComSpec% /c start http://www.microsoft.com"
; else
; 'Site isn't available ' ?
; endif
; $ip = Ping("www.microsoft.com",1)
; $ip ?

function Ping($Computer,$GetIP,optional $LoopCount,optional $TimeOut)
if $GetIP
dim $ip, $ipfile, $
$ipfile = @scriptdir + '\ip.txt'
shell '%Comspec% /q /e:1024 /c for /F "tokens=2 delims=[]" %%i IN ('+ chr(39)
+ '"ping ' + $Computer + ' -n 1 | find "]""' + chr(39) + ') do echo %%i >"' + $ipfile + '"'
$ = open(10,$ipfile,2) $ip = readline(10) $ = close(10) del $ipfile
if $ip
$Ping = $ip
else
$Ping = 'Bad IP address ' + $Computer + '!'
endif
exit 0
else
if $TimeOut
for $c = 0 to $LoopCount
shell '%Comspec% /C ping ' + $Computer + ' -n 1 -w ' + $TimeOut + ' | find /C

"TTL=" > nul'
if @error = 0
$Ping = 1
exit 0
endif
next
else
for $c = 0 to $LoopCount
shell '%Comspec% /C ping ' + $Computer + ' | find /C "TTL=" > nul'
if @error = 0
$Ping = 1
exit 0
endif
next
endif
$Ping = 0
endif
endfunction



Edited by itdaddy (2009-08-07 06:48 PM)
_________________________
Robert
A+, CCNA, MCP
Network Admin
Credit Union Wisconsin

Top
#195352 - 2009-08-07 08:19 PM Re: IF Exist (some service on remote PC?) [Re: itdaddy]
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
We all started somewhere and we needed some oldtimers to kick us into stepping up our game...

There are a few Canadians out there that when aren't scripting are wrestling bears and used to use our scripts as litter.


BTB, look for WMIPing()
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#195355 - 2009-08-07 08:28 PM Re: IF Exist (some service on remote PC?) [Re: Radimus]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11631
Loc: CA
Glenn, I get this error from your link. Not sure why you used an HTTPS link.

http://www.innotechcg.com uses an invalid security certificate.

The certificate is not trusted because the issuer certificate is unknown.

(Error code: sec_error_unknown_issuer)

Top
#195357 - 2009-08-07 08:45 PM Re: IF Exist (some service on remote PC?) [Re: Radimus]
itdaddy Offline
Starting to like KiXtart

Registered: 2006-12-19
Posts: 145
Loc: Wisconsin
radimus

tru dat! ;\)
sure will lookingl wmiping()

hey can I set how many times I want it to try pinging. Like in my program
if after say x millisec if nothing there give up! and move on...
I am really looking of a ping() that pings and tries say 1 or 2 times
adn then ends out and moves on...I am trying to perfect this "check if alive" algorithm and if nothing there quit freaking trying and move on to a live body....this would be awesome! thanks

but you said it right step up my game!
_________________________
Robert
A+, CCNA, MCP
Network Admin
Credit Union Wisconsin

Top
#195358 - 2009-08-07 09:04 PM Re: IF Exist (some service on remote PC?) [Re: NTDOC]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
It's not invalid, it's just not in your trusted CA list.

Regardless, I removed the "s", which should remove the issue. I copied the URL from my browser, which (ever since I installed the web mail system) defaults to HTTPS when connecting to my web site.

Thanks for the heads-up.

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

Top
#195359 - 2009-08-07 09:09 PM Re: IF Exist (some service on remote PC?) [Re: itdaddy]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
The Ping UDF on my site allows you to specify the number of pings. If you specify 10 pings and it replies after the first try, it returns immediately, otherwise it keeps trying until it gets a reply or the number of permitted attempts are exceeded.

If you Ping(host,10) it pings the host, but if you Ping(host,-1) it returns the IP address of the host if it can be resolved, kind of like a NSLookup. It supports an optional 3rd arg to define the ping timeout. It uses WSH and the standard O/S ping.exe.

See also the KFPing() UDF, which runs with KixForms.

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

Top
#195360 - 2009-08-07 11:36 PM Re: IF Exist (some service on remote PC?) [Re: Glenn Barnas]
itdaddy Offline
Starting to like KiXtart

Registered: 2006-12-19
Posts: 145
Loc: Wisconsin
super thank you ;))))
_________________________
Robert
A+, CCNA, MCP
Network Admin
Credit Union Wisconsin

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 764 anonymous users online.
Newest Members
ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder, M_Moore
17887 Registered Users

Generated in 0.124 seconds in which 0.099 seconds were spent on a total of 13 queries. Zlib compression enabled.

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