Jump to content

congnt92

Member
  • Posts

    128
  • Joined

  • Last visited

  • Donations

    0.00 USD 
  • Country

    Vietnam

Posts posted by congnt92

  1. 5 hours ago, Mcinwwl said:

    And again, I tried to do my best with Powershell. tested on PS 2.0/WinXP, both in PS console and Powershell ISE.
    Script outputs drive letter, free space, total space and label for each active removable drive (pendrives, portable HDDs, memory cards... and floppy discs :P)

    
    $drives = [System.IO.DriveInfo]::getdrives() | ?{$_.Drivetype -eq "Removable" -and $_.IsReady -eq $true}
    foreach ($d in $drives) {Write-host ("$($d.RootDirectory.name.TrimEnd("\"))" + " " + [math]::round(($d.AvailableFreeSpace)/1GB,2) + " " +  [math]::round(($d.TotalSize)/1GB,2) + " " + "$($d.VolumeLabel)")}

    That was my output with 4 connected pendrives:  

    
    G: 1.78 1.87 
    H: 14.87 29.28 
    I: 3.73 3.73 
    J: 7.16 7.31 KINGSTON

    Hope that was expected.


     

    Hi Mcinwwl, That's greate. And you're a Powershell professional, I guess you didn't really believe in yourself  :P

    Just a question, how can I save it and use for batch file when i need a mix-method? Tks

  2. 10 hours ago, gunsmokingman said:

    Here is a simple VBS script that list Removable drives if they are connected. It will display the Drive Size, Free Space, Used Spaced.

    Hi, Gunsmokingman

    First, Thank you for your enthusiasm.

    I try your vbs code with 2 USB devices plug on my PC but still .vbs say that no removable drives found.

    I do not know why i get this error. May come from copy paste issue. So can you please attach .vbs file for me.

    Tks :)

  3. 4 minutes ago, dencorso said:

    Your problem is that one of the files is a UNICODE .txt, while the other is a plain ASCII .txt, and, BTW, that vbs expects both to be plain ASCII. :w00t:

    Thank you for your clarification, dencorso. You're right.

    Text2.txt is output from batch code, i do not know why it is unicode .txt.

    But after your hint, i save it as ANSI to make sure again. Rerun .vbs code, it still return
     

    H: Removable Disk 4.0 GB
    I: Removable Disk 7.9 GB
    
    USB1        
    USB2

    Why i need to outptut as

    H: Removable Disk 4.0 GB USB1        
    I: Removable Disk 7.9 GB USB2 

    Tks.

  4. I want to create a batch file with some wmic command to display USB driveletter, description, size, volume name.

    @echo off
    WMIC LOGICALDISK where drivetype=2 get caption,size,description,volumename > text.txt
    for /f "tokens=1-5 skip=1" %%a in ('type "text.txt"') do call :display %%a %%b %%c %%d %%e
    exit /b
    
    :display
    set drive=%1
    set total=%4
    set desc1=%2
    set desc2=%3
    
    set volname=%5
    
    call :convertbytes total
    
    echo %drive% %desc1% %desc2% %total%>> text1.txt
    goto :eof
    
    : convertbytes
    
    REM run some command here to convert bytes to Gib

    ...

    But i have problems when using above code to display vol name. Because in some case vol name contain space then i do not know how to use for /f token (tokens can up to 6, 7, 8 even more).

    In case vol name contain space, then if we just using token 1-5, volname cannot fully display. Such as, FULL Vol name is : KINGSTON USB, then it only display KINGSTON.

    So to solved my problem, i split to output vol name to text2.txt, all the rest will output to text1.txt. Then i will merge text in 2 file (text1.txt, text2.txt) to one file (text3.txt). Finally i use TYPE command to display text3.txt. This is exactly i want to create this topic to get help from you.

    --------

    My problem was solved by Jaclaz's batch code, by Mcinwwl's Powershell code, and of course Gunsmokingman's VBS code (but now I'm waiting his reply to edit *something* wrong may come from his typo).

    Tks all of you, Jaclaz,  Mcinwwl, Gunsmokingman help me solve my problem.

    God bless you :)

  5. 6 hours ago, gunsmokingman said:

    Here is the VBS way of doing it with checks

    Thank you, gunsmokingman

    I tried your .vbs code but get this output. If you have a free time, can you recheck your code and see if there is any typo in it? Tks
     

    H: Removable Disk 4.0 GB
    I: Removable Disk 7.9 GB
    
    ÿþU S B 1                 U S B 2   
     

    Also, just me make sure i'm copy your code completely. I upload your .vbs, too

    test_vbs.zip

  6. 8 hours ago, Mcinwwl said:

    Written ad-hoc in Powershell 2.0 (should work on any newer version, which means every Windows system from XP up to today)
    I'm not a Powershell professional, so it might not be written with respect to all best practices, but it surely works.
    Remember to set your current working directory with cd or set-location before using.

    
    $1 = Get-Content text1.txt
    $2 = Get-Content text2.txt
    foreach($line in $(0..($text1.length - 1))){
    $1[$line] + " " + $2[$line] >> text3.txt} 

    EDIT: Getting curious what the real goal is...

    Tks for your reply. I do not know anything about powershell. I never use it before. i know that there are many ways that better than batch but I'm not good at coding then i always try to write some simple batch file to archive my goal.

    I tried with your method and it work very well. After I have text3.txt, i can display it in batch by type command. This method is "mixed" method: powershell and batch.

    I just have one thing make me worry that i do not know if powershell is always exists in all PC Windows or maybe winPE.

    Again, thank you very much.

  7. 8 hours ago, jaclaz said:

    You may want to ask the actual question and not a small part of it.

    (full disclosure, maybe I know what the actual question is, because we talked about it via PM).

    Remember, you want to reach a goal, express it, DO NOT divide the way you believe you can reach it in n little steps each disjointed from the previous one, there are several reasons for this, among them the fact that there may be "better" or "easier" ways to reach your goal, people doesn't know WHAT you are actually wanting to do, you may make an example for what you believe is the right approach which is either inaccurate or more simply "wrong" , so as soon as an answer will be given to you, you will come up with another question (because the answer is not suitable to your unknown goal) and then another question, and another question :ph34r:.

    You have a test1.cmd that creates text1.txt and a test2.cmd that creates text2.txt, yet, your code deals with two other files outputfile.txt and volname.txt, and there is no trace of text3.txt.

    So I have to assume that text1.txt is actually  outputfile.txt and that text2.txt is volname.txt.

    I can provide you a perfectly valid answer to your question but that won't help you a little bit in getting near your GOAL, (this answers your question and example):

    jaclaz
     

    Hi Jaclaz,

    First i'm sorry. I just want to split my problem because if i post full my goal, then may be there are too much texts, and may be it make the reader quite difficult to know what extractly i need help.

    I tried your code and it work perfect. Also, as your advice, i edit #1 to full post and hope that if there is someone has same problem with me, it can help him/her.

    Again, thank you very much, Jaclaz.

  8. Hi all,

    EDIT: To avoid missmatch between Title and topic content, also to avoid a long post, I repost full my problem in post #9.

    I have 2 small .cmd file. Let say test1.cmd and test2.cmd

    test1.cmd creates text1.txt

    H: Removable Disk 4.0 GB
    I: Removable Disk 7.9 GB

     test2.cmd creates text2.cmd
     

    USB1
    USB2

    My goal is merger text in text1.txt with texts in text2.txt to new file (text3.txt)

    H: Removable Disk 4.0 GB USB1
    I: Removable Disk 7.9 GB USB2

     

    Here my way to do that but it repeat output many times
     

    @echo off
    for /f "tokens=*" %%a in ('type "text1.txt"') do (
    for /f "tokens=*" %%b in ('type "text2.txt"') do echo %%a %%b)
    pause

    Can you help me correct my code? Tks :)

  9. You need to detect if the running OS is 32 bit or 64 bit, then - when  needed - use the "virtual" Sysnative folder:

    http://www.samlogic.net/articles/sysnative-folder-64-bit-windows.htm

     

    Of course while (AGAIN) you should use .cmd and not .bat as extension, how exactly you "convert" the batch file to an executable may matter.

     

    jaclaz

     

    Hi Jaclaz,

    I'm sorry for delay response.

    I use .cmd extension as you say. And i use winrar to create sfx.exe.

     

    Right click test.cmd >> add to archive >> tick create sfx archive check box >> goto Advanced tab >> choose SFX options

    path to extract: %windir%

    run after extraction: test.cmd

    mode: hide all

    advanced: admin access

    update: overwrite all files.

     

    My goal is: I create a winpe by winbuilder and i must to make sure test.cmd only run in my winPE.

    In system32, i have a tag file to help me detect if winpe was build by me or others.

    So in test.cmd i have some command like: if exist %windir%\system32\file.tag then do something, or if exist %windir%\system32\myreg.reg then import it ....

    Because test.cmd required some extra files so i want to create sfx.exe that will extract to %windir% then excute it from here.

    But problem come from here, run test.cmd normally it work fine but if put it to sfx then it say that file.tag not found, mean it's running from winpe that not build by me even i'm testing on my pe.

    Tks.

  10. Your EXE file (I assume the BAT is inside it) is being unpacked to a generated folder name inside your TEMP directory. Better take a closer look at the documentation for how to circumvent that. It'll be an additional parameter that you add in the "Text" window of the SFX. Trust me, the info is there.

     

    HTH

    Tks for your reply, submix8c

    After some works, I found that: On windows 64bits, %windir%\system32 is C:\windows\system32 if run test.cmd. But it will be C:\windows\sysWOW64 folder if run test.sfx.exe

    So after run test.sfx.exe and winrar call test.cmd, then test.cmd say that file.tag not found.

     

    May you will ask me: Why do you say that? Are you sure?

     

    Yes. I'm sure.

    Try with another test.cmd

    @echo offcopy C:\testfile.txt %windir%\system32\testfile.txtpause

    then testfile.txt was copied to system32 folder.

     

    But if i create sfx exe by winrar, after test.cmd extract and run, it copy testfile.txt but to SysWow64 folder.

     

    So can you give me some hints how can I create sfx.exe that can be use on both 32 and 64bits.

    Tks.

  11. Hi Yzöwl, submix8c

    I have same issue with Alystinn.

    .

    I have a .bat and i want to convert it to test.exe which run on both 32 and 64bits OS

    If i run test.bat then it work fine, but if i run test.exe then bat fail.

     

    Here my test.bat (file.tag put at system32 folder but test.exe return not found)

    @echo offif exist %windir%\system32\file.tag echo found! && pause && exitecho not found!pauseexit

    I'm using WinRAR 64bits trail version to make sfx .exe and I run .exe on 64bits OS.

    Can you give me some advices?

    Tks

  12. Only to be able to release *something* on February 29, a small batch (a simple adaptation of multiply.cmd):

    http://reboot.pro/topic/2986-yacbfc-dec2hexcmd-and-hex2deccmd/

    KMG2B.cmd :small batch file to convert numbers expressedin Kb, Mb, Gb into bytes, overcoming the 0x07FFFFFFlimit in batch (aka 2,147,483,647)this is about "real" K/M/G, i.e. powers of 1024what would be now called KiB, MiB, GiB.******** Version 1.0 29 February 2016 ********by jaclazThis file is licensed under my "CAREWARE" license:http://jaclaz.altervista.org/Projects/careware.htmlUsage:KMG2B.cmd Integer[K|M|G]

    jaclaz

     

    Try KMG2B.cmd, work perfectly.

    But if put it in directory which contain space in path it'll error. You may add some double quote for general use. Tks

  13. Oh, my. 

    Did you believe that grubx64.efi is a BOOTSECTOR?  :w00t:

    I guess you should think also about shimx64.efi, consult this (long) page:

    http://ubuntuforums.org/showthread.php?t=2147295

    and this one:

    http://linux.about.com/od/LinuxNewbieDesktopGuide/tp/3-Ways-To-Fix-The-UEFI-Bootloader-When-Dual-Booting-Windows-And-Ubuntu.htm

    Basically, dual booting on UEFI is a total mess, depending on single machines/firmwares and specific version of windows (and *what not* :() but, as you found out, normally you cannot add a multi-boot entry for Linux/GRUB2 to Windows BOOTMGR BCD on UEFI, you need to make GRUB2 (or Refind, etc.) your main bootmanager.

    jaclaz

    Oh i'm do not know about osloader or bootsector in bcdedit command. I think that grubx64.efi just like grldr but grldr config menu.lst, grubx64.efi config grub.cfg.

    I try with bcdedit add grubx64.efi before but no luck. Not remember exactly what error, but it fail on windows boot manager, I will try again and will report detail error. tks for your given links

  14.  

    With computer has 2 disks, we can say that the disk which windows boot from always show as disk 0 in diskpart ?? Not matter with internal or external ??

    I doubt always, very often it's disk 0.

    A user may change UEFI boot order: current running windows disk 0, second disk 1

    The user changes the boot order: next boot is not from previous windows disk

    Possible execeptions

    Kansas chity shuffle http://www.911cd.net/forums//index.php?showtopic=21242

    Machines with chipset storage and addional esata, msata or m.2 connector

    Imagine at two disk: given one EFI system partiton.

    You add a file this single EFI system partiton.

    The end user boot another OS next, creates a second EFI system partiton at the second hard disk.

    And boots from second hard disk next. Your file is missing at active EFI system partiton

    I don't understand the requirements still.

    Machinbe booted at BIOS? Machinbe booted at BIOS?

    What about EFI NVRAM settings?

    Remember, if you boot from UEFI, then mountvol solves your basic issue.

    Given the end user keeps the UEFI disk order.

    A real world simplification:

    If a disk 0 contains a EIF system, then use this. Ignore strange cases.

    By the way:

    At booted PE may reset SystemSetupInProgress settings, e.g. printer support

     

     

    Tks for your detail info.

    My goal:

    - At legacy bios, we can add a menu entry to boot.ini or BCD

    - At uefi, we can add menu to BCD but i do not know why it can not work

     

    quote from .bat (S: is EFI partition which mount by your method)

     

    for /f "tokens=3" %%a in ('bcdedit /create /d "Ubuntu" /application BOOTSECTOR') do set guid=%%a

    bcdedit /set %guid% device partition=S:

    bcdedit /set %guid% PATH \EFI\Boot\grubx64.efi

    ....

     

    But it fail at Windows Boot manager. I guess that boot ubuntu.efi file from BCD is impossible. But this method work with memtest.efi. So may must be signed .efi ??

     

    So i think that, i must replace bootx64.efi from Microsoft with bootx64.efi from ubuntu, then bootx64.efi from ubuntu config file grub.cfg, with grub.cfg i have a menu that chainload to bootfw.efi to boot windows and a menu to boot Live Ubuntu. By this method, i can dual boot windows and linux.

     

    And to copy bootx64.efi from ubuntu to EFI partition, I need a .bat to do this. You and Jaclaz help me solved it.

     

    My .bat request: User must run .bat from real UEFI windows (not PE).

  15. About CurrentControlSet:

    https://support.microsoft.com/en-us/kb/100010

     

    There are several keys that one can check:

    PE 2.x and later:

    HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\WinPE

    PE 1.x and later:

    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\MiniNT

    but there is SystemSetupInProgress (but this may be re-set to 0 intentionally in the build to allow runnign some programs) and more:

    http://www.911cd.net/forums//index.php?showtopic=2840

     

    jaclaz

    Tks for your info, i will try and report result.

  16. Well, if you are going to look in the Registry, then you could probably check also:

    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Firmwarebootdevice

    but this is 7 and later only.

     

    More generally, you should always use the CurrentControlSet or check manually the Select hive on a live system, you cannot assume that Current is ControlSet001.

     

     

    jaclaz

     

    Oh i do not know that. I found this reg key from internet and even do not understand it work for general way or not.

    Can you give me some other ways simpler and quicker ??

  17.  

    Now that the general conversation has finished and because you hadn't specified your OS, I thought I'd mention using a (probably built-in) PowerShell script to create your file.

     

    New-SizedFile.ps1

    param( [string]$FilePath,[double]$Size )$file = [System.IO.File]::Create($FilePath)$file.SetLength($Size)$file.Close()

    Example Uses:

    Create Dummy.txt with size 698 bytes
    .\New-SizedFile.ps1 C:\Users\Yzöwl\Dummy.txt 698
     
    Create Dummy.txt with size 86 KB
    .\New-SizedFile.ps1 C:\Users\Yzöwl\Dummy.txt 86KB
     
    Create Dummy.txt with size 20 MB
    .\New-SizedFile.ps1 C:\Users\Yzöwl\Dummy.txt 20MB
     
    Create Dummy.txt with size 3 GB
    .\New-SizedFile.ps1 C:\Users\Yzöwl\Dummy.txt 3GB

     

     

    Tks for your help. Let me say about my goal.

    I'm creating a multiboot which contain: winpe, ubuntu (live, not install to harddisk). It will work on UEFI and LEGACY.

    -WinPE is thin ver, and I create ToolsforPE.ISO then after boot to WinPE, I use .bat to mount it. (this is reason why I create a topic about For /f command and solved with Jaclaz's help)

    -with uefi computer, i need .efi file to boot then i need a .bat which mount EFI partition then copy some .efi to it, then chainload them by grub2. this is reason why i create a topic about order partition

    -ubuntu live and persistence need a file call: casper-rw with ext2 format. And i must create a "empty" file by fsutil then use mke2fs convert it. since fsutil create a file base on kb in size bytes in size, then i get problems with .bat because it limit number. Jaclaz give a link to download useful tool which create exactly size in Gib.

     

    Because I use .bat for all of 3 task above then I do not know if i can use PowerShell in .bat or not.

  18. Hi,

    I repost this to get some advices from you.

    Cdob's method seem work in most case, even if user run .bat from WinPE (not yet tested)

    But for safety reason, i just want user run .bat from real windows.

    I found a useful reg key to check if user boot from winpe or not

     

    HKLM\SYSTEM\Controlset001\Control\SystemStartOptions

     

    If boot from winpe, that say Win7PE then it will show ..\Win7PE.Wim

    so i use reg query command then use findstr /r "WIM", if not error then user boot from winpe.

    Since LiveXP use .wim boot method then I think this will work with LiveXP, too.

    But just to make sure, I want to ask you if it's good method or we can use another method to detect. Tks

  19.  

    And how can you know these tool. It seem quite "hidden" on internet. I try googled many times but not found some tools like this.

     

    Would you think that the title of The Finder was arbitrary? :dubbio:

    (please note the capital T and F :yes:)

     

    And of course, it's a state secret ...:

    http://www.literaturepage.com/read.php?titleid=man-in-the-iron-mask&abspage=294

    :w00t::ph34r:

     

     

     

    jaclaz

     

    Oh, I see. You're "google" guy.

    So if i can not found something on internet, may i will ask for your help :thumbup. Thanks again for your help in almost my topic.

    God bless  you :)

  20. The tool I normally use to create a 00's file is fsz (part of the dsfok toolkit), but still it uses bytes as argument.

     

    Technically you can even use a loop in plain batch, using the powers of 2 (as long as you want sizes that are multiples), but since you need anyway a third party utility (mke2fs), you could use a file creating one that accepts suffixes like K, M or G.

    Here:

    http://www.henrynestler.com/colinux/tools/

    http://www.henrynestler.com/colinux/tools/file-utils-mingw-bin-stripped.zip

    meet mkfile.exe :

    C:\appoggio\Filetests>mkfileUsage: mkfile [-s] [-r] [-k] [-m] [-g] filename filesizewhere filename is the name of the file to createfilesize if the size of the file.-s means create a sparse file ( only supported on ntfs 5 or greater )-r means resize an existing file-k -m -g means the size is in KB, MB, or GB

    jaclaz

    Greate. I'll try it now. Tks for your useful tool.

    And how can you know these tool. It seem quite "hidden" on internet. I try googled many times but not found some tools like this.

  21. There is a limit (actually more than one) in batch math.

    Besides the fact that only integers are accepted, there is a limit which is 0x7FFFFFFF, i.e. 2,147,483,647.

    Numbers bigger than that are NEGATIVE numbers, i.e.:

    SET /A max=0x80000000

    will output:

    -2147483648

    and

    SET /A max=0xFFFFFFFF

    will output:

    -1

     

    But if you want a file exactly 1 Gb (a "real" one, what to be "politically correct" we should call a Gib), i.e. 1024x1024x1024=1,073,741,824

    There should be no problem.

     

    Otherwise you will need a trick or two (or more).

    Check my multiply.cmd:

    http://reboot.pro/topic/2986-yacbfc-dec2hexcmd-and-hex2deccmd/

     

    The file you create with fsutil is not actually "blank", it is filled of 00's:

    https://technet.microsoft.com/en-us/library/cc788058.aspx

     

    Then, in order to have an EXT2 filesystem applied to it you need a tool capable of formatting a file with that filesystem or capable to format a volume once you have mounted it in a virtual disk driver.

    The Ext2dfsd project:

    https://sourceforge.net/projects/ext2fsd/

    does contain a mkefs2.exe, a Windows port of the mke2fs Linux utility (through Cygwin), which may (or may not) do what you need.

    mke2fs is not exactly a tool with a "friendly" syntax, but usually it auto-calculates all parameters, so that something *like*:

    set CYGWIN=nodosfilewarningmke2fs.exe <full path to the image file>set CYGWIN=

    should work :unsure:

     

    jaclaz

     

    Tks for your explain, Jaclaz.

    About command to make a ext2 file, i found it from RMPrepUSB (steve use fsutil vs mke2fs, too, but not extactly size). Also i don't want use RMPrepUSB just create a ext2 file. Since we have fsutil and light weight tool mke2fs.exe we only need one thing, a .bat file to do that.

     

    I found that, we can create a "empty" file (not sure) with dd for windows. But still it is not exactly size as we want.

     

    I will try your .bat from reboot then see if i can use some code from it for my case.

    Tks

×
×
  • Create New...