@xinso i found a solution but it's not working correctly as the last character returned from the WMIC command is a carriage return (<CR>) character, give me some more time i'll try to fix this. Spoiler (this isn't working but the output is correct and similar to what you want) Code: for /f "skip=1 tokens=1,2 delims= " %%A in ('"wmic nic where (NetConnectionID='Tunngle') get NetConnectionID,PNPDeviceID /format:texttablewsys"') do ( echo "[%%~A]" echo "{%%~B}" ) output: (see how the last 2 lines are completely weird!, they should be empty) Code: "[Tunngle]" "{ROOT\NET\0000}" ]" "{}" EDIT: ok try this one and provide the output, i'll try to find a cleaner solution: Code: for /f "skip=1 tokens=1,2 delims= " %%A in ('"wmic nic where %IX% get NetConnectionID, PNPDeviceID /format:texttablewsys"') do ( set "first=%%~A" set "second=%%~B" goto :outOFloop ) :outOFloop echo: echo "%first%" echo "%second%" echo: EDIT 2: the red colored syntax is critical and shouldn't be skipped/abandoned
OK. I'll test it. And here is what I found: wmic nic where ServiceName='tap0901' get Index pause Code: Index 0 wmic nic where Index=0 get NetConnectionID, PNPDeviceID /%FL% pause Code: NetConnectionID=TAP-9.0.2.1 PNPDeviceID=ROOT\NET\0000 for /f "tokens=2 delims==" %%A in ('"wmic nic where Index=0 get NetConnectionID, PNPDeviceID /%FL%"') do (echo %%A) pause Code: TAP-9.0.2.1 ROOT\NET\0000
Wk-952, one more step to success, please: Code: :NO :-------------------------------------- wmic nic get Index /%FL% | findstr /i Index > "%temp%\Be.txt" if defined Y (call:DT "%RT%\%DIR%\%INF%") else (call:CT "%KQ%\%OA%\OemVista.inf") wmic nic get Index /%FL% | findstr /i Index > "%temp%\Af.txt" for /f "delims=" %%A in ('findstr /v /g:"%temp%\Be.txt" "%temp%\Af.txt"') do (set IX=%%A) :-------------------------------------- echo %IX% pause wmic nic where %IX% get NetConnectionID, PNPDeviceID /format:texttablewsys pause for /f "skip=1 tokens=1,2 delims= " %%A in ('"wmic nic where %IX% get NetConnectionID, PNPDeviceID /format:texttablewsys"') do ( set "first=%%~A" set "second=%%~B" goto :outOFloop ) :outOFloop echo: echo "%first%" echo "%second%" pause Code: Index=0 Press any key to continue . . . NetConnectionID PNPDeviceID 乙太網路 2 ROOT\NET\0000 Press any key to continue . . . "乙太網路" "2" Press any key to continue . . . If NetConnectionID=Local Area Connection 2, then the result would be "Local" "Area" We want "Local Area Connection 2" and "ROOT\NET\0000".
@xinso try this one: Code: for /f "tokens=2,3 delims=," %%A in ('"wmic nic where %IX% get NetConnectionID, PNPDeviceID /format:csv"') do ( set "first=%%~A" set "second=%%~B" ) echo "%first%" echo "%second%"
The Value is correct, and install a TAP, but did not turn it to TAP-9.0.2.1 Code: Index=0 Press any key to continue . . . NetConnectionID PNPDeviceID 乙太網路 2 ROOT\NET\0000 Press any key to continue . . . 乙太網路 2 ROOT\NET\0000 Press any key to continue . . . TAP-9.0.2.1 install did not complete successfully. Press any key to continue . . .
@xinso could you please provide the commands you used so i can see or figure out what's the problem ?
Yes, Wk-952. Code: :NO :-------------------------------------- wmic nic get Index /%FL% | findstr /i Index > "%temp%\Be.txt" if defined Y (call:DT "%RT%\%DIR%\%INF%") else (call:CT "%KQ%\%OA%\OemVista.inf") wmic nic get Index /%FL% | findstr /i Index > "%temp%\Af.txt" for /f "delims=" %%A in ('findstr /v /g:"%temp%\Be.txt" "%temp%\Af.txt"') do (set IX=%%A) :-------------------------------------- echo %IX% pause wmic nic where %IX% get NetConnectionID, PNPDeviceID /format:texttablewsys pause for /f "tokens=2,3 delims=," %%A in ('"wmic nic where %IX% get NetConnectionID, PNPDeviceID /format:csv"') do ( set "CI=%%~A" set "DI=%%~B" ) echo %CI% echo %DI% pause echo:netsh interface set interface name="%CI%" newname="%TP%" >nul 2>&1 "%KQ%\%OA%\devcon" sethwid @%DI% := =%TP% >nul 2>&1 goto:eof Edit: Wk-952, It seems that I made a mistake Code: echo:netsh interface set interface name="%CI%" newname="%TP%" >nul 2>&1 Should be Code: netsh interface set interface name="%CI%" newname="%TP%" >nul 2>&1 Edit: Yes. It is working now Code: TAP-9.0.2.1 has been successfully installed with V9.00.00.9. Code: Activating Windows(R), Enterprise edition (81671aaf-79d1-4eb1-b004-8cbbe173afea) ... Product activated successfully. Name: Windows(R), Enterprise edition Description: Windows(R) Operating System, VOLUME_KMSCLIENT channel Partial Product Key: MKKG7 License Status: Licensed Volume activation expiration: 259200 minute(s) (180 day(s)) Configured Activation Type: KMS Most recent activation information: Key Management Service client information Client Machine ID (CMID): 572f8c9c-7819-4bf1-bacc-ba5d11d38c36 Registered KMS machine name: 9.0.2.0:1688 KMS machine IP address: 9.0.2.0 KMS machine extended PID: 06401-00206-271-158280-03-1028-9600.0000-2592014 Activation interval: 120 minutes Renewal interval: 10080 minutes KMS host caching is enabled Code: ROOT\NET\0002 : Removed 1 device(s) were removed. TAP-9.0.2.1 has been uninstalled successfully. You've done it again, my dear friend.
You've done it again, my dear friend. Now I can loudly call it "Final". Yeah. Thanks a lot. Edit: But I used it as per Code: for /f "tokens=2,3 delims=," %%A in ('"wmic nic where %IX% get NetConnectionID, PNPDeviceID /format:csv"') do (set CI=%%A&set DI=%%B) Will it be Alright?
yes but wrap the variable and its value in quotes like this: Code: for /f "tokens=2,3 delims=," %%A in ('"wmic nic where %IX% get NetConnectionID, PNPDeviceID /format:csv"') do (set "CI=%%A"&set "DI=%%B") just in case the value contains spaces or special characters, and don't worry those wraping quotes won't be appended to the variable
I see. And what if I already had quotes for the next command? Is it still necessary to quote the Variable? Code: netsh interface set interface name="%CI%" newname="%TP%" >nul 2>&1
yep, the wrapping quotes in the set command are necessary, as they make sure that spaces and special characters do not crash the for loop and also as i told you they do not affect the variable contents (they're not appended). The quotes that you used in the next command is an excellent coding practice, i recommend keeping the quotes in the set command and also in this next command (and probably the other next commands).
Yes, Wk-952, I'd renew as Code: for /f "tokens=2,3 delims=," %%A in ('"wmic nic where %IX% get NetConnectionID, PNPDeviceID /format:csv | findstr /i ROOT"') do (set "CI=%%A"&set "DI=%%B") netsh interface set interface name="%CI%" newname="%TP%" >nul 2>&1 "%KQ%\%OA%\devcon" sethwid @%DI% := =%TP% >nul 2>&1 Thanks, mate. Edit: I've renewed as Code: :YES :-------------------------------------- :Thanks to Wk-952's instruction for /f "tokens=7 delims=\ " %%A in ('reg query ^^^"%PH%\^^%%SystemRoot^^%%/system32/DRIVERS/tap0901.sys^^^" /v Source') do %E0% (set DIR=%%A) for /f "delims=" %%A in ('"dir /b %RT%\%DIR% 2^>nul | findstr /i inf"') do %E0% (set INF=%%A) if defined INF (if exist "%RT%\%DIR%\tap0901.sys" set Y=1) else (call:NF) :NO :-------------------------------------- wmic nic get Index /%FL% | findstr /i Index > "%temp%\Be.txt" if defined Y (call:DT "%RT%\%DIR%\%INF%") else (call:CT "%KQ%\%OA%\OemVista.inf") wmic nic get Index /%FL% | findstr /i Index > "%temp%\Af.txt" for /f "delims=" %%A in ('findstr /v /g:"%temp%\Be.txt" "%temp%\Af.txt"') do (set IX=%%A) :-------------------------------------- :Thanks to Wk-952's instruction for /f "tokens=2,3 delims=," %%A in ('"wmic nic where %IX% get NetConnectionID, PNPDeviceID /format:csv | findstr /i ROOT"') do (set "CI=%%A"&set "DI=%%B") netsh interface set interface name="%CI%" newname="%TP%" >nul 2>&1 "%KQ%\%OA%\devcon" sethwid @%DI% := =%TP% >nul 2>&1 goto:eof
@ Wk-952 I have to quit on this Code: :NO :-------------------------------------- wmic nic get Index /%FL% | findstr /i Index > "%temp%\Be.txt" if defined Y (call:DT "%RT%\%DIR%\%INF%") else (call:CT "%KQ%\%OA%\OemVista.inf") wmic nic get Index /%FL% | findstr /i Index > "%temp%\Af.txt" for /f "delims=" %%A in ('findstr /v /g:"%temp%\Be.txt" "%temp%\Af.txt"') do (set IX=%%A) :-------------------------------------- for (the sake of "echo was off" resulting in %IX% (Index) was not revealed) Code: NetConnectionID - Invalid alias verb. TAP-9.0.2.1 install did not complete successfully. Note: This works while there are few TAPs. And now I managed this way Code: :TAP :-------------------------------------- "%KQ%\%OA%\devcon" hwids @ROOT\NET\* 2>nul | findstr /i %TP% >nul&&%E0% (goto:FINISH) :-------------------------------------- wmic nic get ServiceName 2>nul | findstr /i tap0901 >nul 2>&1 if %errorlevel% EQU 0 (call:YES) else (set N=1&call:NO) Code: :NO :-------------------------------------- if defined N (echo 0 > "%temp%\Be.txt") else (wmic nic where ServiceName='tap0901' get Index /%FL% 2>nul | findstr /i Index > "%temp%\Be.txt") if defined Y (call:DT "%RT%\%DIR%\%INF%") else (call:CT "%KQ%\%OA%\OemVista.inf") wmic nic where ServiceName='tap0901' get Index /%FL% 2>nul | findstr /i Index > "%temp%\Af.txt" for /f "delims=" %%A in ('findstr /v /g:"%temp%\Be.txt" "%temp%\Af.txt"') do (set IX=%%A) Code: TAP-9.0.2.1 has been successfully installed with V9.00.00.9. Regards
@xinso after which command you got this error also if possible please turn on echo before this command: Code: NetConnectionID - Invalid alias verb. TAP-9.0.2.1 install did not complete successfully. i'm very sorry i didn't get you properly, but where is the issue in this code it seems correct in terms of syntax, so why are you getting the previously mentioned error?
I have no idea about this. One TAP, OK. Two TAPs, OK. But crashed when there were some ten TAPs. By this time, the %IX% was unable to be shown (since echo has been off). Turn echo on, yet to no avail. Thank you so much for helping me a lot. I've been more than happy with your kind and efficient instructions.
this means that the for loop responsible for creating the variable %IX% was not executed properly (executed with errors), Code: :NO ... for /f "delims=" %%A in ('findstr /v /g:"%temp%\Be.txt" "%temp%\Af.txt"') do (set IX=%%A) could you please reproduce the error (install many ten TAPs) and provide a full output of the 2 files Be.txt and Af.txt ? EDIT: very sorry, i can't do that since i have very limited knowledge in programming languages. EDIT 2: please also make sure echo is turned on for the part/sub-routine NO) that has the problem.
Yes. Sure. Thank you! Please wait few Secs. Here it goes Code: :NO :-------------------------------------- wmic nic get Index /%FL% | findstr /i Index > "%temp%\Be.txt" type "%temp%\Be.txt" pause if defined Y (call:DT "%RT%\%DIR%\%INF%") else (call:CT "%KQ%\%OA%\OemVista.inf") wmic nic get Index /%FL% | findstr /i Index > "%temp%\Af.txt" type "%temp%\Af.txt" pause for /f "delims=" %%A in ('findstr /v /g:"%temp%\Be.txt" "%temp%\Af.txt"') do (set IX=%%A) echo %IX% pause Code: Index=0 Index=1 Index=2 Index=3 Index=4 Index=5 Index=6 Index=7 Index=8 Index=9 Index=10 Index=11 Index=12 Index=13 Index=14 Index=15 Press any key to continue . . . Index=0 Index=1 Index=2 Index=3 Index=4 Index=5 Index=6 Index=7 Index=8 Index=9 Index=10 Index=11 Index=12 Index=13 Index=14 Index=15 Index=16 Press any key to continue . . . ECHO is off. Press any key to continue . . . NetConnectionID - Invalid alias verb. TAP-9.0.2.1 install did not complete successfully. Press any key to continue . . .
@xinso ok give me some time, this is gonna take long, please wait for an "edit" in this post. EDIT: the solution is here: http://forums.mydigitallife.net/thr...ut-batch-files?p=949248&viewfull=1#post949248
Neither do I. But we can do it well following instructions by the Master. Would you mind having a go for it?