SQL xp_cmdshell

大家讲道理
發布: 2016-11-10 11:15:10
原創
967 人瀏覽過

GO
---打开xp_cmdshell
EXEC sp_configure 'show advanced options', 1;
RECONFIGURE;
EXEC sp_configure 'xp_cmdshell', 1;
RECONFIGURE
 
GO
---创建文件夹
declare @shellCommand nvarchar(1024)
Set @shellCommand='"mkdir C:\sqlcreatefold"'
exec xp_cmdshell @shellCommand
 
GO
--复制文件--准备一个空的文本文件在C盘
declare @shellCommand nvarchar(1024)
Set @shellCommand='Copy "C:\1.txt'+'" "C:\sqlcreatefold\1.txt'+'"'
exec xp_cmdshell @shellCommand
GO
--导出数据到TXT
Create table ##temp(line varchar(100))
Insert into ##temp(line)values('asdfghjklasdfghjkl')
Insert into ##temp(line)values('一二三四五六七')
declare @shellCommand nvarchar(1024)
Set @shellCommand='bcp "Select line From ##temp" queryout C:\sqlcreatefold\1.txt'+' -S"." -U"sa" -P"123456" -c -T'
exec xp_cmdshell @shellCommand
drop table ##temp
 
GO
--读取TXT文件
Create table ##temp(line varchar(100))
exec(N'bulk insert ##temp from N''C:\sqlcreatefold\1.txt''')
select * From ##temp
drop table ##temp
 
GO
--调用RAR--压缩文件夹
declare @shellCommand nvarchar(1024)
declare @WinRar varchar(128)
set @WinRar='C:\Program Files\WinRAR\WinRAR.exe'
Set @shellCommand='""'+@WinRar+'"  a -ep1 -afzip -df -ibck C:\sqlcreatefold\Package.zip C:\sqlcreatefold"'
exec xp_cmdshell @shellCommand
set @shellCommand='" dir C:\sqlcreatefold"'
exec xp_cmdshell @shellCommand
登入後複製

來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
作者最新文章
最新問題
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!