Advertisement

05.05.2008 at 11:56AM PDT, ID: 23377325
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

Capture output of ktpass.exe using VBScript - objShell.Exec("ktpass /?") not working
Tags: vbscript
I am trying to have a vbscript call KTPass.exe  (Kerberos Keytab utility part of support tools). I would like to capture this output and save it to a log file for future reference.

While the vbscript function I use works fine for logging the output of "dir" and other commands, it does not seem to log the output of ktpass.

logExec "dir"              -> Yields output in file
LogExec "cmd /c dir" -> Yields output in file
LogExec "ktpass /?" -> Yields Nothing
LogExec "cmd /c ktpass /?" -> Yields Nothing

LogExec "test.bat" (which just calls ktpass) -> Yields "ktpass /?" and thats it.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
Sub logExec(strCommand)
   dim objShell, objExecObject, strOutput
   Set objshell = wscript.creatobject("wscript.shell")
   Set objExecObject = objShell.Exec(strCommand)
   Do Until objExecObject.Stdout.AtEndOfStream
      strOutput = objExecObject.Stdout.ReadLine()
      wrtielog(strOutput)
      WScript.Echo strOutput
   loop
end sub
Start your free trial to view this solution
Question Stats
Zone: Programming
Question Asked By: Amadork
Solution Provided By: RobSampson
Participating Experts: 1
Solution Grade: B
Views: 12
Translate:
Loading Advertisement...
05.05.2008 at 12:13PM PDT, ID: 21502244

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.05.2008 at 02:30PM PDT, ID: 21503187

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.05.2008 at 07:09PM PDT, ID: 21504322

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.05.2008 at 09:21PM PDT, ID: 21504736

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.06.2008 at 06:49PM PDT, ID: 21512576

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.06.2008 at 07:46PM PDT, ID: 21512834

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
Microsoft
  • Internet Protocols
  • Applications
  • Development
  • OS
  • Hardware
  • Windows Security
Apple
  • Operating Systems
  • Hardware
  • Programming
  • Networking
  • Software
Internet
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Spy / Ad Blockers
  • Web Browsers
  • New Net Users
  • Web Development
  • Chat / IM
  • Anti Spam
  • Web Servers
  • Anti-Virus
  • Email Clients
Gamers
  • Tips
  • Online / MMORPG
  • Puzzle
  • Emulators
  • Action / Adventure
  • Role Playing
  • Consoles
  • Game Programming
  • Strategy
  • Sports
  • Misc
  • Computer Games
Digital Living
  • Hardware
  • New Net Users
  • New Users
  • Software
  • Digital Music
  • Gaming World
  • Home Security
  • Apple
  • Networking Hardware
Virus & Spyware
  • Vulnerabilities
  • IDS
  • Encryption
  • Anti-Virus
  • Operating Systems Security
  • Software Firewalls
  • WebApplications
  • Cell Phones
  • Operating Systems
  • Internet
  • Hardware Firewalls
Hardware
  • Handhelds / PDAs
  • Displays / Monitors
  • Components
  • Networking Hardware
  • Peripherals
  • Laptops/Notebooks
  • Storage
  • Servers
  • Desktops
  • New Users
  • Misc
  • Apple
Software
  • System Utilities
  • Industry Specific
  • Network Management
  • Photos / Graphics
  • Page Layout
  • VMWare
  • Misc
  • Web Development
  • OS
  • CYGWIN
  • Voice Recognition
  • Message Queue
  • Quality Assurance
  • Security
  • Firewalls
  • MultiMedia Applications
  • Development
  • Database
  • Office / Productivity
  • Business Management
  • OS/2 Apps
  • Server Software
  • Internet / Email
ITPro
  • OS
  • Storage
  • Encryption
  • Operating Systems Security
  • Apple Hardware
  • Laptops & Notebooks
  • Servers
  • Networking Hardware
  • Peripherals
  • Devices
  • Displays / Monitors
  • WebTrends / Stats
  • Search Engines
  • Firewalls
  • WebApplications
  • IDS
  • Vulnerabilities
  • Email Clients
  • File Sharing
  • Spy / Ad Blockers
  • Web Browsers
  • Web Servers
  • Networking
  • Anti-Virus
  • Chat / IM
  • Anti Spam
Developer
  • Web Servers
  • Web Browsers
  • Game Programming
  • Dev Tools
  • Industry Specific
  • Office / Productivity
  • Database
  • CYGWIN
  • Web Development
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Programming
  • Content Management
  • Application Servers
  • Protocols
Storage
  • Removable Backup Media
  • Storage Technology
  • Servers
  • Grid
  • Remote Access
  • Backup / Restore
  • Misc
  • Hard Drives
OS
  • Miscellaneous
  • Security
  • Development
  • Linux
  • VMWare
  • MainFrame OS
  • Unix
  • Apple
  • OS / 2
  • AS / 400
  • BeOS
  • Microsoft
  • VMS / OpenVMS
