博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
sql server 查询任务管理器数据
阅读量:6155 次
发布时间:2019-06-21

本文共 3378 字,大约阅读时间需要 11 分钟。

 
USE
master
go
IF
OBJECT_ID
(
'
tempdb..#temp
'
)
IS
NOT
NULL
DROP
TABLE
#
temp
CREATE
TABLE
#
temp
(
id
INT
IDENTITY
(
1
,
1
)
NOT
NULL
,Proc_info
NVARCHAR
(
MAX
)
NULL
,
CONSTRAINT
pk_id
PRIMARY
KEY
( id
ASC
)
)
--
insert data into temp table
INSERT
INTO
#
temp
( Proc_info )
EXEC
master..xp_cmdshell
'
tasklist /v
'
--
delete the wrong records
DELETE
FROM
#
temp
WHERE
Proc_info
IS
NULL
OR
Proc_info
LIKE
'
%==========%
'
OR
ID
=
2
GO
--
create a splite function
CREATE
FUNCTION
F_split_V2 (
@S
NVARCHAR
(
4000
),
@i
INT
)
RETURNS
NVARCHAR
(
100
)
AS
BEGIN
IF
@i
=
1
--
Image_name
BEGIN
IF
PATINDEX
(
'
%.exe%
'
,
@s
)
=
0
SET
@s
=
RTRIM
(
LEFT
(
@s
,
PATINDEX
(
'
%[0-9]%
'
,
@s
)
-
1
))
ELSE
SET
@s
=
RTRIM
(
LEFT
(
@s
,
PATINDEX
(
'
%.exe%
'
,
@s
)
+
4
))
END
ELSE
IF
@i
=
2
--
Pid
BEGIN
IF
PATINDEX
(
'
%.exe%
'
,
@s
)
=
0
SET
@s
=
STUFF
(
@s
,
1
,
PATINDEX
(
'
%[0-9]%
'
,
@s
)
-
1
,
''
)
ELSE
SET
@s
=
LTRIM
(
SUBSTRING
(
@s
,
PATINDEX
(
'
%.exe%
'
,
@s
)
+
4
,
LEN
(
@s
)))
SELECT
@s
=
RTRIM
(
LEFT
(
@s
,
PATINDEX
(
'
%[^0-9]%
'
,
@s
)
-
1
))
END
ELSE
IF
@i
=
3
--
Session_name
BEGIN
IF
PATINDEX
(
'
%.exe%
'
,
@s
)
=
0
SET
@s
=
STUFF
(
@s
,
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,
@s
=
STUFF
(
@s
,
1
,
PATINDEX
(
'
%[1-9]%
'
,
@s
)
-
1
,
''
)
,
@s
=
RTRIM
(
LEFT
(
@s
,
PATINDEX
(
'
%k%
'
,
@s
)
-
1
))
END
ELSE
IF
@i
=
6
--
user_name
SELECT
@s
=
STUFF
(
@s
,
1
,
PATINDEX
(
'
%[0-9]%
'
,
@s
)
-
1
,
''
)
,
@s
=
STUFF
(
@s
,
1
,
PATINDEX
(
'
%[^0-9]%
'
,
@s
)
-
1
,
''
)
,
@s
=
STUFF
(
@s
,
1
,
PATINDEX
(
'
%[0-9]%
'
,
@s
)
-
1
,
''
)
,
@s
=
STUFF
(
@s
,
1
,
PATINDEX
(
'
%[1-9]%
'
,
@s
)
-
1
,
''
)
,
@s
=
RTRIM
(
SUBSTRING
(
@s
,
PATINDEX
(
'
%\%
'
,
@s
)
+
1
,
18
))
ELSE
IF
@i
=
7
--
cup_time
SELECT
@s
=
SUBSTRING
(
@s
,
PATINDEX
(
'
%[0-9]:[0-9][0-9]:[0-9][0-9]%
'
,
@s
),
8
)
ELSE
SELECT
@s
=
RIGHT
(
@s
,
CHARINDEX
(
'
'
,
REVERSE
(
@s
),
3
)
-
1
)
RETURN
@s
END
go
SELECT
dbo.F_split_V2(Proc_info,
1
)
AS
image_name
,dbo.F_split_V2(Proc_info,
2
)
AS
PID
,dbo.F_split_V2(Proc_info,
3
)
AS
session_name
,dbo.F_split_V2(Proc_info,
4
)
AS
session#
,dbo.F_split_V2(Proc_info,
5
)
+
'
K
'
AS
Memory
,dbo.F_split_V2(Proc_info,
6
)
AS
User_name
,dbo.F_split_V2(Proc_info,
7
)
AS
cpu_time
,
'
xp_cmdshell
''
taskkill -IM
'
+
dbo.F_split_V2(Proc_info,
1
)
+
'
/f
'''
AS
script
FROM
#
temp

转载地址:http://qjffa.baihongyu.com/

你可能感兴趣的文章
jdk1.7和jdk1.8的String的getByte方法的差异
查看>>
java父子进程通信
查看>>
Android ADB server didn't ACK * failed to start daemon * 简单有效的解决方案
查看>>
Olap学习笔记
查看>>
Codeforces Round #431 (Div. 1)
查看>>
如何进行数组去重
查看>>
将标题空格替换为 '_' , 并自动复制到剪切板上
查看>>
List Collections sort
查看>>
Mysql -- You can't specify target table 'address' for update in FROM clause
查看>>
使用局部标准差实现图像的局部对比度增强算法。
查看>>
2017-2018-1 20165313 《信息安全系统设计基础》第八周学习总结
查看>>
《代码敲不队》第四次作业:项目需求调研与分析
查看>>
菜鸡互啄队—— 团队合作
查看>>
HttpWebRequest的GetResponse或GetRequestStream偶尔超时 + 总结各种超时死掉的可能和相应的解决办法...
查看>>
SparseArray
查看>>
第二章
查看>>
android背景选择器selector用法汇总
查看>>
[转]Paul Adams:为社交设计
查看>>
showdialog弹出窗口刷新问题
查看>>
java
查看>>