I heed help to create batch file. How to take characters from string and place them to variable?
-
Hello, there is a task that I want to automate. I need to update program on some PCs (about 10-15). So I need to uninstall old program version and install new one. And I want to make Batch file for this. At first I want to find old App that installed on the system and uninstall it: I have found EXE file that can help me - UninstallW.exe. And bathch start with: @echo off uninstallW /w /a > 1.txt SO i get file with all installed programs, like: .......... {CFEF48A8-BFB8-3EAC-8BA5-DE4F8AA267CE}… Microsoft .NET Framework 4 Multi-Targeting Pack (version 4.0.30319) {EB879750-CCBD-4013-BFD5-0294D4DA5BD0}… Apple Application Support (version 2.1.7) {ED784556-66AA-3F17-9B58-7246ACB5C7E4}… Microsoft Visual Basic 2010 Express - ENU (version 10.0.40219) {ED784556-66AA-3F17-9B58-7246ACB5C7E4}… {ED784556-66AA-3F17-9B58-7246ACB5C7E4}… ........ To find the string that I need, I use: for /f "delims=" %%a in ('findstr /C:"My DICOM Viewer" 1.txt') do set key=%%a echo %key% And I will get string like this saved in "key" variable: {5A3C1721-F8ED-11E0-8AFB-B8AC6F97B88E}… My DICOM Viewer (version 6.1.0.5001) Then to unistall Program - I need only {5A3C1721-F8ED-11E0-8AFB-B8AC6F97B88E}. So my question is - how can I get(extract) value in the { ---- } and save it to the new variable like "key1" ? Thank you.
-
Answer:
I think this may help you http://www.dostips.com/DtTipsStringManipulation.php Additional Some times I got it difficult to this straight from dos due I'm not an expert. I use combination of dos and vbscript and work fine. For the above i have make a script for you. lets start 1)Create the VBSCRIPT copy the following codes and paste it in a notepad 'Start code ========== inputfile = Wscript.arguments.Item(0) query = Wscript.arguments.Item(1) Const ForReading = 1 Set objFSO = CreateObject("Scripting.FileSystemObject… set objOFI= objFSO.OpenTextFile(inputfile, ForReading) AllLine = objOFI.ReadAll arrLines = Split(AllLine , vbcrlf) For i = 0 to Ubound(arrLines) if instr(arrLines(i), query) > 0 then Result = arrLines(i) end if Next strstr = instr(Result, "{") strend = instr(Result, "}") strlng = (strend - strstr) + 1 outputLine = mid(Result, strstr, strlng ) wscript.echo outputLine 'end code ========== 2) Save the file as vbsript click file save as save as type must be : all files in Filename: <YourFilename.vbs> (example: TextQuery.vbs) please omit spaces in any file name when you are programming, my preference is Camel Notation 3) incorporate the vbscript in your code - replace your dos code. Make a backup off your batch file for in case off's) for /f "delims=" %%a in ('findstr /C:"My DICOM Viewer" 1.txt') do set key=%%a echo %key% -with set vbsscript="C:\TextQuery.vbs" set filepath="C:\test.txt" set queryitem="My DICOM Viewer" for /f %%A in ( ' cscript //nologo %vbsscript% %filepath% %queryitem% ' ) do set key1=%%A 4) adjust the dos code you just replace with the correct vbscript full path name, full file path name to be query and the item to be query. do not omit the quotes 5) Test your code please note that the output of the vbscript will be defined as variable key1. To change it, change the variable name replace key1 in the last part of the dos code ====> % ' ) do set key1=%%A If you find some error contact me at [email protected]
Eugeny at Yahoo! Answers Visit the source
Related Q & A:
- How to skip the input in batch file?Best solution by Stack Overflow
- How to run an interactive batch file on windows from a service?Best solution by Stack Overflow
- How to Create a file in "my documents" folder?Best solution by Stack Overflow
- How to create jar file from command line?Best solution by Stack Overflow
- How to make a batch file copy itself?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.