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 Reverse Sort Order
andyking-pit View Drop Down
Newbie
Newbie


Joined: 18 December 2009
Location: Pittsburgh, PA
Online Status: Offline
Posts: 1
Post Options Post Options   Quote andyking-pit Quote  Post ReplyReply Direct Link To This Post Topic: PsExec and "net use"
    Posted: 18 December 2009 at 7:24pm
I accomplished what I needed with this as well.  We use SMS 2003 to distribute and install software packages.  Where the SMS client has failed, I was looking to use PSEXEC to remotely execute a software installs on a remote client, where it would run from the local/remote server.  Ie sitting in Pittsburgh a would make a client PC in Denver install from the Denver server.

Because of how the packages are configured (using a HTA files that derive the path where there are executed from) they need to be executed from a mapped network drive.  The share where the files are located have everyone read access so that the SYSTEM account which is what does the install can access it.

The solution for me was to use the -s option to run the process in the SYSTEM context, and to have it execute a batch file.

The batch file contains the remote/local UNC path to the install source.  So PSEXEC copies the batch file to the remote host which then executes it as the SYSTEM account.  Maps to the hidden SMS share, changes to the mapped drive and executes the HTA which displays to the user and the install works great.

psexec.exe -s -c -i  \\target \\mypc\g$\remoteinstall.bat

where remoteinstall.bat = 
net use p: /delete
net use p: \\remotelocalserver\share$\smsPkgIDFolder
p:
NameOfPackageToExecute.hta

I also found that when using the -s (and -i) option, if I open an interactive command window, I can do this process interactively so long as the shares I am mapping to have everyone full control.

Back to Top
sanatogen View Drop Down
Newbie
Newbie


Joined: 21 March 2009
Online Status: Offline
Posts: 1
Post Options Post Options   Quote sanatogen Quote  Post ReplyReply Direct Link To This Post Posted: 21 March 2009 at 1:03am
Hi Folks,

Just to say thanks to all who contributed to this thread. I was beating my head for 3 hours over this one and as a results of this thread my script now works.

Rod
Back to Top
molotov View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 04 October 2006
Online Status: Offline
Posts: 17492
Post Options Post Options   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
molotov View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 04 October 2006
Online Status: Offline
Posts: 17492
Post Options Post Options   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
e-master View Drop Down
Newbie
Newbie


Joined: 10 October 2008
Online Status: Offline
Posts: 2
Post Options Post Options   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
e-master View Drop Down
Newbie
Newbie


Joined: 10 October 2008
Online Status: Offline
Posts: 2
Post Options Post Options   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
mabino View Drop Down
Newbie
Newbie


Joined: 30 January 2006
Online Status: Offline
Posts: 2
Post Options Post Options   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
mabino View Drop Down
Newbie
Newbie


Joined: 30 January 2006
Online Status: Offline
Posts: 2
Post Options Post Options   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
Karlchen View Drop Down
Senior Member
Senior Member
Avatar

Joined: 18 June 2005
Location: Germany
Online Status: Offline
Posts: 5121
Post Options Post Options   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
ronaldknol View Drop Down
Newbie
Newbie


Joined: 26 January 2006
Location: Canada
Online Status: Offline
Posts: 2
Post Options Post Options   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
 Post Reply Post Reply Page  12>

Forum Jump Forum Permissions View Drop Down