Database
  • Oracle
  • Miscellaneous
  • MySQL
  • Software
  • Sybase
  • Contact Management
  • PostgreSQL
  • Data Manipulation
  • Clarion
  • InterSystems Cache
  • Siebel
  • MUMPS
  • OLAP
  • SQLBase
  • SAS
  • GIS & GPS
  • 4GL
  • Berkeley DB
  • DB2
  • Informix
  • Interbase / Firebird
  • FoxPro
  • Reporting
  • LDAP
  • Filemaker Pro
  • MS SQL Server
  • dBase
  • MS Access
Security
  • Misc
  • Web Browsers
  • Software Firewalls
  • Operating Systems Security
  • File Sharing
  • Spy / Ad Blockers
  • Vulnerabilities
  • WebApplications
  • IDS
  • Anti-Virus
  • Encryption
  • Anti Spam
  • Email Clients
  • VPN
  • Chat / IM
Programming
  • Editors IDEs
  • Installation
  • Handhelds / PDAs
  • Multimedia Programming
  • System / Kernel
  • Algorithms
  • Game
  • Signal Processing
  • Project Management
  • Open Source
  • Database
  • Misc
  • Languages
  • Processor Platforms
  • Theory
Web Development
  • Scripting
  • Blogs
  • Web Servers
  • Software
  • Search Engines
  • Web Graphics
  • Images
  • Internet Marketing
  • Images and Photos
  • Components
  • Document Imaging
  • Web Languages/Standards
  • Illustration
  • WebApplications
  • Fonts
  • WebTrends / Stats
  • Authoring
  • Digital Camera Software
  • Miscellaneous
Networking
  • Protocols
  • Apple Networking
  • Network Management
  • Message Queue
  • Application Servers
  • Content Management
  • File Servers
  • Email Servers
  • Misc
  • Java Editors & IDEs
  • Wireless
  • Networking Hardware
  • Backup / Restore
  • System Utilities
  • ISPs & Hosting
  • Web Servers
  • Storage Technology
  • Removable Backup Media
  • Servers
  • Broadband
  • Grid
  • OS / 2
  • Novell Netware
  • Unix Networking
  • Windows Networking
  • Security
  • Telecommunications
  • Operating Systems
  • Linux Networking
Other
  • Community Advisor
  • Lounge
  • Community Support
  • New Net Users
  • Philosophy / Religion
  • Math / Science
  • Miscellaneous
  • URLs
  • Expert Lounge
  • Politics
  • Puzzles / Riddles
Community Support
  • Suggestions
  • New to EE
  • New Topics
  • Community Advisor
  • CleanUp
  • Announcements
  • General
  • Feedback
  • Input
  • EE Bugs
 
05.05.2008 at 12:13PM PDT, ID: 21502244
Worth noting:
ktpass /? > output.txt

Does not redirect the ktpass output to a file, but instead outputs to the screen and creates a blank text file.

Also, ktpass can be downloaded here:
http://www.microsoft.com/downloads/details.aspx?FamilyId=6EC50B78-8BE1-4E81-B3BE-4E7AC4F0912D&displaylang=en
 
05.05.2008 at 02:30PM PDT, ID: 21503187

Rank: Genius

Hi, I  haven't tried this (can't test it yet), but try reading from the output file that it should redirect to if you pass just
cmd /c ktpass /?
or
ktpass /?

the new sub I've created will automatically output to file, using Run instead of Exec.

Regards,

Rob.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
Sub logExecToFile(strCommand)
   dim objShell, objExecObject, strOutput, objFSO
   Const intForReading = 1
   Set objFSO = CreateObject("Scripting.FileSystemObject")
   Set objshell = CreatObject("wscript.shell")
   strOutput = "myFile.txt"
   objShell.Run strCommand & " > " & strOutput, 1, True
   Set objFile = objFSO.OpenTextFile(strOutput, intForReading, False)
   strContents = objFile.ReadAll
   objFile.Close
   Set objFile = Nothing
   MsgBox strContents
end Sub
Open in New Window
 
05.05.2008 at 07:09PM PDT, ID: 21504322
Tried it, didn't appear to work. It had the same basic issue as all the other redirect methods.

When run it appears to bypass the output that is redirected output and shows to the screen anyway. Its like instead of going to stdout that can be redirected it has something hard coded to ouput to the screen.
 
05.05.2008 at 09:21PM PDT, ID: 21504736

Rank: Genius

I'm sorry. No matter what I've tried, I have been unable to gather the output from KTPass.  There might be more sophisticated ways by using Windows APIs from Office VBA, but I'm not sure....

Rob.
 
05.06.2008 at 06:49PM PDT, ID: 21512576
Ok, backup plan then.

How about the following work around:
1) Run ktpass in another window (cmd /k ktpass /?)
2) Select the window and copy the text.
3) Past the copied text into a file
4) Close the window

or if the above can't be done the following:
1) Run ktpass in another window (cmd /k ktpass /?)
2) Screenshot the dos window.
3) Save the screenshot to file.

I know theoretically this stuff can be done with VB and sendkeys... but I've never used sendkeys before.
 
05.06.2008 at 07:46PM PDT, ID: 21512834

Rank: Genius

OK, here's a bit of a process, but try it out....

