PSexec Command

Posted on 2012-08-28
Last Modified: 2012-08-29
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.
Question by:WellingtonIS
    LVL 12

    Expert Comment

    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"?
    LVL 67

    Expert Comment

    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.

    Author Comment

    When I try to run the command it tells me that the file name or volume label syntax is incorrect.

    Author Comment

    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.

    Author Comment

    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???
    LVL 12

    Accepted Solution

    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

    Author Closing Comment

    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.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    We have adopted the strategy to use Computers in Student Labs as the bulletin boards. The same target can be achieved by using a Login Notice feature in Group policy but it’s not as attractive as graphical wallpapers with message which grabs the att…
    New Windows 7 Installations take days for Windows-Updates to show up and install. This can easily be fixed. I have finally decided to write an article because this seems to get asked several times a day lately. This Article and the Links apply to…
    Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
    This Micro Tutorial will give you a introduction in two parts how to utilize Windows Live Movie Maker to its maximum capability. This will be demonstrated using Windows Live Movie Maker on Windows 7 operating system.

    728 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

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now