From: Neil on
I'm desperately trying to automate KList(in the resource kit) to purge
kerberos tickets and for the life of me I can't figure out how

I have this:-

Set objShell = WScript.CreateObject("WScript.Shell")
Set objExecObject = objShell.Exec("%comspec% /c klist.exe purge")

Do Until objExecObject.StdOut.AtEndOfStream
strLine = objExecObject.StdOut.ReadLine()
wscript.echo strLine
strIP = Instr(strLine,"Purge")
If strIP <> 0 Then
wscript.echo strLine
objExecObject.StdIn.Write "y"
End If
Loop


And it just doesn't work. I've tried Sendkeys and that doesn't work either.

Can anyone help me?
From: mr_unreliable on
hi Neil,

Offhand, I don't see anything wrong, but this is
tricky business. Can you say exactly where your
script goes bad?

I suspect that in the following snippet, you might
try removing the "WScript.Echo" line, as it may be
"discombobulating" the input stream:

If strIP <> 0 Then
wscript.echo strLine <= try removing this stmt
objExecObject.StdIn.Write "y"
End If

Also, try stopping the script after you find a "purge"
line, and see if typing in the "y" manually (without
using the stdin) will work.

cheers, jw
____________________________________________________________

You got questions? WE GOT ANSWERS!!! ..(but, no guarantee
the answers will be applicable to the questions)


Neil wrote:
> I'm desperately trying to automate KList(in the resource kit) to purge
> kerberos tickets and for the life of me I can't figure out how
>
> I have this:-
>
> Set objShell = WScript.CreateObject("WScript.Shell")
> Set objExecObject = objShell.Exec("%comspec% /c klist.exe purge")
>
> Do Until objExecObject.StdOut.AtEndOfStream
> strLine = objExecObject.StdOut.ReadLine()
> wscript.echo strLine
> strIP = Instr(strLine,"Purge")
> If strIP <> 0 Then
> wscript.echo strLine
> objExecObject.StdIn.Write "y"
> End If
> Loop
>
>
> And it just doesn't work. I've tried Sendkeys and that doesn't work
> either.
>
> Can anyone help me?
From: Tom Lavedas on
On Feb 26, 2:17 pm, mr_unreliable <kindlyReplyToNewsgr...(a)notmail.com>
wrote:
> hi Neil,
>
> Offhand, I don't see anything wrong, but this is
> tricky business.  Can you say exactly where your
> script goes bad?
>
> I suspect that in the following snippet, you might
> try removing the "WScript.Echo" line, as it may be
> "discombobulating" the input stream:
>
>     If strIP <> 0 Then
>       wscript.echo strLine  <= try removing this stmt
>       objExecObject.StdIn.Write "y"
>     End If
>
> Also, try stopping the script after you find a "purge"
> line, and see if typing in the "y" manually (without
> using the stdin) will work.
>
> cheers, jw
> ____________________________________________________________
>
> You got questions?  WE GOT ANSWERS!!!  ..(but, no guarantee
>     the answers will be applicable to the questions)
>
> Neil wrote:
> > I'm desperately trying to automate KList(in the resource kit) to purge
> > kerberos tickets and for the life of me I can't figure out how
>
> > I have this:-
>
> > Set objShell = WScript.CreateObject("WScript.Shell")
> > Set objExecObject = objShell.Exec("%comspec% /c klist.exe purge")
>
> > Do Until objExecObject.StdOut.AtEndOfStream
> >  strLine = objExecObject.StdOut.ReadLine()
> > wscript.echo strLine
> >  strIP = Instr(strLine,"Purge")
> >  If strIP <> 0 Then
> >     wscript.echo strLine
> >      objExecObject.StdIn.Write "y"
> >  End If
> > Loop
>
> > And it just doesn't work.  I've tried Sendkeys and that doesn't work
> > either.
>
> > Can anyone help me?

I'd try staying away from the whole Exec thing, as I have had nothing
but troubles with trying that sort of thing. If the klist program
needs a confirming "Y", I'd try this instead ...

nRes = objShell.Run("%comspec% /c echo.Y| klist.exe purge", o, true)
wsh.echo nRes

If nRes returns 0, then all worked as expected. Any other number
means it failed. It may fail, if klist doesn't accept piped input
from StdIn. I just don't know the klist program, so I can't say one
way or the other.
__________________
Tom Lavedas
From: Neil on

> nRes = objShell.Run("%comspec% /c echo.Y| klist.exe purge", o, true)
> wsh.echo nRes
>


Tom

I went with Exec as I need to loop through stdout as there may be more
than one 'y' to send.



jw - thanks - I'll give it a try
From: Neil on
On 26/02/2010 15:43, Neil wrote:
> I'm desperately trying to automate KList(in the resource kit) to purge
> kerberos tickets and for the life of me I can't figure out how


I gave up with Exec and did this:


Set objShell = CreateObject("WScript.Shell")
Set objWMIService =
GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")

PurgeKerberosTickets

Sub PurgeKerberosTickets
objShell.run ("klist.exe purge")
wscript.sleep 500
Do While IsKListRunning
objShell.SendKeys "y"
wscript.sleep 100
Loop
wscript.quit
End Sub


Function IsKListRunning
Set colProcesses = objWMIService.ExecQuery("SELECT * FROM Win32_Process
WHERE Name = 'klist.exe'")
If colProcesses.Count = 0 then
IsKListRunning = FALSE
Else
IsKListRunning = TRUE
End If
End function


I know everyone hates SendKeys, but it works *now* which is good enough
for me! Thanks for the input!