Unable to output result from diskpart to text file.

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
fade2gray
Posts: 85
Joined: 21 Apr 2015, 12:28

Unable to output result from diskpart to text file.

Post by fade2gray » 08 Dec 2022, 15:01

Code: Select all

RunAs, %ComSpec% /c ""diskpart /s" "C:\path_to\folder name with spaces\commands.txt" > "C:\path_to\folder name with spaces\output.txt""
commands.txt simply contains

Code: Select all

list disk
exit
output.txt is created, but is just an empty file.

What am I doing wrong?

User avatar
mikeyww
Posts: 26883
Joined: 09 Sep 2014, 18:38

Re: Unable to output result from diskpart to text file.

Post by mikeyww » 08 Dec 2022, 15:12

Does it work when you put the command into a Windows batch file?

User avatar
fade2gray
Posts: 85
Joined: 21 Apr 2015, 12:28

Re: Unable to output result from diskpart to text file.

Post by fade2gray » 08 Dec 2022, 15:39

I haven't to be honest, Mikey. What format would that take?

User avatar
mikeyww
Posts: 26883
Joined: 09 Sep 2014, 18:38

Re: Unable to output result from diskpart to text file.

Post by mikeyww » 08 Dec 2022, 15:48

Another way:

Code: Select all

MsgBox, % getWmic("DiskDrive", "Name")

getWmic(section, property) {
 For objItem in ComObjGet("winmgmts:").ExecQuery("SELECT * FROM Win32_" section)
  wtext .= Trim(objItem[property]) "`n"
 Return Trim(wtext, "`n")
}
Or:

Code: Select all

For objItem in ComObjGet("winmgmts:").ExecQuery("SELECT * FROM Win32_DiskDrive") {
  wtext .= Trim(objItem["Name"]) "`n"
  wtext .= Trim(objItem["Size"]) "`n"
  wtext .= Trim(objItem["Status"]) "`n`n"
}
MsgBox, % Trim(wtext, "`n")
EDIT: ListView version below.

Code: Select all

fieldList = Name|Size (GB)|Status|Partitions|SerialNumber
Gui, Font, s10
Gui, Add, ListView, w600, %fieldList%
For oItem in ComObjGet("winmgmts:").ExecQuery("SELECT * FROM Win32_DiskDrive") {
 ; https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-diskdrive
 field := []
 For each, item in StrSplit(fieldList, "|") {
  If (item = "Size (GB)")
       val := Round(oItem["Size"] / 1024 ** 3)
  Else val := oItem[item]
  field.Push(val)
 }
 LV_Add("", field*)
}
LV_ModifyCol(1, 200)
LV_ModifyCol(2, "80 Center")
LV_ModifyCol(3, "50 Center")
LV_ModifyCol(4, "80 Center")
LV_ModifyCol(5, 200)
Gui, Show,, Drives
Last edited by mikeyww on 08 Dec 2022, 17:06, edited 5 times in total.

User avatar
Smile_
Posts: 858
Joined: 03 May 2020, 00:51

Re: Unable to output result from diskpart to text file.

Post by Smile_ » 08 Dec 2022, 16:33

@fade2gray
Did you read the docs about RunAs?

User avatar
mikeyww
Posts: 26883
Joined: 09 Sep 2014, 18:38

Re: Unable to output result from diskpart to text file.

Post by mikeyww » 08 Dec 2022, 17:01

Good point. This worked here.

Code: Select all

If !A_IsAdmin && !((cLine := DllCall("GetCommandLine", "str")) ~= " /restart(?!\S)") {
 params := RegExReplace(cLine, ".+\.exe.*? ")
 Try Run *RunAs "%A_AhkPath%" /restart %params%
 ExitApp
}
dir = %A_ScriptDir%
out = %dir%\output.txt
RunWait, %ComSpec% /c DISKPART /s "%dir%\commands.txt" > "%out%",, Hide
Run, %out%

User avatar
fade2gray
Posts: 85
Joined: 21 Apr 2015, 12:28

Re: Unable to output result from diskpart to text file.

Post by fade2gray » 08 Dec 2022, 18:35

Marvellous, thank you both.

Post Reply

Return to “Ask for Help (v1)”