简体   繁体   English

使用xp_cmdshell的任务列表

[英]Tasklist using xp_cmdshell

I want to know how i will use the tasklist cmd that will output the imagename plus the hostname 我想知道我将如何使用任务列表cmd来输出图像名和主机名

i have thus syntax but could not combine the result into one. 我有这样的语法,但不能将结果合并为一个。

EXEC xp_cmdshell 'tasklist /fi "imagename eq notepad.exe"';  

plus hostname 加上主机名

This will give you what you want: 这将给您您想要的:

DECLARE @T TABLE (capture VARCHAR(5000))

INSERT @T
EXEC xp_cmdshell 'tasklist /fi "imagename eq notepad.exe"'; 

INSERT INTO dbo.[N4FO_OpenGUIOutput] (Output,system) 
SELECT capture, @@SERVERNAME as host FROM @T WHERE capture IS NOT NULL

But you have to actually connect to the SQL Server to run it so you'll already need to know the host name to connect to. 但是您必须实际连接到SQL Server才能运行它,因此您已经需要知道要连接的主机名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM