#214350 - 2026-07-14 04:26 PM
Win11 25H2 kills KixTrat Function
|
Lipman
Getting the hang of it
Registered: 2005-05-09
Posts: 52
Loc: Jersey Shore USA
|
I have been using this function in a utility to provide a GUI to select a file and pass that file name to be processed.
Function SelectFile()
Dim $objSHELLexec, $CMD, $objSHELL
$SelectFile=""
$CMD='mshta.exe "about:< input type=file id=FILE><script>FILE.click();new ActiveXObject("Scripting.FileSystemObject").GetStandardStream(1).WriteLine(FILE.value);close();resizeTo(0,0);</script>" '
$objSHELL=CreateObject("WScript.Shell")
$objSHELLexec=$objSHELL.Exec($CMD)
$SelectFile=$objSHELLexec.StdOut.ReadLine()
EndFunction
Now that I updated a PC from 23H2 to 25H2, the above function is no longer viable so I am seeking another function to do likewise usable in Win11 25H2.
|
|
Top
|
|
|
|
#214355 - 2026-07-16 10:03 PM
Re: Win11 25H2 kills KixTrat Function
[Re: NTDOC]
|
morganw
Fresh Scripter
Registered: 2015-10-20
Posts: 22
Loc: UK
|
This isn't a KiXtart issue, it is a security change in Windows. https://support.microsoft.com/en-US/serv...00-6725-preview
[MSHTA inline scripts] After installing this update, inline scripts passed directly to MSHTA.exe will no longer run and fail silently with no error code. This behavior is intentional; inline script execution was identified as a security vulnerability and was blocked as part of a planned security hardening change. Execution of .hta files that contain script within their HTML code continues to work as expected. Apps using inline scripts must shift to supported alternatives, such as invoking an .hta file or loading script from an external file.
|
|
Top
|
|
|
|
#214361 - 2026-07-17 10:51 PM
Re: Win11 25H2 kills KixTrat Function
[Re: Allen]
|
Allen
KiX Supporter
   
Registered: 2003-04-19
Posts: 4572
Loc: USA
|
Better version
Function SelectFile(optional $InitialDir, $Filter)
; If $InitialDir is omitted, the dialog does NOT default to @scriptdir or the
; current working directory - it opens wherever the user last browsed to in
; ANY prior OpenFileDialog on this machine. Pass $InitialDir explicitly if
; starting location matters.
Dim $objSHELLexec, $CMD, $objSHELL, $fh, $paramFile, $rc, $builtFilter
$SelectFile = ""
$paramFile = "%TEMP%\_selectfile_params.txt"
; $Filter accepts any bare extension - txt, pdf, exe, or whatever else - and
; gets built into a full "Label|*.ext" filter automatically, e.g. "txt"
; becomes "TXT files (*.txt)|*.txt". If the caller already passed a full
; filter string (detected by the presence of "|"), it's used exactly as
; given, untouched.
If $Filter <> "" And InStr($Filter, "|") = 0
If Left($Filter, 1) = "."
$Filter = SubStr($Filter, 2)
EndIf
$builtFilter = UCase($Filter) + " files (*." + $Filter + ")|*." + $Filter
Else
$builtFilter = $Filter
EndIf
$fh = FreeFileHandle()
$rc = Open($fh, $paramFile, 5)
$rc = WriteLine($fh, $builtFilter + @CRLF)
$rc = WriteLine($fh, $InitialDir + @CRLF)
$rc = Close($fh)
$CMD = 'powershell.exe -NoProfile -STA -Command "' +
'Add-Type -AssemblyName System.Windows.Forms; ' +
'$p = Get-Content ' + Chr(39) + $paramFile + Chr(39) + '; ' +
'$f = New-Object System.Windows.Forms.OpenFileDialog; ' +
'if ($p[0]) { $f.Filter = $p[0] }; ' +
'if ($p[1]) { $f.InitialDirectory = $p[1] }; ' +
'if ($f.ShowDialog() -eq [System.Windows.Forms.DialogResult]::OK) { $f.FileName }"'
$objSHELL = CreateObject("WScript.Shell")
$objSHELLexec = $objSHELL.Exec($CMD)
If Not $objSHELLexec.StdOut.AtEndOfStream
$SelectFile = $objSHELLexec.StdOut.ReadLine()
EndIf
Del $paramFile
EndFunction
Dim $reportPath, $installerPath, $logPath
$reportPath = SelectFile("C:\Reports", "pdf")
If $reportPath <> ""
? "Selected report: " + $reportPath
EndIf
$installerPath = SelectFile("C:\Downloads", "exe")
If $installerPath <> ""
? "Selected installer: " + $installerPath
EndIf
$logPath = SelectFile("C:\Logs", "txt")
If $logPath <> ""
? "Selected log file: " + $logPath
EndIf
_________________________
(... better days ahead)
|
|
Top
|
|
|
|
#214362 - 2026-07-18 02:37 PM
Re: Win11 25H2 kills KixTrat Function
[Re: Allen]
|
Lipman
Getting the hang of it
Registered: 2005-05-09
Posts: 52
Loc: Jersey Shore USA
|
AWESOME !
Thank you Allen !
That works and resolves my issue.
Thank you to all respondents.
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 710 anonymous users online.
|
|
|