I'm sure a lot of people have seen "hi, Scripting guy!. "One of the problems above, even if you have not read the original, you should have seen the code copied and pasted."
How do i show the User a dialog box to select a file?
Q: Hi, scripting guy! Is there any way that I can use a script to show the User a dialog box for the user to select a file to use? -bf
Answer: Hello, BF. If you are using Windows 2000, we do not know how to do this, at least not in the operating system. But if you are using Windows XP, the situation is different. On Windows XP, you can use the "UserAccounts.CommonDialog" object to display a standard File Open dialog box to the user. You can use a script that resembles the following code:
The code I will not copy paste, the original inside there, the Internet is also everywhere. The problem is that this code is only available for Windows XP Systems (Windows 2003 may be OK, but I haven't tested them), and Windows 7 is starting to get popular now. In Vista and Windows 7 systems, the default is not to bring the UserAccounts.CommonDialog component (incidentally, Safrcfiledlg.fileopen and Safrcfiledlg.filesave components are not).
So how do you show the User a dialog box to select a file in a Windows 7 system? The answer is the File selection dialog box in HTML:
Copy Code code as follows:
Function Browseforfile ()
Dim Shell:set Shell = CreateObject ("Wscript.Shell")
Dim Fso:set fso = CreateObject ("Scripting.FileSystemObject")
Dim tempfolder:set TempFolder = fso. GetSpecialFolder (2)
Dim tempname:tempname = fso. GetTempName ()
Dim Tempfile:set tempfile = Tempfolder.createtextfile (Tempname & ". HTA")
Tempfile.write _
""
"<title>Browse</title>" & _
""<body>" & _
"<input type= ' file ' id= ' F '/>" & _
"<script type= ' Text/javascript ' >" & _
"var f = document.getElementById (' f ');" & _
"F.click ();" & _
"var shell = new ActiveXObject (' Wscript.Shell ');" & _
"Shell. RegWrite (' Hkey_current_user\\volatile environment\\msgresp ', f.value); "& _
"Window.close ();" & _
"</script>" & _
"</body>" & _
"
Tempfile.close
Shell. Run TempFolder & "\" & Tempname & ". HTA", 0, True
Browseforfile = Shell. RegRead ("Hkey_current_user\volatile environment\msgresp")
Shell. RegDelete "Hkey_current_user\volatile Environment\msgresp"
End Function
' Author:demon
' website:http://demon.tw
' DATE:2011/6/2
Path = Browseforfile ()
If path <> "" Then WScript.Echo Path
Original: http://demon.tw/programming/vbs-open-file-dialog.html