Link to home
Start Free TrialLog in
Avatar of Brian
BrianFlag for United States of America

asked on

PSEXEC help - execute .bat

Hello.
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?
Avatar of SysExpert
SysExpert
Flag of Israel image

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 !
Avatar of Brian

ASKER

That syntax has always worked for me but I'll give it a shot.
Avatar of Brian

ASKER

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.
Avatar of Brian

ASKER

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 - www.sysinternals.com



'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):

Avatar of Brian

ASKER

I got this figured out on my own.
ASKER CERTIFIED SOLUTION
Avatar of Brian
Brian
Flag of United States of America 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
Closed, 250 points refunded.
Vee_Mod
Community Support Moderator