2016-09-08 48 views
1

我對批處理腳本非常陌生,必須使用控制檯來詢問Registry以獲取網絡配置文件描述,並只將描述數據輸出到txt文件。 我正在使用for/f循環來執行此操作。 我首先註冊查詢整個密鑰,以便列出網絡配置文件的每個子密鑰並將其存儲在文本文檔中。然後我/ f這個文本文件只使用標記提取出這個子鍵的名字,將它存儲爲一個變量。 然後,我使用該變量來註冊查詢描述名稱的各個關鍵字,並將其輸出到另一個僅顯示網絡配置文件描述的文本文件。以下是我的批處理腳本。提取網絡配置文件並僅顯示txt文件中的網絡配置文件描述

Echo Required to skip line for processing >>%~dp0\1SSID.txt 
REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\Profiles" /s /v Description >>%~dp0\1SSID.txt 

setlocal enableDelayedExpansion 
    rem get each key from 1SSID.txt 
    for /f "usebackq skip=1 tokens=1,2" %%i in ("%~dp0\1SSID.txt") do (
     echo %%i %%j>>%~dp0\2Processingstage.txt 

    rem skip the first line and grab tokens 3 from the second line to show description and desription name 
    for /f "usebackq skip=1 tokens=3" %%k in (`reg query "%%I %%j" /v Description`) do set "Description=%%l 
     echo Network Description - %%l >>%~dp0\3SSIDoutput.txt 
     ) 
     ) 

先覺得我注意到的是跳過= 1不工作,並期待在每行。 由於這不起作用,它不會提取正確的數據以放入reg查詢。我試過了不同的標記,沒有跳過,跳過了,但是有了分隔符(它沒有識別)。我一直在這個工作幾個小時,只是不能讓它工作。這可能很簡單,但我找不到解決辦法。

+0

'skip = 1'當然不適用於每一行,它定義爲跳過文本的* first *行;它'做**沒有**定義跳過第一個標記... – aschipfl

+0

不知道你想要輸出什麼,這似乎是一個漫長的取得一些註冊表數據的方式。如果您發佈了一個註冊查詢輸出示例,也許有一些配置文件解釋您需要什麼。 – Compo

+0

看看這個,並告訴我,如果它可以幫助你或沒有,==> http://stackoverflow.com/questions/36715753/is-it-possible-to-change-the-wifi-hosted-network-settings - 使用-CMD-BAT-VBS – Hackoo

回答

0

從這個線程:Wi-Fi SSID detail

,我不知道這是否代碼工作過英語的機器或沒有,因爲我剛剛試了一下到現在爲止,我的法國的機器上。 所以,只要給一個嘗試,並告訴我的結果:

@echo off & setlocal enabledelayedexpansion & color 0A 
Title %~n0 to get SSID With details 
:::::::::::::::::::::::::::::::::::::::::::: 
:: Automatically check & get admin rights :: 
:::::::::::::::::::::::::::::::::::::::::::: 
Set TmpLogFile=%tmp%\TmpLog.txt 
If Exist %TmpLogFile% Del %TmpLogFile% 
REM --> Check for permissions 
Reg query "HKU\S-1-5-19\Environment" >%TmpLogFile% 2>&1 
REM --> If error flag set, we do not have admin. 
if '%errorlevel%' NEQ '0' (
Echo. 
ECHO      **************************************** 
ECHO      ^| Running Admin shell... Please wait...^| 
ECHO      **************************************** 

    goto UACPrompt 
) else (goto gotAdmin) 

:UACPrompt 
    echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs" 
    set params = %*:"="" 
    echo UAC.ShellExecute "cmd.exe", "/c ""%~s0"" %params%", "", "runas", 1 >> "%temp%\getadmin.vbs" 

    "%temp%\getadmin.vbs" 
    del "%temp%\getadmin.vbs" 
    exit /B 

:gotAdmin 
:::::::::::::::::::::::::::: 
::START 
:::::::::::::::::::::::::::: 
Set "TmpLog=%~dp0%~n0_Tmp.txt" 
Set "Log=%~dp0%~n0.txt" 
If Exist "%TmpLog%" Del "%TmpLog%" 
If Exist "%Log%" Del "%Log%" 
rem Populate the array 
Set i=0 
for /f "skip=1 tokens=2 delims=:" %%a in ('netsh wlan show profiles ^|find /i "Profil"') do (
    set /A i+=1 
    set "list[!i!]=%%a" 
) 
set SSID=%i% 
rem Display array elements for SSID List 
cls 
for /L %%i in (1,1,%SSID%) do (
    echo(
    echo SSID number %%i: "!list[%%i]:~1!!" 
    echo(
) 
pause 
rem Display array elements for SSID List with details 
cls 
for /L %%i in (1,1,%SSID%) do (
    echo(
    echo SSID number %%i: "!list[%%i]:~1!!" 
    echo(
    netsh wlan show profiles "!list[%%i]:~1!!" key=clear 
    netsh wlan show profiles "!list[%%i]:~1!!" key=clear >> "%TmpLog%" 
) 
Cmd /U /C Type "%TmpLog%" > "%Log%" 
If Exist "%TmpLog%" Del "%TmpLog%" 
Start "" "%Log%" 
pause 
exit /b 
0

下面是一個簡單的例子,其應該輸出爲每個GUID和說明一起跑步的腳本文件。

@Echo Off 
SetLocal EnableExtensions DisableDelayedExpansion 
(Set k=HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\Profiles) 
For /F "Delims==" %%A In ('Set GUID[ 2^>Nul') Do Set "%%A=" 
Set "i=101" 
For /F "EOL=E Tokens=1,2*" %%A In ('Reg Query "%k%" /S /V Description') Do (
    If "%%~nB" NEq "%%~B" (Call Set "GUID[%%i:*1=%%]=%%~nB") Else (
     Call Call Set GUID[%%i:*1=%%]="%%%%GUID[%%i:*1=%%]%%%%","%%C" 
     Set/A i+=1)) 
If %i% NEq 101 (>"%~dp0NetProfs.log" 2>Nul Set GUID[) 
EndLocal 
Exit/B 

您可能需要右鍵單擊並以管理員身份運行,原因是這些密鑰上的殘留。