![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | how to use the Common Item Dialog from vista in VBscript Im trying to write a few scripts for use in AD in VBscript I thought it would be nice and straight forward to be able to open csv files and the like by using a Browse For File Window so the help desk can simply find browse for the file but i am not having much luck. I have been able to BrowseForFolder Method - http://msdn.microsoft.com/en-us/libr...65(VS.85).aspx but i would like to use the new vista shell Common Item Dialog if possible. http://msdn.microsoft.com/en-us/libr...85).aspx#usage. this page gives examples but i dont know how to apply them in vbs. below is a chunk of code that wil work but i would like to use something more like the second piece that only works in XP Set objShell = CreateObject("Shell.Application") Set objFolder = objShell.BrowseForFolder _ (WINDOW_HANDLE, TITLE, OPTIONS, ROOT) Set objFolderItem = objFolder.Self objPath = objFolderItem.Path wscript.echo (objFolderItem.Path) this give the window that you would typically see when opening an office document Set objDialog = Createobject("Useraccounts.Commondialog") objDialog.Filter = "All files|*.*" objDialog.Filterindex = 1 objDialog.dialogTitle = "Select a file" intResult = objDialog.Showopen IF(intResult = 0) THEN Wscript.quit ELSE Wscript.echo objDialog.FileName END IF |
My System Specs![]() |
| | #2 (permalink) |
| | Re: how to use the Common Item Dialog from vista in VBscript J Red wrote: Quote: > below is a chunk of code that wil work but i would like to use something > more like the second piece that only works in XP > > Just for clarification, are you saying you want that XP code to run on Vista? |
My System Specs![]() |
| | #3 (permalink) |
| | Re: how to use the Common Item Dialog from vista in VBscript Hi There, short answer no, what i want is some VBScript code to open the Common Item Dialog. IFileDialog, IFileOpenDialog, and IFileSaveDialog. http://msdn.microsoft.com/en-us/libr...85).aspx#usage what i want to do is be able to use the GUI to open a file. while the first piece of code works, i would rather use the standard open file window, like a a user sees in any office program. thanks for your reply Quote: > hi J Red, > > Just for clarification, are you saying you want that XP code > to run on Vista? > |
My System Specs![]() |
| | #4 (permalink) |
| | Re: how to use the Common Item Dialog from vista in VBscript J Red wrote: Quote: > short answer no, what i want is some VBScript code to open the Common Item > Dialog. IFileDialog, IFileOpenDialog, and IFileSaveDialog. There are (at least) two possibilities. One is using an instance of IE (could be hidden) with the input tag and type=file. That will give you an open file dialog. See the code below. The other us to use a third-party control (an activeX object) which is programmed to show an open or saveas dialog. There are several such controls available, one such control can be found here: http://ccrp.mvps.org/index.html?cont...rpfiledlg5.htm Code Sample. This is one such found in the archives of this ng. There are several: <code sample> ' Adapted by Tom Lavedas from an example by Walter Zackery MsgBox("You Sclected: " & ChooseFile("c:\windows\desktop")) WScript.Quit Function ChooseFile(StartIn) With CreateObject("InternetExplorer.Application") .fullscreen = true ' required for absolute positioning of ULC .Navigate("about:blank") .Left = 300 : .Top = 200 ' position Upper Left Corner ' While .Busy : if Wscript.Version > 5 Then WScript.Sleep 100 : Wend While .Busy : WScript.Sleep 100 : Wend With .document .Write("<input id=file type=file"_ & " style='position:absolute; left:0; top:0'>") .all.file.focus if Wscript.Version > 5 Then CreateObject("Wscript.Shell").Sendkeys StartIn WScript.Sleep 200 End if .all.file.click ' opens dialog window ' The file dialog is modal, so no wait loop is required. ChooseFile = .all.file.value if ChooseFile = StartIn Then ChooseFile = "" '=> Cancelled End With ' Document End With ' IE.App End Function ' ChooseFile </code sample> cheers, jw ____________________________________________________________ You got questions? WE GOT ANSWERS!!! ..(but, no guarantee the answers will be applicable to the questions) p.s. on closer inspection, certain aspects of that sample script are no longer supported by IE (fullscreen for example). However, the underlying idea of using the input tag with type=file is still valid. |
My System Specs![]() |
| | #5 (permalink) |
| | another example can't say where I found this, but it may be easier to follow. (Extract code and make it an hta app): --- <hta code> --- <html> <head> <hta:application id="anhta"> <title> Select File </title> <script language="vbscript"> sub btnSel_onclick() msgbox "You selected " & FileName.value end sub Sub ClickButton() MsgBox("ClickButton Called") Dim doc Set doc = document End Sub </script> </head> <body onload = "ClickButton"> <center> <input id="FileName" type="file" size="40"> <br><br> <button id="btnSel">Select</button> </center> </body> </html> --- </hta code> --- cheers, jw |
My System Specs![]() |
| | #6 (permalink) |
| | Re: another example (using ms Common Dialog Control) If you happen to have ms's Common Dialog Control (comdlg32.ocx) available, then you can use that to show the open or saveas dialogs. <sample code> ' 06June05: modified to show open dlg... Option Explicit Dim oCD : Set oCD = WScript.CreateObject("MSComDlg.CommonDialog.1", "oCD_") Dim sFile : sFile = String(260, Chr(0)) ' allocate space ' some comm dlg constants... Const OFN_HIDEREADONLY = &H4 Const OFN_CREATEPROMPT = &H2000 Const OFN_EXPLORER = &H80000 Const OFN_LONGNAMES = &H200000 With oCD ' setup parameters... .Flags = OFN_EXPLORER Or OFN_LONGNAMES Or OFN_CREATEPROMPT Or OFN_HIDEREADONLY .MaxFileSize = 260 .InitDir = "c:\windows\" .DefaultExt = "htm" .Filter = "Internet Files (*.htm) | *.htm | All Files (*.*) | *.* " .FilterIndex = 2 .FileName = "Default_Filename_Here.htm" .ShowOpen ' .ShowSave ' note: show modal sFile = .FileName ' retrieve the result... End With MsgBox("you selected: " & vbCrLf & vbCrLf & " " & sFile) ' report result Set oCD = nothing ' clean up WScript.Quit </sample code> cheers, jw p.s. comdlg32.ocx is a licensed control, and you will only have it available if you have an older (classic) vb5 or vb6 installed -- or if you have vba installed. |
My System Specs![]() |
| | #7 (permalink) |
| | Re: how to use the Common Item Dialog from vista in VBscript Hi There, thanks for your suggestions. i looked into using the IE instance but it was very slow. i was hoping to just use a shell command or similar. im surprised MS doesnt have an easy way to use this through VBS i think i will just stick with the browse folder box for now really im just starting out with VBs thanks for your help |
My System Specs![]() |
| | #8 (permalink) |
| | Re: how to use the Common Item Dialog from vista in VBscript J Red wrote: Quote: > i think i will just stick with the browse folder box for now > I went back and read your reference to the VISTA objects, CLSID_FileOpenDialog and CLSID_FileSaveDialog. I'm not much good at reading c# code, but it looks like ms is instantiating the above objects via the "CoCreateInstance" system api. To the best of my understanding, the vbs "CreateObject" is just a wrapper for "CoCreateInstance". And so, depending on what you find in your registry, you may be able to just instantiate fod and fsd directly from script. OTOH, that may be just wishful thinking. If I had a vista system available, I would try it. If you are really adventuresome, you could write a simple vb.net assembly, which "wraps" those dialogs. Then using the vb.net "interop" (interoperability) feature, you could give your assembly a COM interface and call it from script. People who are back in the vin98 era (like me), shudder to contemplate vb.net assemblies. The vb.net framework is a vastly greater memory and cp hog than the old-fashioned vb (and vbs) runtimes. But then, if you have a multi-gig processor and a multi-gig memory, then vb.net and its framework is a-piece-of-cake. cheers, jw |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| can VBScript determine the active tab of a dialog? | VB Script | |||
| common dialog on vista | VB Script | |||
| Common File Dialog for Vista | VB Script | |||
| Common Dialog (Load/Save) - Missing Keyboard Shortcuts? | Vista file management | |||
| Newbie question about Explorer Views and common dialog details view?? | Vista General | |||