Sysinternals Homepage
Forum Home Forum Home > Sysinternals Utilities > PsTools
  New Posts New Posts RSS Feed: PsExec and "net use"
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

PsExec and "net use"

 Post Reply Post Reply Page  12>
Author
Message
  Topic Search Topic Search  Topic Options Topic Options
ronaldknol View Drop Down
Newbie
Newbie


Joined: 26 January 2006
Location: Canada
Online Status: Offline
Posts: 2
  Quote ronaldknol Quote  Post ReplyReply Direct Link To This Post Topic: PsExec and "net use"
    Posted: 26 January 2006 at 4:15pm

Having searched this forum and on the internet I still have not been able to get my problem answered, so hence this new post.

Using psexec v1.70, my PC is Windows 2000 Professional SP4, the remote machine is also Windows 2000 Professional SP4. No firewalls involved, both machines are part of a (Windows 2003) domain. The remote machine automatically logs on with a known username and password (account and passwd), I am logged on to my PC with my own credentials (myaccount and mypasswd).

The remote machine (account) automatically maps a network drive when it logs on (done through Windows Explorer with Reconnect At Logon).

I am trying do remotely change that mapped drive to another server. On the remote machine locally I can do this (works):

    net use W: /delete
    net use W: \\server\share /PERSISTENT:YES

But, from my PC using PsExec this does not work and I get strange results. Here's what I did:

    psexec \\remote -u domain\account -p passwd -i net use W: /delete

This fails with error:

    The network connection could not be found.
    More help is available by typing NET HELPMSG 2250.

If I try to map a new drive

    psexec \\remote -u domain\account -p passwd -i net use K: \\server\share

This works, and the K: drive shows up on the remote machine in Windows Explorer (but with a red X indicating disconnected) and I can access it. So then I want to disconnect it:

    psexec \\remote -u domain\account -p passwd -i net use K: /delete

And again I get the error:

    The network connection could not be found.
    More help is available by typing NET HELPMSG 2250.

But now even though I got this error, Windows on the remote machine is confused. Windows Explorer still shows the K: drive, but running "net use" on that remote machine shows no K: drive. Windows Explorer "Disconnect Network Drive" also does not show K:.

I have tried this over and over, but I get the same results. PsExec with "net use K: \\server\share" works, but after that the machine does not indicate that the drive is mapped, and cannot be unmapped, even though Windows Explorer sees the newly mapped drive and can access it.

Thoughts?

 


Cheers,

Ronald.
Back to Top
Karlchen View Drop Down
Senior Member
Senior Member
Avatar

Joined: 18 June 2005
Location: Germany
Online Status: Offline
Posts: 5121
  Quote Karlchen Quote  Post ReplyReply Direct Link To This Post Posted: 26 January 2006 at 4:49pm
Good evening, Ronald.

psexec \\remote -u domain\account -p passwd -i net use W: /delete


Minor thing: in this case the -i switch is not needed. (I.e. you do not need it here, but it is unrelated to your issue.)

Major thing: the -e switch is needed!

Reason:
psexec without the -e switch will logon user domain\account on \\remote. Yet, it will not load account's profile, but the profile of LOCAL SYSTEM on \\remote.
LOCAL SYSTEM will not have the drive mapping W:, hence the correct, but unexpected error message.

psexec with the -e switch will logon user domain\account on \\remote. And it will load account's profile. The drive W: should be assigned, and "net use w: /delete" should work.

So your psexec command should read like this:
psexec \\remote -u domain\account -p passwd -e net use W: /delete


Let us know if it really works.
(I cannot test this scenario at this moment, because I am not connected to any usable network, except the internet obviously.
I remember though that in ancient PSTools thread(s) the same problem has been discussed before, I do not remember the essence. I do suspect, however, that drive (un)assignement using psexec may not be "sticky". This would correspond to what you wrote in the second half of your message.)

Karl



Edited by Karlchen
Back to Top
ronaldknol View Drop Down
Newbie
Newbie


Joined: 26 January 2006
Location: Canada
Online Status: Offline
Posts: 2
  Quote ronaldknol Quote  Post ReplyReply Direct Link To This Post Posted: 26 January 2006 at 6:13pm

Hi Karl, thanks for the quick response.

So I tried again, this time with -e. But I still get the same result.


psexec \\remote -u domain\account -p passwd -e net use N: \\server\share

The command completed successfully.
net exited on remote with error code 0.

Right after this I look on the remote machine (VNC) and N: does show up in Windows Explorer, and I can access it. But, "net use" does not show N: and I cannot psexec delete it:


psexec \\remote -u domain\account -p passwd -e net use N: /DELETE

The network connection could not be found.
More help is available by typing NET HELPMSG 2250.
net exited on vancg074 with error code 2.

I was unsure about the -e option since the proper account is already loaded (and active) on the machine; the account is already logged on (on the console).


Cheers,

Ronald.
Back to Top
Karlchen View Drop Down
Senior Member
Senior Member
Avatar

Joined: 18 June 2005
Location: Germany
Online Status: Offline
Posts: 5121
  Quote Karlchen Quote  Post ReplyReply Direct Link To This Post Posted: 27 January 2006 at 3:26am
Hi, Ronald.

I was unsure about the -e option since the proper account is already loaded (and active) on the machine; the account is already logged on (on the console).

The "-e" option is meaningful for the psexec session on \\remote.

To see the difference yourself, try
psexec \\remote -u domain\account -p passwd -e cmd.exe

