| 1. |
Solve : show batch output in msg box!? |
|
Answer» hi 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 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 |
|