?
Solved

xp_cmdshell with net use

Posted on 2003-11-04
8
Medium Priority
?
3,763 Views
Last Modified: 2012-05-04
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
Comment
Question by:changeexpert
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
8 Comments
 
LVL 1

Expert Comment

by:timberbt
ID: 9686845
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
 

Author Comment

by:changeexpert
ID: 9688434
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
 
LVL 1

Expert Comment

by:timberbt
ID: 9689507
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
 

Author Comment

by:changeexpert
ID: 9689785
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
 
LVL 1

Accepted Solution

by:
timberbt earned 200 total points
ID: 9690075
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
Check out the latest tech news, community articles, and expert highlights in August's newsletter.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question