9/04/2008

Retrieving "exit strings" from vbScript

Retrieving exit codes from vbScript is not very tricky, but there's no method to retrieve "exit strings" from a script.
Below there's listed a little workaround to keep strings in "computers mind" after a script finished without using tempfiles, registry keys or environment variables as data store.

Step by Step:

  1. ShowResult.vbs calls the script AskUser.vbs

  2. AskUser.vbs captures somes user input

  3. AskUser.vbs writes the user input into the windows clipboard

  4. AskUser.vbs ends

  5. ShowResults.vbs queries the clipboard for the written text

  6. ShowResults.vbs shows the result



ShowResult.vbs

Dim objShell : set objShell = CreateObject("Wscript.Shell")
Dim objIE :Set objIE = CreateObject("InternetExplorer.Application")

objShell.Run "\AskUser.vbs",1,True

objIE.Navigate("about:blank")
WScript.echo objIE.document.parentwindow.clipboardData.GetData("text")


AskUser.vbs

Dim objIE : Set objIE = CreateObject("InternetExplorer.Application")

If Msgbox("Please press YES or NO", vbYesNo) = vbYes Then
YourText = "YES was pressed"
Else
YourText = "NO was pressed"
End If

'Write to clipboard
objIE.Navigate("about:blank")
objIE.document.parentwindow.clipboardData.SetData "text", YourText

No comments: