Have a VB.Net app wherein I am trying to call klist.exe to purge cached Kerberos tickets.
Dim klist As New ProcessStartInfo("C:\Windows\System32\klist.exe")
klist.Arguments = "purge"
Process.Start(klist)
Debugger spits out:
System.ComponentModel.Win32Exception: 'The system cannot find the file specified'
The file clearly exists, and can be run without elevated permissions from a command prompt.
What kind of tomfoolery is this? Or am I so tired I'm missing something obvious?
On a 64bit machine, the files in c:\windows\system32
are 64bit files and the files in c:\windows\SysWOW64
are 32bit files (yeah.. I know what you're going to say). A background redirection in the OS ensures that 32bit programs that try to access c:\windows\system32
are redirected to c:\windows\syswow64
so they can find the 32bit files they think they want out of system32. Given that klist.exe
is in system32 and hence 64bit (for me at least, ymmv), your app not finding it means it's likely it is 32bit and being redirected to the syswow64 folder, which doesn't contain klist.exe. Your console session, on the other hand, doesn't have this bitness problem and is using the system32 folder/finding klist.exe
Set your app to be 64bit; set the Target CPU to x64
or make it AnyCPU and turn off the "Prefer 32bit" tickbox