1.

Solve : show batch output in msg box!?

Answer»

hi
i want to show my final output in massage box, i don't know but something like that,

code:

@echo off
set/P drive="your drive>"
fsutil volume diskfree %drive%

output in massage box, like,
msg * "OUTPUT_OF_fsutil volume diskfree %drive%"

tnxbatch scripting does not have message boxes. VBScript does.
you can simply make your own exe with this functionality using another language. I have a program I could upload that does exactly what you want, but you will have to wait for me to get it from my home computer in a few days bc I am on vacation. If it is mandatory, I can give you some vb or c++ code.With VBScript, you could run the fsutil command, capture the output into a variable and then display a message box. With NT batch, you'd have to capture the output in a file, then push it into the message box:

This won't win any beauty contests, but it might take home the prize for Miss Congeniality:

Code: [Select]@echo off
setlocal

set /p drive=Enter Drive Letter:

for /f "tokens=* delims=" %%i in ('fsutil volume diskfree %drive%:') do (
echo %%i >> text
)

<text msg %username%
del text

At the prompt enter only the drive letter; the batch file will insert the colon.

Good luck. Nicely spotted, Sidewinder, I had forgotten about msg. I played around with it a bit

Code: [Select]@echo off
set /p drive="Enter Drive Letter: "
Echo Statistics for Drive %drive%: > text
for /f "tokens=* delims=" %%i in ('fsutil volume diskfree %drive%:') do echo %%i >> text
<text msg %username%
del text
it is so much cleaner to just write a program in c, copy it to system32, and then call it from batch by just typing MSGBOX [bla bla]Quote from: Linux711 on August 06, 2011, 08:08:00 PM

it is so much cleaner to just write a program in c, copy it to system32, and then call it from batch by just typing msgbox [bla bla]

You can do this already from VBscript
Quote from: Salmon Trout on August 07, 2011, 01:07:01 AM
You can do this already from VBscript

... and you can do a lot more things...

As I shall PROCEED to demonstrate...

Code: [Select]' Make Shell object available
Set Shell = CreateObject("Wscript.Shell")

' Force use of cscript.exe so we can use console input
If Instr(1, WScript.FullName, "CScript", vbTextCompare) = 0 Then
Shell.Run "cscript """ & WScript.ScriptFullName & """", 1, False
WScript.Quit
End If

' Get console input from user
' 1. Write prompt to console, no newline
wscript.stdout.Write "Enter drive letter: "

' 2. Get user input terminated by Enter
UserInput = Wscript.StdIn.ReadLine

' 3. Just get first character in case they type C: or similar
DriveLetter = Mid(UserInput,1,1)

' Start building string to pass to messagebox
' Force drive letter to upper case (just because we can!)
MessageString = "Drive letter is: " & UCase(DriveLetter)

' This is the string we pass to Shell for execution
FsUtilString = "fsutil volume diskfree " & DriveLetter & ":"

' Start FSUtil running
Set oExec = Shell.Exec(FsUtilString)

' While it has not yet finished...
Do While oExec.StdOut.AtEndOfStream <> True

' Get each line in turn from fsutil
FsUtilOutputLine = oExec.StdOut.ReadLine

' Split the line at the colon
SplitLineArray = Split(FsUtilOutputLine,":")

' We have split Array has 2 elements, 0 and 1
' Because there is 1 colon in each line
LineText = SplitLineArray(0)
ByteText = SplitLineArray(1)

' Force the bytes value string into a number
ByteNumb = Eval(ByteText)

' Some HANDY values demonstrated
KiloBytes = ByteNumb / 1024
MegaBytes = ByteNumb / (1024 * 1024)
GigaBytes = ByteNumb / (1024 * 1024 * 1024)

' We'll show GB in brackets after the bytes figure
' We'll reduce the large number of decimal places to just 2
GBFormat = FormatNumber(Gigabytes,2)

' Build up the string for the message box
' Insert a carriage return / line feed after each line (except the last)
' So that they will appear as separate lines in the box
MessageString=MessageString & VBcrlf & LineText & ":" & ByteText & " (" & GBFormat & " GB)"

Loop

' Retval is a dummy value in this case since we are only using 1 Button (OK button)
' Therefore we are not concerned about the return value
Retval = MsgBox(MessageString, vbOKOnly, "Disk Free and Used Space")





thanks for reply

this code is work, but i don't know vbScript language Quote from: behzad-007 on August 07, 2011, 07:13:05 AM
thanks for reply

this code is work, but i don't know vbScript language

Now is the time to start learning! I put lots of comments in there. Or you have batch code above.



You can do it in 5 lines of batch

Code: [Select]@echo off
Set /p drive=Enter Drive Letter:
fsutil volume diskfree %drive%: > text.txt
<text.txt msg %username%
del text.txt
In fact you can do it in 1 line

Code: [Select]@Set /p drive=Enter Drive Letter: & echo Drive %drive%: > text.txt & fsutil volume diskfree %drive%: >> text.txt & <text.txt msg %username% & del text.txttnx so much

5 line batch worked!
but 1 line code is not WORKING in my pc!! Quote from: behzad-007 on August 08, 2011, 03:17:48 AM
but 1 line code is not working in my pc!!
Yes it has an error I will try to fix it


Discussion

No Comment Found