Download the WSHExtend ActiveX control from here:
Instructions: http://freenet-homepage.de/gborn/WSHBazaar/WSHExtend.htm
Direct link: http://freenet-homepage.de/gborn/WSHBazaar/WSHExtOcx211.zip

Copy the WinExtend.ocx file to your C:\Windows\System32 folder, and register it by running
regsvr32 WinExtend.ocx

Now, create one script file, called Script2.vbs, with this code in it:

'==============
Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
strKTPass = "c:\Program Files\Support Tools\ktpass.exe"
strKTPass = objFSO.GetFile(strKTPass).ShortPath
strCommand = "cmd /k " & strKTPass & " /?"
objShell.Run strCommand, 1, False
'==============

That script runs KTPass.

Then, paste the code below into another VBS file with any name you like. This is your parent file.

It will call Script2, find the CMD window's process ID, copy the text to a text file, and close the CMD window.

All this is a bit hopeful, I hate using SendKeys, but it seems our only option!

Regards,

Rob.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
Set wshExt = CreateObject("WSHExtend.WinExt")
lngProcessID = wshExt.WSHShell("wscript """ & Replace(Wscript.ScriptFullName, WScript.ScriptName, "") & "Script2.vbs""", 1)
 
strComputer = "."
lngCmdProcess = 0
 
strOutputFile = Replace(Wscript.ScriptFullName, WScript.ScriptName, "") & "Result.txt"
 
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Do
	Set colItems = objWMIService.ExecQuery("SELECT ProcessID FROM Win32_Process WHERE ParentProcessID=" & lngProcessID & " AND Name='cmd.exe'", "WQL", _
	                                    wbemFlagReturnImmediately + wbemFlagForwardOnly)
	For Each objItem In colItems
		lngCmdProcess = objItem.ProcessID
	Next
Loop Until lngCmdProcess > 0
'MsgBox lngProcessID
' Wait for the DOS window to become active
'intCount = 0
'Do
'	intCount = intCount + 1
'	' CHANGE THE intCount VALUE IF YOU REQUIRE MORE Time
'	If intCount = 10000 Then
'		MsgBox lngCmdProcess & " could not be found"
'		Exit Do	
'	End If
'Loop Until wshExt.WSHAppActivate(lngCmdProcess) = 0	
'wshExt.WSHSendKeys "(% )", True
wshExt.WSHWait 100
wshExt.WSHAppActivate(lngCmdProcess)
wshExt.WSHSendKeys "ES", True
wshExt.WSHAppActivate(lngCmdProcess)
wshExt.WSHSendKeys "(% )", True
wshExt.WSHAppActivate(lngCmdProcess)
wshExt.WSHSendKeys "ES", True
wshExt.WSHAppActivate(lngCmdProcess)
wshExt.WSHSendKeys "{ENTER}", True
wshExt.WSHWait 50
wshExt.WSHShell "cmd /c taskkill /F /PID " & lngCmdProcess, 0
'If wshExt.WSHAppActivate(lngCmdProcess) = 0 Then
	'wshExt.WSHSendKeys "ES{ENTER}", True
	'wshExt.WSHSendKeys "{ENTER}", True
	'wshExt.WSHSendKeys "EK", True
	'For iVal = 1 To 24 
	'    wshExt.WSHSendKeys "+{DOWN}", True 
	'Next
	'For iVal = 1 To 80 
	'    wshExt.WSHSendKeys "+{RIGHT}", True 
	'Next
	'wshExt.WSHSendKeys "{ENTER}", True 
'Else
'	MsgBox lngCmdProcess & " was lost."
'End If
 
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Navigate("about:blank")
strClipboardText = objIE.document.parentwindow.clipboardData.GetData("text")
objIE.Quit
 
'MsgBox strClipboardText
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objOutputFile = objFSO.CreateTextFile(strOutputFile, True)
objOutputFile.Write strClipboardText
objOutputFile.Close
Set objOutputFile = Nothing
Set objFSO = Nothing
 
wshExt.WSHShell "notepad " & strOutputFile, 1
 
'Msgbox "Done"
 
Sub GetWindow
	intCount = 0
	Do
		intCount = intCount + 1
		If intCount = 1000 Then
			MsgBox lngCmdProcess & " could not be found"
		End IF
	Loop Until wshExt.WSHAppActivate(lngCmdProcess) = 0	
End Sub
Open in New Window
Accepted Solution
 
 
05.15.2008 at 08:06PM PDT, ID: 21579724
I mentioned about how I was having difficulty capturing the output of ktpass to someone, and he told me about two output streams that are very common.

1) Stdout (which I had been trying to capture)
2) Stderr (Which he though maybe ktpass outputed to)

Sure enough, he was right. The following code works for ktpass.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
Sub logExec(strCommand)
   dim objShell, objExecObject, strOutput
   Set objshell = wscript.creatobject("wscript.shell")
   Set objExecObject = objShell.Exec(strCommand)
   Do Until objExecObject.StdErr.AtEndOfStream
      strOutput = objExecObject.StdErr.ReadLine()
      writelog(strOutput)
      WScript.Echo strOutput
   loop
end sub
Open in New Window
 
 
 
20080236-EE-VQP-29 / EE_QW_2_20070628