Solved

xp_cmdshell with net use

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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…
Sometimes clients can lose connectivity with the Lotus Notes Domino Server, but there's not always an obvious answer as to why it happens.   Read this article to follow one of the first experiences I had with Lotus Notes on a client's machine, my…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

695 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