gpt4 book ai didi

parsing - 需要帮助编写批处理文件来读取带有空分隔符的 MS Access .ldb 锁定文件

转载 作者:行者123 更新时间:2023-12-03 03:32:32 25 4
gpt4 key购买 nike

我正在尝试创建一个批处理文件来读取 Microsoft Access .ldb 锁定文件。锁定文件包含计算机名称和用户名的列表。我想提取计算机名称并最终根据外部命令运行它们。

批处理文件的格式是单行(1)计算机名称(2) NULL 字符(十六进制 00)(3) 约20个车位(4)用户名(5) NULL 字符(6)约20个车位重复。

Notepad++ 中的示例,其中 (NUL) 代表十六进制 00:

COMPUTER0123(NUL)                     Admin(NUL)                     COMPUTER0507(NUL)                     Admin(NUL)

I've tried several methods using FOR to read the file but can't get past the first computer name.

setlocal EnableDelayedExpansionset file=database.ldbfor /F %%a in ('type %file%') do (    echo %%a    )

For for most of my Access databases, the user name in the file is Admin. I've been able to use FIND to tell me how many occurrences of "Admin" are in the file (plus 1).

for /f "delims=" %%n in ('find /c /v "Admin" %file%') do set "len=%%n"
set "len=!len:*:=!"
echo %len% (minus 1) computer names to process
<%file% (
for /l %%l in (1 1 !len!) do (
set "line="
set /p "line="
echo(!line!)
)
)

遍历找到的行不起作用,可能是因为文件中只有一行(没有回车符)。

我想找到一个适用于 Windows XP 标准安装的解决方案。

<小时/>

收到接受的答案后,我将其合并到我在下面发布的批处理文件中。我将该文件命名为 ShowUsersInLDB.bat 并将其放入我的 SendTo 文件夹中。

@echo off
::===================================================================
:: Put this in your SendTo folder and it will let you right-click
:: on an Access .ldb/.laccdb lock file and tell you the computer
:: names that have opened the database.
::
:: After the computer names are shown, this will prompt you to
:: search for the user names associated with each computer. This
:: depends upon finding a 3rd party file named NetUsers.exe in
:: the user profile folder. Feel free to change the path if you
:: want to store the file in another location.
::
:: NetUsers.exe can be downloaded from here: http://www.optimumx.com/downloads.html#NetUsers
::
:: Notes:
:: 1) Keep in mind that sometimes after people leave the database
:: the lock file still shows their computer name. Don't jump
:: to conclusions.
:: 2) NetUsers.exe seems to report all users who have logged on
:: to the computer and not logged off, including services.
:: If you aren't familiar with your user names or your users are
:: sharing remote desktops/Citrix/Terminal Services, you may have
:: to guess who might have created the lock entry.
::
:: Installation:
:: You may find a batch file named Install_UsersInLDB.bat that will
:: copy this file to the SendTo folder and the NetUsers.exe file to
:: the user profile (or a place you define).
::
:: Ben Sacherich - March 2014
:: Please let me know if you have any ideas for improvements.
::===================================================================

setlocal
set file="%1"

:: Make sure the file has a compatible extension.
if "%~x1"==".ldb" goto :ExtensionIsValid
if "%~x1"==".laccdb" goto :ExtensionIsValid

echo.
echo "%~n1%~x1" is not the correct file type.
echo.
pause
goto :End

:ExtensionIsValid
echo The Access "%~n1%~x1" file contains
echo the following computer names:
echo.
set "compNameLine=1"
for /f %%A in ('more "%file%"') do (
if defined compNameLine (
echo %%A
set "compNameLine="
) else set "compNameLine=1"
)

echo.
echo Are you ready to look up the user names on each computer?
pause

set "compNameLine=1"
for /f %%A in ('more "%file%"') do (
if defined compNameLine (
::echo %%A
"%userprofile%\netusers" \\%%A
set "compNameLine="
) else set "compNameLine=1"
)

echo.
echo -- Validation finished at %time%
pause
:End
exit

最佳答案

CMD.EXE 通常不能很好地处理 NUL 字节。但有一些外部命令可以处理 NUL 字节。

您还必须担心“线”的长度。 CMD.EXE 不喜欢长度超过 8191 字节的行。

我认为你最好的选择是“更多”,因为它将 NUL 转换为新行。

以下内容应回显您的计算机名称。

@echo off
setlocal
set "file=database.ldb"
set "compNameLine=1"
for /f %%A in ('more "%file%"') do (
if defined compNameLine (
echo %%A
set "compNameLine="
) else set "compNameLine=1"
)

关于parsing - 需要帮助编写批处理文件来读取带有空分隔符的 MS Access .ldb 锁定文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13845555/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com