vs.
psexec \\remote -u domain\account -p passwd cmd.exe
and
check the environment variables (%userprofile% e.g.)

I am sure you will notice the difference.

About the drive (un)assignements not being sticky:
As soon as find the time I will try to locate the ancient threads where this problem was discussed (as a side issue). If they are still on the server and if I find them, I will give the links here. Not sure though if the essence was not: do not (un)assign drives using psexec.

Karl
Back to Top
mabino View Drop Down
Newbie
Newbie


Joined: 30 January 2006
Online Status: Offline
Posts: 2
  Quote mabino Quote  Post ReplyReply Direct Link To This Post Posted: 30 January 2006 at 9:50am
Originally posted by ronaldknol

Hi Karl, thanks for the quick response.

So I tried again, this time with -e. But I still get the same result.


psexec \\remote -u domain\account -p passwd -e net use N: \\server\share

The command completed successfully.
net exited on remote with error code 0.

Right after this I look on the remote machine (VNC) and N: does show up in Windows Explorer, and I can access it. But, "net use" does not show N: and I cannot psexec delete it.



I am unable to get as far as you have in mapping the drive to begin with.  I've set up a test scenario where I'm trying to give the command via psexec to map a share that has few restrictions on it (shared to Everyone, perms are read-only).  I issue the command as you have above and get "command completed successfully... error code 0".  With the account logged in on the target machine I inspect both Windows Explorer and net use and neither report the existence of a mapped drive.  I've also tried:


psexec \\remote -u account -p passwd -e cmd.exe /c net use N: \\server\share


This pops up a DOS box for a moment on the target's desktop which then immediately closes.  This resembles the behavior of typing the cmd.exe... bit into Start > Run.  However, when sent via psexec it fails, typed into Start > Run and its successful.

I'm struggling to find this out as I do not want to have to copy the scripts I wish to run locally.

Back to Top
mabino View Drop Down
Newbie
Newbie


Joined: 30 January 2006
Online Status: Offline
Posts: 2
  Quote mabino Quote  Post ReplyReply Direct Link To This Post Posted: 30 January 2006 at 12:19pm
Originally posted by Karlchen


About the drive (un)assignements not being sticky:
As soon as find the time I will try to locate the ancient threads where this problem was discussed (as a side issue). If they are still on the server and if I find them, I will give the links here. Not sure though if the essence was not: do not (un)assign drives using psexec.


I was able to both add and remove mappings via psexec with the following commands, however after initially mapping the drive it is reported as being unavailable.

psexec -u administrator -p password \\target -e net use g: \\server\share /PERSISTENT:YES /user:guest

The command completed successfully.

psexec -u administrator -p password \\target -e cmd /c net use

Status       Local     Remote                     Network
---------------------------------------------------
Unavailable  G:        \\server\share           Microsoft
The command completed successfully.

psexec -u administrator -p password \\target -e cmd /c net use g: /delete

psexec -u administrator -p password \\target -e cmd /c net use

There are no entries in the list.



As a result of its unavailability I cannot run any scripts located there.  Running these same commands locally however successfully mounts the drive so it is usuable.


Edited by mabino
Back to Top
e-master View Drop Down
Newbie
Newbie


Joined: 10 October 2008
Online Status: Offline
Posts: 2
  Quote e-master Quote  Post ReplyReply Direct Link To This Post Posted: 10 October 2008 at 9:16pm

let me explain what's the real root-cause of this problem.

when you start a process remotely with PSExec (with or without -e, depends on the version) the remote process can't access any network drive. But, it can access the network. Thus the script above really works, because first you attach the network drive, and being in the same process-environment you are able to detach it.
 
one way of solution i'm looking for is to create batch files on the clients which will have the "net use x: \\zzz" command at first, and the "start yyyy.exe" command after. so, by executing remotely this batch file, i'll have attached the network drive, and in the same context of execution i'll start the executable i need.
 
another solution could be to use the "cmd" as a remote command to start the executable in the same way by joining the commands with &. I should start it like "cmd net use x: \\client & start process.exe". I'm going to test it right now, and let you know the results(i hope this post is relevant for someone yet, since it is 2 years old ;))
 
Back to Top
e-master View Drop Down
Newbie
Newbie


Joined: 10 October 2008
Online Status: Offline
Posts: 2
  Quote e-master Quote  Post ReplyReply Direct Link To This Post Posted: 10 October 2008 at 9:49pm
Ok, it works. So you just need to start something like this:
 
psexec -i -d -u user -p password \\client cmd "/C net use x: \\server & c:\program.exe"
 
hope i helped for someone.
Back to Top
molotov View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 04 October 2006
Online Status: Offline
Posts: 17287
  Quote molotov Quote  Post ReplyReply Direct Link To This Post Posted: 11 October 2008 at 3:35am
When dealing with PsExec, mapped drives, and a remote system, the situation may frequently be described in these articles:
Services and Redirected Drives
INFO: Services and Redirected Drives
Daily affirmation:
net helpmsg 4006
Back to Top
molotov View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 04 October 2006
Online Status: Offline
Posts: 17287
  Quote molotov Quote  Post ReplyReply Direct Link To This Post Posted: 29 October 2008 at 4:14pm
Note: moved chearns' post into its own topic:
Problem copying file
Daily affirmation:
net helpmsg 4006
Back to Top
 Post Reply Post Reply Page  12>

Forum Jump Forum Permissions View Drop Down

Privacy Statement