SSMS可扩展性/插件 - 获取当前数据库和服务器(SSMS extensibility/addin - get current database and server)
我正在尝试为自定义审计要求编写SSMS插件(需要审计生产环境中用户运行的所有查询)。 我有.addin文件位于相应的文件夹中,它命中了我的Connect.Exec方法中的断点,我能够从活动文档中选择查询语句。 但是我不确定是否有任何属性或方法可以查找以获取数据库名称和用户连接的服务器?
I am trying to write a SSMS addin for a custom auditing requirement (need to audit all queries ran by users in a production environment). I have the .addin file located in the appropriate folders and it hits the breakpoints in my Connect.Exec method and I am able to get the query statements under selection from the active document. However I am not sure if there is any property or method that I could look up to get the database name and the server the user was connected to ?
原文:https://stackoverflow.com/questions/25150386
最满意答案
编辑 - 似乎我没有正确解释,人们不知道它是如何工作的。 我的错。 我会试着更好地解释它。
原因在于for命令的内部工作方式。
当到达
for var in (files)
行时,将检查目录以查看是否有任何文件匹配并需要处理。然后,
for
命令(真正的cmd),发出一个目录查询来枚举这些文件。 此查询只返回集合中的第一个文件 。 如果有任何与for
命令中的文件掩码相匹配的辅助文件,则会设置一个标志,指示调用方(cmd)有更多要处理的文件,但其余文件的列表尚未检索 。当执行内部代码
for
达到迭代结束时,并且有待处理的文件被读取时,会发送一个查询以获取待处理文件列表的剩余部分,并与for
文件选择相匹配。系统使用剩余文件列表填充缓冲区。 如果此时文件列表足够短以便在缓冲区中完全播放,则查询将不会重复。 如果文件列表大小不足以放入缓冲区,则检索部分列表,并在处理检索列表中的文件时,再次发送查询以获取更多文件进行处理。
缓冲区中的文件数量取决于文件名的长度。 文件名越短,缓冲区中的文件越多,查询文件系统越少。
此行为(仅在文件查询返回存在待处理文件时才会执行(在第一个文件处理结束时检索剩余文件列表)。 当一个查询不返回该标志时,不会检索到更多文件。
例外
如果在NTFS中工作,如果文件按字母顺序大于在
for
命令中处理的最后一个文件,则文件仅包含在“重新查询”中。如果FAT工作,则查询将包括所有生成的与文件选择独立匹配的新文件。 是的,它可能陷入无限循环。 (在测试中,系统缓冲区只检索一个文件名,并在每次迭代中检索)。 你可以试试
break > a.txt && cmd /v:on /c "for %f in (*.txt) do break > !random!.txt"
我所有的测试都是在Windows 7 64位,NTFS和FAT32分区上进行的(在USB驱动器上)。 没办法测试其他配置。 如果有人看到不同的行为,请评论。
有关更多信息,请参阅ZwQueryDirectoryFile
EDITED - Seems i've not explained it properly and people doesn't see how it works. My fault. I'm going to try to explain it better.
The reason is the way the for command works internally.
When the line
for var in (files)
is reached, the directory is checked to see if any files match and need to be processed.Then,
for
command (cmd really), issues a directory query to enumerate the files. This query returns only the first file in set. If there are any aditional files that match the file mask infor
command, a flag is set that indicates to the caller (cmd) that there are more files to be processed, but the list of the remaining files is not yet retrieved.When execution of code inside
for
reachs the end of an iteration, and there are files pending to be read, a query is sent to get the remaining of the list of files pending to be processed and that match thefor
file selection.System fills a buffer with the list of files remaining. If at that point the list of files is short enough to be full readed in buffer, the query will not be repeated. If the list of files is big enough to not fit in buffer, partial list is retrieved and when files in retrieved list are processed, the query will be sent again to get more files to process.
Number of files in buffer depends on length of filename. Shorter filenames, more files in buffer and less queries to filesystem.
This behaviour (retrieving remaining list of files at end of first file processing) is only done if the query for files returns that there are files pending. When one query does not return that flag, no more files are retrieved.
EXCEPTIONS
If working in NTFS, the files only get included in "requeries" if they are alphabetically greater than the last file that has been processed in
for
command.If working if FAT, the query will include all new file generated that match the
for
command file selection independly of it name. And yes, it can get into an infinite loop. (In tests, the system buffer only retrieve one filename, and requery in each iteration). You can trybreak > a.txt && cmd /v:on /c "for %f in (*.txt) do break > !random!.txt"
All my tests has been made on a windows 7 64bit, NTFS and FAT32 partition (this on a USB drive). No way to test other configurations. If anyone see a diferent behaviour, please comment.
For more information, ZwQueryDirectoryFile
相关问答
更多-
循环的批处理脚本(Batch script for loop)[2022-04-13]
看起来%comspec%变量已被置%comspec%或更改,但找不到cmd.exe 测试这个以查看错误,并在工作机器上删除第2行以使其正常工作。 @echo off set comspec=c:\aaa for /f "delims=;" %%g in ('dir') do echo %%g pause 非常有趣的是cmd.exe的路径被缓存。 下面的两个脚本是相同的,只更改了命令的顺序 此批处理文件将因两个命令而失败 @echo off set comspec=c:\aaa for /f "delims ... -
检测BATCH中的文件更新(Detecting a file update in BATCH)[2022-05-11]
您应该为每个用户使用一个文件来检查状态。 这使您可以在自己的窗口中制作不同的广告。 聊天窗口不一定必须共享 - 但可以将其分开。 显示屏不必一次又一次更新,仅在写入时激活,否则显示其他用户的消息或他们自己的设置。 状态消息通过窗口标题显示。 最后但并非最不重要的是,使用find或更多来从共享聊天文件中读出消息。 当然,你可以用robocopy来做到这一点,但是如果这种方法工作得足够快的话...... 您可以将其全部扩展,以便为每个发送的消息创建每个用户的控制文件。 这反过来将允许robocopy轻松监视这样 ... -
玩家以5个积分开始游戏,这意味着游戏在开始时不会结束。 您应该翻转循环的各个部分 - 首先执行绘图,然后检查游戏是否结束: while (playing) { // Code to do another drawing if (credits == 0) { System.out.println("\nYou lose !"); playing = false; } else if (credits == 10) { S ...
-
为什么在批量程序的FOR循环中创建额外的文件?(Why is an extra file being created in FOR loop of batch program?)[2021-10-06]
编辑 - 似乎我没有正确解释,人们不知道它是如何工作的。 我的错。 我会试着更好地解释它。 原因在于for命令的内部工作方式。 当到达for var in (files)行时,将检查目录以查看是否有任何文件匹配并需要处理。 然后, for命令(真正的cmd),发出一个目录查询来枚举这些文件。 此查询只返回集合中的第一个文件 。 如果有任何与for命令中的文件掩码相匹配的辅助文件,则会设置一个标志,指示调用方(cmd)有更多要处理的文件,但其余文件的列表尚未检索 。 当执行内部代码for达到迭代结束时,并且有 ... -
你可以用两种方式做到这一点。 您需要更改批处理作业myJob以从基本目录检索所有pdf文件,包括使用java的子目录。 另一种选择是使用unix查找基本目录下的所有pdf文件,包括sub directory find . -name "*.pdf" 获取输出可能是逗号分隔,并将此逗号分隔的字符串作为批处理作业的参数,并且应修改myJob以读取新参数并处理它 You can do it in two ways. You need to change your batch job myJob to retrie ...
-
额外行创建导入文件(Extra Line Created Import File)[2023-07-12]
问题是您必须删除由TransformProductToEdi生成的最后一个vbCrLf ,用于数组retval的最后一个条目 在TransformProductToEdi中生成vbCrLf的最后一行是 retVal &= .GeminiDepartmentId & vbCrLf the issue is you have to remove the last vbCrLf produced by TransformProductToEdi for the last entry of the arra ... -
批处理中带有额外后缀的文件(files with extra suffix in batch)[2022-04-08]
一种解决方案是在循环内通过扩展进行过滤: FOR %%A IN (*txt.*) DO ( IF NOT "%%~xA"==".txt" CALL :renum "%%A" ) 这通过使用“ FOR变量引用的增强替换”来工作,在这种情况下为%%~xA 。 您可以通过执行FOR /?来获得所有可用替换的概述FOR /? 。 更新: 此解决方案不区分大小写,因为既没有明确要求也没有禁止。 如果需要不区分大小写,请使用IF /I而不是普通IF 。 正如dbenham所说,有边缘情况: name.txt. ... -
@echo off setlocal EnableDelayedExpansion rem Create an empty file cd . > key.txt rem Start a parallel process that wait for Enter key rem and add a line to the empty file start "" /B cmd /C "set /P = & echo line >> key.txt" set "key=" :wait cls s ...
-
批量变量循环查询(Batch Variable Loop Inquiry)[2022-02-24]
一个主意 : @Echo off&cls setlocal enabledelayedexpansion set /a $count=1 for /f "delims=" %%a in ('dir "C:\directory1\directory2\directory1\work" /b/o') do ( md "C:\BackupLocation\%%a-!$Count!" 2>nul staging-backup "%%a-!$Count!" "C:\BackupLocation\%%a-!$C ... -
在块语句(a parenthesised series of statements) , 整个块被解析然后执行。 块中的任何%var%将在解析块时被该变量的值替换 - 在块执行之前 - 同样的事情适用于FOR ... DO (block) 。 因此, IF (something) else (somethingelse)将在遇到IF时使用%variables%的值执行。 在您的情况下, y和x都是在循环中设置的,因此使用解析循环时的值。 很可能,这些值是空的,因此例如echo %y%将被解释为echo ,因 ...