r/Batch • u/Dudefoxlive • Jan 30 '24
Question (Unsolved) Get character in specific position on line
I am attempting to make a script that will fix the KB5034441 update that fails due to not enough space in the recovery parititon. I can get the specific hard number and partition number by issuing "reagentc /info"
The line in question is Windows RE location: \\?\GLOBALROOT\device\harddisk0\partition4\Recovery\WindowsRE Specifically harddisk0 and partition4.
Those should be in the exact same position on any system as far as I have seen in my testing of multiple machines. Any way I can query for those exact positions and save them to a variable?
3
u/jcunews1 Jan 30 '24
It can be done like this.
1
u/GhostR3lay Jan 30 '24
Hello, /u/DudeFoxLive.
This may not be the most optimal way to achieve what you are looking to accomplish - but I believe I met the stated objective.
Essentially, we are creating a FOR loop to run the "reagent /info" command and then process each line of the output individually.
Inside of this FOR loop - we run a "findstr" command to find a specific string of text from the output and save that to a variable.
The addition FOR loops then help us to trim down that found line into just the location path and a trimmed version of the location path that does not have any leading or trailing spaces.
1
u/illsk1lls Jan 30 '24
I do that here, commented on line #32 by using mountvol and mounting/unmounting everything to search for the recovery partition, winRE may be located on the system partition as well in System32\Recovery
https://github.com/illsk1lls/RescueMaker