Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Choose file from windows file browser & pass as parameter 2 bat file? 2

Status
Not open for further replies.

Zooby12

Programmer
Aug 10, 2011
8
US
Hi, i'm brand new to VBScript but I need to use it to choose a file from the windows file browser and pass the entire path of the file as a parameter to a bat file that i call. So far I have the option to pick a file, and the option to pass parameters to the bat file. I, however, can't get the value of the parameter to be passed to the bat file instead of "parameter" itself. Also, even if I do get it to be passed, I don't think it would include the entire path where the file is located. If you could help with this, that'd be great. Here is what I have:

Option Explicit
Dim ObjFSO, InitFSO

Set ObjFSO = CreateObject("UserAccounts.CommonDialog")

ObjFSO.Filter = "|All Files|*.*"
ObjFSO.FilterIndex = 5
ObjFSO.InitialDir = "..\"

InitFSO = ObjFSO.ShowOpen

If InitFSO = False Then
Wscript.Echo "Script Error: Please select a file!"
Wscript.Quit
Else
WScript.Echo "You selected the file: " & ObjFSO.FileName
Const NORMAL_WINDOW = 1
Dim oShell, sParams
sParams = "ObjFSO.FileName"
Set oShell = CreateObject("Shell.Application")
oShell.ShellExecute "..\load\fmco\ofp\patch_constants\patch_constants.bat", sParams, , , NORMAL_WINDOW
Set oShell = Nothing
End If
 
Replace this:
sParams = "ObjFSO.FileName"
with this:
sParams = ObjFSO.FileName

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PHV is correct. By putting quotes around the object, you are assigning sParams the text between the quotes instead of the value of the object.

Just a suggestion...

objFSO is commonly used to represent a FileSystemObject. Consider changing it to objDialog so it clearly represents a Dialog object. Same goes for oShell. Perhaps objApp is better candidate.

-Geates

"I hope I can feel and see the change - stop the bleed inside a feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Thanks PHV! It worked!

I swear I tried that though... I must've only tried the sParams with or without quotes. My fault.

And thank you for the suggestions Geates.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top