PSEXEC help - execute .bat

Posted on 2007-10-10
Last Modified: 2012-06-27
I'm trying to execute a batch file using PSEXEC on a remote system to map shortcuts to the users desktop. The syntax in my .bat is:

echo F|xcopy "F:\Shortcut to Controlled Documents.lnk" "%userprofile%\desktop\Shortcut to Controlled Documents.lnk" /d /y

I know this works. I've used it hundreds of times.

My syntax for PSEXEC is:

PSEXEC @C:\systemlist.txt -c C:\ConDocs.bat

The connection is made but I get an "invalid drive specification" from PSEXEC when attempting to copy the shortcuts. The return shows that it's trying to copy the shortcut to "C:\Documents and Settings\NetworkService\Desktop\Shortcut to Controlled Documents.lnk" and the NetworkService profile has no "desktop" directory.

What I want PSEXEC to do is run the bat file on the current active user that's logged on to the PC. I know I can do this via GPO at the next logon, but I was trying to just get it out of the way without waiting for users to log off/log on again. Can this be done using the %userprofile% wildcard?
Question by:Haze0830
    LVL 63

    Expert Comment

    Certainly should ne as long as they are already logged in.

    A batch file might need double  %% not single.

    test it.

    I hope this helps !
    LVL 2

    Author Comment

    That syntax has always worked for me but I'll give it a shot.
    LVL 2

    Author Comment

    Well, using two % it's now at least returning the proper user profile. But now I'm getting an error stating "Invalid drive specification". This script works when run from the local PC but NOT when using PSEXEC.
    LVL 2

    Author Comment

    Here's what it returns when using PSEXEC to execute a .bat file, note that in this instance I'm NOT using a profile wildcard and attempting to copy directly to the All Users profile:

    C:\Program Files\Support Tools>psexec \\brianlap1 -c C:\condocs.bat

    PsExec v1.73 - Execute processes remotely
    Copyright (C) 2001-2006 Mark Russinovich
    Sysinternals -

    'C:\WINDOWS\system32>echo F  | xcopy "F:\Shortcut to Controlled Documents.lnk" "C
    :\Documents and Settings\All Users\desktop\Shortcut to Controlled Documents.lnk"
     /d /y
    Invalid drive specification
    0 File(s) copied
    condocs.bat exited on brianlap1 with error code 4.

    Here's what it returns when I run PSEXEC with cmd + arguments (ie NO .bat file used):

    LVL 2

    Author Comment

    I got this figured out on my own.
    LVL 2

    Accepted Solution

    Works with the following syntax:

    LVL 1

    Expert Comment

    Closed, 250 points refunded.
    Community Support Moderator

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    UNC paths question 18 58
    Tool to detect and alert when DNS failover occurs 4 29
    Weird Issues with AD GPOs 5 67
    AutoCad licenses 9 24
    Ever notice how you can't use a new drive in Windows without having Windows assigning a Disk Signature?  Ever have a signature collision problem (especially with Virtual Machines?)  This article is intended to help you understand what's going on and…
    This article offers some helpful and general tips for safe browsing and online shopping. It offers simple and manageable procedures that help to ensure the safety of one's personal information and the security of any devices.
    Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…
    With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

    729 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

    21 Experts available now in Live!

    Get 1:1 Help Now