Issue with running DISM from comspec

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
RickC
Posts: 299
Joined: 27 Oct 2013, 08:32

Issue with running DISM from comspec

03 Aug 2021, 22:47

I used information from https://www.tenforums.com/tutorials/29588-see-full-details-about-windows-10-iso-file-usb.html to create an AHK script to automate the process.

If I enter the following in a CMD console the output is successfully redirected to the clipboard:

Code: Select all

dism /get-wiminfo /wimfile:D:\sources\install.esd /index:1 | clip
However, if I try to run this using AHK, nothing gets passed to the clipboard:

Code: Select all

#SingleInstance Force
Clipboard := ""  ; Clear the clipboard of any content
FileSelectFile, SelectedFile, 3, , Select an install file, (install.wim; install.esd)
if (SelectedFile = "")
  {
   MsgBox, The user didn't select anything.
   ExitApp
   }
else
   ;MsgBox dism /get-wiminfo /wimfile:%SelectedFile% /index:1 ;Use MsgBox to test output to commandline
   Run, %comspec% /c dism /get-wiminfo /wimfile:%SelectedFile% /index:1, , hide | clip ;Pass the parameters to DISM
MsgBox, %Clipboard% ; Display the result
Can anyone point out what I'm doing wrong?

(Weirdly it did work once but not since.)
User avatar
mikeyww
Posts: 26886
Joined: 09 Sep 2014, 18:38

Re: Issue with running DISM from comspec

03 Aug 2021, 22:53

I have not tried this, but you might try putting your "clip" with the command line instead of making it look like an AHK option, because it is not an AHK option. I also do not know whether running DISM via AHK would require running as admin. Since DISM is a program, I am not sure whether ComSpec is required for this to work (but perhaps it is needed for "clip" to work). Finally, I suggest using RunWait instead of Run. Without RunWait, the script proceeds before the run is finished.

It seems to me that "else" is redundant in this script.
RickC
Posts: 299
Joined: 27 Oct 2013, 08:32

Re: Issue with running DISM from comspec

03 Aug 2021, 23:39

Hi mikeyww - Many thanks for your reply.

I tried this:

Code: Select all

#SingleInstance Force
; Prompt to 'Run as Admin', i.e. show UAC dialog
If Not A_IsAdmin
{
   Run *RunAs "%A_ScriptFullPath%"  ; Requires v1.0.92.01+
   ExitApp
}
Clipboard := ""  ; Clear the clipboard of any content
FileSelectFile, SelectedFile, 3, , Select an install file, (install.wim; install.esd)
if (SelectedFile = "")
  {
   MsgBox, The user didn't select anything.
   ExitApp
   }
;else
   ;MsgBox dism /get-wiminfo /wimfile:%SelectedFile% /index:1 ;Use MsgBox to test output to commandline
   RunWait, %comspec% /c dism /get-wiminfo /wimfile:%SelectedFile% /index:1, , hide | clip ;Pass the parameters to DISM
MsgBox, %Clipboard% ; Display the result
Still doesn't work.

I'm using comspec because DISM is for commandline use only and I want to both hide the console output window and redirect the result. I've also tried using > instead of | as the redirector but I still can't get the output to the clipboard. It's not a clipboard issue because if I add a ClipWait line then the script just waits forever and if I remove the redirection it still doesn't work.

As a test I changed the comspec line to:

Code: Select all

RunWait, %comspec% dism /get-wiminfo /wimfile:%SelectedFile% /index:1,  ;Pass the parameters to DISM
This showed me the commandline console window but DISM didn't fire within it.

I've also tried using the full path to the DISM executable with no parameters but still no success:

Code: Select all

RunWait, %comspec% C:\Windows\System32\dism.exe  ;Run DISM
The issue is quite clearly DISM not firing... which I don't understand.

(I'm sorry but I didn't understand what you meant by making "clip" 'with the command line instead of making it look like an AHK option'.)
garry
Posts: 3764
Joined: 22 Dec 2013, 12:50

Re: Issue with running DISM from comspec

04 Aug 2021, 04:34

just a short example , see dism-help

Code: Select all

#SingleInstance, Force
If !A_IsAdmin
	Run *RunAs "%A_AhkPath%" "%A_ScriptFullPath%"
Process, Priority, , H
RunWait, %comspec% /c "dism /? |clip",,hide
msgbox,%clipboard%
exitapp
RickC
Posts: 299
Joined: 27 Oct 2013, 08:32

Re: Issue with running DISM from comspec

04 Aug 2021, 05:52

Hi garry - Many thanks for your post.

It's all working now. I had the DISM syntax correct but didn't realise a) the commandline string had to be fully enclosed in quotes - including the redirection, and b) that DISM requires elevation. I'll need to remember that in future.

Code: Select all

#SingleInstance, Force
If !A_IsAdmin
	Run *RunAs "%A_AhkPath%" "%A_ScriptFullPath%"
Process, Priority, , H
Clipboard := ""  ; Clear the clipboard of any content
FileSelectFile, SelectedFile, 3, , Select an install file, (install.wim; install.esd)
if (SelectedFile = "")
  {
   MsgBox, The user didn't select anything.
   ExitApp
   }
RunWait, %comspec% /c "dism /get-wiminfo /wimfile:%SelectedFile% /index:1 |clip",,hide ;Pass the parameters to DISM
MsgBox, %Clipboard% ; Display the result
ExitApp
When run and pointed at either a install.wim or install.esd file in a Windows ISO it now spits out this:

Image

This is exactly what I wanted and so much easier than using just an elevated commandline console.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Decar, doodles333, mikeyww, Tupper and 222 guests