xp_cmdshell with net use


when I use 'net use \\\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 \\\c$ password /user:username' ", it returns successful but nothing actual happen.
I tried to put 'net use \\\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?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hey there...what exactly are you trying to do?

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



changeexpertAuthor Commented:

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?

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.

changeexpertAuthor Commented:

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?


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.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows 2000

From novice to tech pro — start learning today.