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
  1. Dim objShell : set objShell = CreateObject("Wscript.Shell")  
  2. Dim objIE :Set objIE = CreateObject("InternetExplorer.Application")  
  3.   
  4. objShell.Run "<path>\AskUser.vbs",1,True  
  5.   
  6. objIE.Navigate("about:blank")  
  7. WScript.echo objIE.document.parentwindow.clipboardData.GetData("text")  
  8. </path>  


AskUser.vbs
  1. Dim objIE : Set objIE = CreateObject("InternetExplorer.Application")  
  2.   
  3. If Msgbox("Please press YES or NO", vbYesNo) = vbYes Then  
  4.  YourText = "YES was pressed"  
  5. Else  
  6.  YourText = "NO was pressed"  
  7. End If  
  8.   
  9. 'Write to clipboard  
  10. objIE.Navigate("about:blank")  
  11. objIE.document.parentwindow.clipboardData.SetData "text", YourText  

No comments: