Home  >  Article  >  Database  >  SQL 查询分析中使用net命令问题

SQL 查询分析中使用net命令问题

WBOY
WBOYOriginal
2016-06-07 17:58:49850browse

SQL 查询分析中使用net命令问题,有需要的朋友可以参考下。

在DOS命令下(或Bat文件)执行:
net use \\192.168.100.1\ipc$ ks-c-001-11 /user:administrator
COPY \\192.168.100.1\xm\XM\SALE_DBC.* c:\temp /y
COPY \\192.168.100.1\xm\XM\sale07.* c:\temp /y
COPY \\192.168.100.1\xm\XM\sale10.* c:\temp /y
COPY \\192.168.100.1\xm\XM\sale11.* c:\temp /y
net use \\192.168.100.1\ipc$ /del
查询分析中下执行:
1.使用xp_cmdshell,最好在命令前加上"master.dbo.",因为存储过程“xp_cmdshell”属于master数据库。
2.在设置连接IPC时,"user:"和"用户名"之间还要加上连接的IP或电脑名称.
一、使用IP地址连接
--1.设置连接
EXEC master.dbo.xp_cmdshell 'net use \\192.168.100.1\ipc$ ks-c-001-11 /user:192.168.100.1\administrator'
--2.执行dos命令
EXEC master.dbo.xp_cmdshell 'COPY \\192.168.100.1\xm\XM\SALE_DBC.* c:\temp /y'
EXEC master.dbo.xp_cmdshell 'COPY \\192.168.100.1\xm\XM\sale07.* c:\temp /y'
EXEC master.dbo.xp_cmdshell 'COPY \\192.168.100.1\xm\XM\sale10.* c:\temp /y'
EXEC master.dbo.xp_cmdshell 'COPY \\192.168.100.1\xm\XM\sale11.* c:\temp /y'
--3.断开连接
EXEC master.dbo.xp_cmdshell 'net use \\192.168.100.1\ipc$ /del'
二、使用电脑名称连接
--1.设置连接
EXEC master.dbo.xp_cmdshell 'net use \\ks-008\ipc$ ks-c-001-11 /user:ks-008\administrator'
--2.执行dos命令
EXEC master.dbo.xp_cmdshell 'COPY \\ks-008\xm\XM\SALE_DBC.* c:\temp /y'
EXEC master.dbo.xp_cmdshell 'COPY \\ks-008\xm\XM\sale07.* c:\temp /y'
EXEC master.dbo.xp_cmdshell 'COPY \\ks-008\xm\XM\sale10.* c:\temp /y'
EXEC master.dbo.xp_cmdshell 'COPY \\ks-008\xm\XM\sale11.* c:\temp /y'
--3.断开连接
EXEC master.dbo.xp_cmdshell 'net use \\ks-008\ipc$ /del'
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn