Link to home
Start Free TrialLog in
Avatar of WellingtonIS
WellingtonIS

asked on

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.
Avatar of serchlop
serchlop
Flag of Mexico image

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"?
Avatar of Qlemo
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.
Avatar of WellingtonIS
WellingtonIS

ASKER

When I try to run the command it tells me that the file name or volume label syntax is incorrect.
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.
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???
ASKER CERTIFIED SOLUTION
Avatar of serchlop
serchlop
Flag of Mexico image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.