Solved

xp_cmdshell with net use

Posted on 2003-11-04
8
3,109 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
  • 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 50 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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…
A Short Story about the Best File Recovery Software – Acronis True Image 2017
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now