ms sql : xp_cmdshell

向高手请教一个问题:
当我执行:
  use master
exec  xp_cmdshell 'osql /S musqlserver /U sa /P mypwd /d haodb /Q "select top 10 * from trandetail"  /o C:/my1.xls'
以上执行成功,会产生新文件:C:/my1.xls'
然后我想将此文件直接copy到另一台电脑中[已建连接]
执行
  EXEC xp_cmdshell 'copy C:/my1.xls  //192.168.42.42/d$'
  时候,系统会提示"拒绝访问"
  而在DOS窗口中执行:
  C:/my1.xls  //192.168.42.42/d$ 则没有任何问题

我想应该是用户权限的问题
因为在sql中,用户是sa
在DOS中,用户则是administrator

那我应该怎么做??

先建立共享信用关系
master..xp_cmdshell 'net use //192.168.42.42/d$ 123  /user:domain/administrator'

关于net use的用法看帮助。

 

exec xp_cmdshell 'net use Z: //192.168.42.42/d$   /user:domain/administrator'
exec xp_cmdshell 'copy C:/my1.xls Z:/'
exec xp_cmdshell 'net use Z: /del'

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值