okidoki
Goto Top

Datei auswählen (XP, Win7...) mittels vbs in Batch

Hallo zusammen,
das Thema wird hier heiß diskutiert und es gibt auch Lösungansätze:
VBS-BAT Datei auswählen oder hier 1.

Das Problem ist aber, dass die beiden ersten Varianten unter Windows 7 nicht mehr funktionieren.
Folgenden Code habe ich anzubieten, der in W7 geht und den den Pfad auch ausgibt. Nun möchte ich allerdings den Pfad in einer Variablen haben und benötige kein Ausgabefenster. Das bekomme ich leider nicht hin und benötige eure Hilfe! Dann ist vielleicht auch Dani und vielen anderen geholfen!
@ECHO OFF & SETLOCAL
 >%temp%\msgbox.vbs ECHO Function BrowseForFile()
>>%temp%\msgbox.vbs ECHO With CreateObject("WScript.Shell")  
>>%temp%\msgbox.vbs ECHO Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")  
>>%temp%\msgbox.vbs ECHO Dim tempFolder : Set tempFolder = fso.GetSpecialFolder(2)
>>%temp%\msgbox.vbs ECHO Dim tempName : tempName = fso.GetTempName() ^& ".hta"  
>>%temp%\msgbox.vbs ECHO Dim path : path = "HKCU\Volatile Environment\MsgResp"  
>>%temp%\msgbox.vbs ECHO With tempFolder.CreateTextFile(tempName)
>>%temp%\msgbox.vbs ECHO .Write "<input type=file name=f>" ^& _  
>>%temp%\msgbox.vbs ECHO "<script>f.click();(new ActiveXObject('WScript.Shell'))" ^& _  
>>%temp%\msgbox.vbs ECHO ".RegWrite('HKCU\\Volatile Environment\\MsgResp', f.value);" ^& _  
>>%temp%\msgbox.vbs ECHO "close();</script>"  
>>%temp%\msgbox.vbs ECHO .Close
>>%temp%\msgbox.vbs ECHO End With
>>%temp%\msgbox.vbs ECHO .Run tempFolder ^& "\" ^& tempName, 1, True  
>>%temp%\msgbox.vbs ECHO BrowseForFile = .RegRead(path)
>>%temp%\msgbox.vbs ECHO .RegDelete path
>>%temp%\msgbox.vbs ECHO End With
>>%temp%\msgbox.vbs ECHO End Function
>>%temp%\msgbox.vbs ECHO MsgBox BrowseForFile
for /f "delims=" %%i in ('cscript //nologo %temp%\msgbox.vbs') do set "Pfad=%%~dpi" & set "Name=%%~ni" & set "Typ=%%~xi"  
del %temp%\msgbox.vbs
echo %Name%

Gruß
okidoki

Content-Key: 213372

Url: https://administrator.de/contentid/213372

Printed on: April 18, 2024 at 06:04 o'clock

Member: colinardo
colinardo Aug 05, 2013 updated at 11:04:45 (UTC)
Goto Top
Hallo okidoki,
die letzte Zeile der VBS in wscript.echo BrowseForFile ändern
>>%temp%\msgbox.vbs ECHO wscript.echo BrowseForFile
@ECHO OFF & SETLOCAL
 >%temp%\msgbox.vbs ECHO Function BrowseForFile()
>>%temp%\msgbox.vbs ECHO With CreateObject("WScript.Shell")  
>>%temp%\msgbox.vbs ECHO Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")  
>>%temp%\msgbox.vbs ECHO Dim tempFolder : Set tempFolder = fso.GetSpecialFolder(2)
>>%temp%\msgbox.vbs ECHO Dim tempName : tempName = fso.GetTempName() ^& ".hta"  
>>%temp%\msgbox.vbs ECHO Dim path : path = "HKCU\Volatile Environment\MsgResp"  
>>%temp%\msgbox.vbs ECHO With tempFolder.CreateTextFile(tempName)
>>%temp%\msgbox.vbs ECHO .Write "<input type=file name=f>" ^& _  
>>%temp%\msgbox.vbs ECHO "<script>f.click();(new ActiveXObject('WScript.Shell'))" ^& _  
>>%temp%\msgbox.vbs ECHO ".RegWrite('HKCU\\Volatile Environment\\MsgResp', f.value);" ^& _  
>>%temp%\msgbox.vbs ECHO "close();</script>"  
>>%temp%\msgbox.vbs ECHO .Close
>>%temp%\msgbox.vbs ECHO End With
>>%temp%\msgbox.vbs ECHO .Run tempFolder ^& "\" ^& tempName, 1, True  
>>%temp%\msgbox.vbs ECHO BrowseForFile = .RegRead(path)
>>%temp%\msgbox.vbs ECHO .RegDelete path
>>%temp%\msgbox.vbs ECHO End With
>>%temp%\msgbox.vbs ECHO End Function
>>%temp%\msgbox.vbs ECHO wscript.echo BrowseForFile
for /f "delims=" %%i in ('cscript //nologo "%temp%\msgbox.vbs"') do set "Pfad=%%~dpi" & set "Name=%%~ni" & set "Typ=%%~xi"  
del %temp%\msgbox.vbs
echo %Name%

Grüße Uwe
Member: OKIDOKI
OKIDOKI Aug 05, 2013 at 11:42:00 (UTC)
Goto Top
Super Uwe, dankeschön!

Hoffentlich hilft es auch anderen.

okidoki
Member: OKIDOKI
OKIDOKI Apr 04, 2015 at 08:33:23 (UTC)
Goto Top
Hallo zusammen,

nachdem Uwes Lösung die letzten 2 Jahre problemlos funtioniert hat, geht nun nichts mehr ...

Es folgt das Öffnen eines Editors mit der Meldung:

<input type=file name=f><script>f.click();(new ActiveXObject('WScript.Shell')).RegWrite('HKCU\\Volatile Environment\\MsgResp', f.value);close();</script>

Kann mir da jemand unter die Arme greifen?
okidoki
Mitglied: 114757
114757 Apr 04, 2015 updated at 08:47:50 (UTC)
Goto Top
Moin,
es folgt das Öffnen eines Editors mit der Meldung:
dann ist auf deinem System die HTA Dateierweiterung nicht mehr im Originalzustand bzw. das default Verb steht auf Bearbeiten anstatt Ausführen. Setze diese auf default zurück (kannst du dir aus einem Original Windows 7 abschauen).
Dabei hilft dir das Tool extman


Gruß jodel32
Member: OKIDOKI
OKIDOKI Apr 04, 2015 at 08:52:32 (UTC)
Goto Top
... leider nein, steht schon auf 'open' ...
Gruß
Mitglied: 114757
114757 Apr 04, 2015 updated at 09:00:24 (UTC)
Goto Top
Zitat von @OKIDOKI:

... leider nein, steht schon auf 'open' ...
Gruß
Dann ist das Open-Verb bzw. die Befehlszeile nicht mehr original oder dein Virenscanner blockt jetzt das Ausführen von HTAs, oder der IE ist korrupt, bzw. eher Sicherheitseinstellungen dort zu restriktiv eingestellt.
Member: OKIDOKI
OKIDOKI Apr 04, 2015 at 09:00:04 (UTC)
Goto Top
Danke jodel32!
Hast de eventuell eine Alternative? Ich benötige den Dialog dennoch face-smile

Gruß okidoki
Member: colinardo
Solution colinardo Apr 04, 2015, updated at Apr 05, 2015 at 08:57:39 (UTC)
Goto Top
Zitat von @OKIDOKI:

Danke jodel32!
Hast de eventuell eine Alternative? Ich benötige den Dialog dennoch face-smile
Hallo OKIDOKI,
ich habe da eine Batch/Powershell-Kombinations-Variante für das "visuelle Auswählen" eines Pfades via FileOpen-Dialog
@echo off
for /f "delims=" %%a in ('powershell -ExecutionPolicy ByPass -Command "&{[System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms') | Out-Null;$dlg = New-Object System.Windows.Forms.OpenFileDialog;if($dlg.ShowDialog() -eq 'OK'){return $dlg.Filename}}"') DO set "name=%%a"  
echo %name%
Der Dialog lässt sich bei Bedarf natürlich auch noch anpassen, um z.B. die Dateifilter, initialer Pfad etc. festzulegen...

Grüße Uwe
Member: OKIDOKI
OKIDOKI Apr 04, 2015 at 09:33:55 (UTC)
Goto Top
Prima, danke Uwe!!!

Eine Lösung vor Ostern zu finden hätte ich nicht gedacht - ich glaube an den Hasen, bestimmt!

Grüße
okidoki