• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4077
  • Last Modified:

xp_cmdshell with net use

Hi,

when I use 'net use \\192.168.0.1\c$ password /user:username' at the command prompt, it works fine.  But if i try to use it in sql with " exec master..xp_cmdshell 'net use \\192.168.0.1\c$ password /user:username' ", it returns successful but nothing actual happen.
I tried to put 'net use \\192.168.0.1\c$ password /user:username' in .bat file and exec master..xp_cmdshell 'd:\connect.bat' still doesn't work.

Is there any problem for this?
0
changeexpert
Asked:
changeexpert
  • 3
  • 2
1 Solution
 
timberbtCommented:
Hey there...what exactly are you trying to do?

Couldn't you just run the .bat file directly without having to map a drive?

i.e.

\\192.168.0.1\c$\connect.bat

=Timberbt
0
 
changeexpertAuthor Commented:
Hi,

I tried to map a drive on the fly inside stored proc by using xp_cmdshell with net use.  I have surf around the web and seems like could be releated to permission between SQL and Windows.

Any idea?

Thanks
0
 
timberbtCommented:
Well a couple things...

1) Remember that when you map a drive you are mapping it for a user.  That user is the one who executes XP_CmdShell.  If the user is NOT in the sysadmin role on SQL, then it is executed under the SQL Server Agent Proxy Account.   WHich means that the drive might get mapped, but it's going to get mapped for that user only.

2)  What are you mapping the drive for?  when possible it is usually better to avoid xp_cmdshell altogether, so if you state what you're trying to accomplish, there might be a better way to do it.

=Timberbt
0
 
changeexpertAuthor Commented:
Hi,

I have a SQL job that will be executed every 10 minutes to move files from Server A to Server B's specific folder with a user account which only have write permission on that folder only.  Server B's IP could be changed, that's why I need to map the drive on the fly.

Any good idea to do this?

Thanks
0
 
timberbtCommented:
Okay

1) In enterprise manager open your server, go to Management, ricght clikc on SQL Server Agent, go to the Job System Tab,
at the bottom, uncheck "Only users with SysAdmin priveleges can execute CMDExec and Active Scripting job steps" the hit the Reset Proxy accuont button.   Put in the account you want to use to run your command.

2) Make the step in the job you want to do.  do you execution as "copy \\server1\myshare\*.pst \\server2\myshare\"

make sure the user you put in for the proxy account has permissions to the shares, etc...

that should do it.

=Timberbt
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now