0

i have written a program which calculates the HASH of all files of a folder and saves it an an xml file. now my objective is that i want to give the folder to be evaluated, explicitly from outside the program

  Dim WshShell, oExec, input
Set WshShell = CreateObject("WScript.Shell")
Set oExec    =_
     WshShell.exec("C:\Users\Administrator\Downloads\fciv.exe -md5 -r -xml _
     d.xml C:\openssl")

 input = ""

 Do While oexec.status=0


 WScript.Sleep 5000
 Loop

this is the program. i tried adding inputbox command thinking i would be able to give the input explicitly. here is the modified program

 Dim WshShell, oExec, strin
 Set WshShell = CreateObject("WScript.Shell")
 strin= inputbox("folder")
 Set oExec    =_
  WshShell.exec("C:\Users\Administrator\Downloads\fciv.exe -md5 -r -xml ex.xml strin")
 input = ""
 Do While oexec.status=0*

 WScript.Sleep 1000
 Loop

this is not working :( pls help. what exactly shud i be using thr? also how do i give the same input using a cmd file???

dante akram
  • 39
  • 2
  • 8

1 Answers1

1

You just need to use the string concatenation operator & to build the command string:

 Dim WshShell, oExec, strin
 Set WshShell = CreateObject("WScript.Shell")
 strin= inputbox("folder")
 Set oExec    =_
  WshShell.exec("C:\Users\Administrator\Downloads\fciv.exe -md5 -r -xml ex.xml """ & strin & """")
 input = ""
 Do While oexec.status=0
     WScript.Sleep 1000
 Loop

I took the liberty of adding the appropriate double-quotes in case the input path has spaces. You might want to also add in some validation of the path, eg:

dim fso: set fso = CreateObject("Scripting.FileSystemObject")
if not fso.FolderExists(strin) then
     WScript.Echo strin & " not found"
     WScript.Quit 1
end if
  • 1
    The reason for this is that VBScript doesn't expand variables inside strings. – Ansgar Wiechers Aug 01 '13 at 09:35
  • how can i pass parameter using cmd file instead of inputbox. Is it possible? – dante akram Aug 01 '13 at 09:41
  • can somebody please tell me how to pass a parameter to a file using cmd command???? for example: i want to be able to give the folder name (initialised by strin in the above program) to be given using cmd instead of inputbox..is it possible? pls help – dante akram Aug 06 '13 at 08:52
  • @amateur_vbscripter a parameter to a vbscript? see [msdn](http://msdn.microsoft.com/en-us/library/z2b05k8s(v=vs.84).aspx) and [this question](http://stackoverflow.com/q/10091711/69820) or [search](http://stackoverflow.com/search?q=%5Bvbscript%5D+arguments) –  Aug 06 '13 at 19:29