提取网络配置文件并仅在txt文件中显示网络配置文件描述 [英] Extracting Network Profiles and displaying only Network Profile description in txt file

查看:88
本文介绍了提取网络配置文件并仅在txt文件中显示网络配置文件描述的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对批处理脚本非常陌生,必须使用控制台来查询注册表以获取网络配置文件描述,并且仅将描述数据输出到txt文件. 我正在使用for/f循环来执行此操作. 我首先通过reg来查询整个密钥,以便它列出网络配置文件的每个子密钥,并将其存储在文本文档中.然后,对于/f这个文本文件,它使用标记将子项名称仅提取出来,并将其存储为变量. 然后,我使用该变量重新查询各个关键字的描述名称,并将其输出到另一个仅显示网络配置文件描述的文本文件.下面是我的批处理脚本.

I am very new to batch scripting and have to use console to interrogate Registry for network profile description and output only the description data to a txt file. I am using a for /f loop to do this. I first reg query the whole key so it lists every sub key for network profiles and stores this in a text document. I then for /f this text file to extract out only the subkey name using tokens to store this as a variable. I then use the variable to reg query the individual keys for the Description name and output this to another text file which should display only the Network profile description. Below is my batch script.

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
        )
       )

我首先注意到的是skip = 1无效,并查看每一行. 由于这不起作用,因此不会提取正确的数据以放入reg查询中.我尝试使用不同的令牌,没有跳过,有跳过,有delims(它无法识别).我已经为此工作了几个小时,简直无法使它正常工作.这可能很简单,但是我找不到解决方法.

The first think I notice is the skip=1 doesn't work and look at every line. As this doesn't work it doesn't extract the correct data to place into the reg query. I have tried with different tokens, without skip, with skip, with delims (which it didn't recognise). Ive been working on this for hours and simply cant get it to work. This is probably simple but I cant find a way around this.

推荐答案

下面是一个简单的示例,该示例应该输出一个文件,其中提供每个GUID和描述以及正在运行的脚本.

Here is an quick example which should output a file providing each GUID and Description alongside your running script.

@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

由于对这些键的限制,您可能需要右键单击并以管理员身份运行.

You will probably need to right-click and run as Administrator due to resrictions on those keys.

这篇关于提取网络配置文件并仅在txt文件中显示网络配置文件描述的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