需要帮助编写一个批处理文件来读取MS Access .ldb锁定文件与空分隔符(Need help writing a batch file to read a MS Access .ldb lock file with null delimiters)
我正尝试创建一个批处理文件来读取Microsoft Access .ldb锁定文件。 锁定文件包含计算机名称和用户名称的列表。 我想提取计算机名称并最终针对外部命令运行它们。
(1)计算机名(2)空字符(十六进制00)(3)大约20个空格(4)用户名(5)空字符(6)大约20空间重复。
Notepad ++中带有
(NUL)
表示十六进制00的示例:COMPUTER0123(NUL) Admin(NUL) COMPUTER0507(NUL) Admin(NUL)我已经尝试了几种使用
FOR
读取文件的方法,但无法通过第一台计算机名称。setlocal EnableDelayedExpansion set file=database.ldb for /F %%a in ('type %file%') do ( echo %%a )对于我的大部分Access数据库,文件中的用户名是
Admin
。 我已经能够使用FIND
来告诉我文件中出现了多少次“Admin”(加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
I am trying to create a batch file to read a Microsoft Access .ldb lock file. The lock file contains a list of computer names and user names. I want to extract the computer names and eventually run them against an external command.
The format of the batch file is a single row with (1) a computer name (2) a NULL character (Hex 00) (3) approximately 20 spaces (4) the user name (5) a NULL character (6) approximately 20 spaces repeating.
Example in Notepad++ with
(NUL)
representing Hex 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 EnableDelayedExpansion set file=database.ldb for /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 useFIND
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!) ) )
Iterating through the found lines doesn't work, probably because there only is one line in the file (no carriage returns).
I would like to find a solution that would work with a standard install of Windows XP.
After receiving an accepted answer, I combined that into a batch file that I'm posting below. I named the file
ShowUsersInLDB.bat
and put it in my SendTo folder.@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
原文:https://stackoverflow.com/questions/13845555
最满意答案
如果可以的话,使用编译好的lambda,速度更快。
Use a compiled lambda if you can, its MUCH faster.
相关问答
更多-
如果可以的话,使用编译好的lambda,速度更快。 https://vagifabilov.wordpress.com/2010/04/02/dont-use-activator-createinstance-or-constructorinfo-invoke-use-compiled-lambda-expressions/ Use a compiled lambda if you can, its MUCH faster. https://vagifabilov.wordpress.com/2010/04 ...
-
根本区别在于Unity(或任何DI容器)实际上可以管理您的依赖项。 Activator.CreateInstance只是创建实例。 如果您有一些具有构造函数参数的类型而某些类型没有,那该怎么办? 或者你想要设置的属性? 容器将递归对象图并确定应将哪些值放入这些构造函数参数或属性中。 Activator.CreateInstance不会这样做。 容器管理对象的生命周期。 如果对于某些类型,您总是希望A类型具有相同的实例,但是B的每个类型都需要一个新实例? 使用容器执行此操作非常简单,您必须自己为Activat ...
-
使用反思时,您应该首先问问自己几个问题,因为您可能会遇到难以维护的顶级复杂解决方案: 有没有办法使用泛型或类/接口继承来解决问题? 我可以使用dynamic调用(仅限.NET 4.0及更高版本)解决问题吗? 性能是否重要,即我的反映方法或实例化调用是否被调用一次,两次或一百万次? 我可以结合技术来实现一个聪明但可行/可理解的解决方案吗? 我可以和丢失的编译时类型安全吗? 一般/动态 根据您的描述,我假设您在编译时不知道类型,只知道它们共享接口ICalculation 。 如果这是正确的,那么上面的数字(1) ...
-
假设你有一个名为MyFancyObject类,如下所示: class MyFancyObject { public int A { get;set;} } 它让你转过来: String ClassName = "MyFancyObject"; 成 MyFancyObject obj; 运用 obj = (MyFancyObject)Activator.CreateInstance("MyAssembly", ClassName)) 然后可以做如下事情: obj.A = 100; 这是它的目的。 ...
-
我更简单的方法是抛弃界面并使用类型类型创建一个枚举,然后你只需要一个类来选择每个类的类型。 Dim query = db.Songlist.Where(Function(s) s.genre = genre).ToList I simpler way would be to ditch the interface and make an enum with the genre types then you only need one class where you select which genre e ...
-
埋在以下文章的原因是: 关于CLR如何在数组类型上进行接口调度的一个奇怪的微妙之处 感兴趣的具体文本如下: 我们的接口调度逻辑有一个重要的优化,其中FOR EACH CALL SITE,它显式地检查一个特定目标,如果失败,则执行较慢的哈希表查找,如果该查找失败,则回退到昂贵的查找。 因此,对于倾向于到达一个目的地的呼叫站点而言,它非常快,并且呼叫到达许多目标的站点,您会变得很好,但性能却不是很好。 根据出现的第一个对象的具体类型初始化调用站点优化。 您应该能够通过将测试中的IPlugin接口替换为Plugi ...
-
有一个使用差异...当你写: var obj = Activator.CreateInstance
(); 你使用类似Type的类,这是做到这一点的好方法。 您使用了具有类类型引用的泛型类型。 但那里: var obj2 =(myType) Activator.CreateInstance(myType); 你使用类就像一个实例(对象)。 你不能这样做,一个类是一个模式。 如果要调用第二种方法,则必须编写: var obj2 =(myType) Activator.CreateInstan ... -
Activator.CreateInstance vs Factory Pattern(Activator.CreateInstance vs Factory Pattern)[2023-04-25]
工厂模式是更高级的模式。 它为您提供了一种可以解决创建对象时可能发生的一些问题的结构。 从维基百科引用, 创建对象通常需要复杂的流程,不适合包含在组合对象中。 对象的创建可能会导致代码的重复,可能需要组成对象无法访问的信息,可能无法提供足够的抽象级别,或者可能不会成为组成对象关注的一部分。 创建对象所需的一些过程包括确定要创建哪个对象,管理对象的生命周期以及管理对象的专门建立和拆卸问题。 Activator.CreateInstance不解决任何这些问题,它只允许您创建一个类型的新实例。 如果你没有像上述那 ... -
我认为它与使用UWP有关,但我不确定 那是对的。 了解UWP上可用的基本API的一个好方法是过滤“Silverlight”: https : //msdn.microsoft.com/en-us/library/system.activator.createinstance(v = vs.95).aspx I figure it has something to do with using UWP but I'm not sure That's correct. A good way to know whi ...
-
所以你已经创建了这个对象? 然后就像使用is运算符一样简单。 var obj = Activator.CreateInstance(...); bool objIsIMyInterface = obj is IMyInterface; 如果您想在创建System.Type的位置进行测试,可以使用Type.IsAssignableFrom : Type type = ... bool typeIsIMyInterface = typeof(IMyInterface).IsAssignableFrom(typ ...