[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1484
  • Last Modified:

PSexec Command

I'm trying to user the following command and suddenly it's not working???
PSexec \\@%var% -s cmd /c copy "C:\Icon\xxx.url" "%allusersprofile%\Desktop" /Y

It's saying can't find the file specified.
It is copying to the C:\icon I can see it but suddenly it's not going from C:\icon\ to the all users desktop???

The @%var% is from a multiple machine text file but for testing I was using the computer name in the command.
0
WellingtonIS
Asked:
WellingtonIS
  • 4
  • 2
1 Solution
 
serchlopCommented:
What happed if you change the command to

PSexec \\@%var% -s cmd /c dir "C:\Icon\xxx.url"

or in the machine @%var% try to open a cmd and run dir "C:\Icon\xxx.url" to verify if the path exists

Maybe it could be permissions problem

Which account are you using? this account has permission to "C:\Icon\xxx.url"?
0
 
QlemoC++ DeveloperCommented:
The %allusersprofile% var is expanded on the machine before executing psexec, so if you execute from W7 to XP or reversed it will not work. You'll need either to escape the % (^%), or use cmd with delayed expansion to postpone %allusersprofile% substitution to the latest possible point in time:
PSexec \\PC -s cmd /c /e:on /v:on copy "C:\Icon\xxx.url" "!allusersprofile!\Desktop\" /Y

Open in new window

Also note that I have added an backslash to the target. That way "Desktop" cannot be misinterpreted to be the target file name instead of a folder.
0
 
WellingtonISAuthor Commented:
When I try to run the command it tells me that the file name or volume label syntax is incorrect.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
WellingtonISAuthor Commented:
As for the permissions problem I'm running it as a system command.  I also tried with my user name and password and it's the same thing.  However I can do an administrative share with my user name and password.
0
 
WellingtonISAuthor Commented:
For some strange reason that I can't explain when I try to copy to %allusersprofile% is says the system can't find the path specified????

PSexec \\pc -s cmd /c copy "c:\icon\xxx.url" "%allusersprofile% \desktop" /Y

Stranger still is I can run this on my test machine without issue???
0
 
serchlopCommented:
If this still doesn't work remotely it's possible the allusersprofile environmental variable is being read from the machine which executed the psexec command, rather than the remote machine.

You can create a batch file with the following commands:


@echo off
cmd /c copy "C:\Icon\xxx.url" "%allusersprofile%\Desktop" /Y

Open in new window




Put this batch in a network share, for example \\server\batch

and the use psexec to run this command in the remote machine

PSexec \\@%var% -s \\server\batch\CopyIcon.bat
0
 
WellingtonISAuthor Commented:
I'm not sure why the "old' way doesn't work but I modified the PSexec script to copy the bat file to the C drive of the PC run it and then delete the bat file.  thanks.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now