PSexec help - open and close programs remotely (PalmDesktop) and overwrite data file(s)

Currently I have 2 PC's that my users walk up to with a Palm Pilot (a Tungsten I think), insert it in the USB cradle, and then use Hotsync to update: the calendar, contacts, and to-do list so it is the same as the 1st PC (the admin. assistant who enters in the data).  The second 2 PC's only need to look at the data, not make any changes to it (aka they never update the calender, contacts, or to-do list themselves).

I wanted to write a small script to copy that data (calender, contacts, to-do list) over the network to a share on each PC.  In one way, that's pretty easy, but I also need it to first have it close the PalmDestop Software on the remote PC's, then copy the new data (it can just overwrite the old data), and then re-start the PalmDesktop program on the remote PC's, all by the admin assistant clicking the link to the script on her desktop.  I think there is a Sysinternals (Now MSoft) program called psexec that can be used to do this, but as my programming skills are worse than a script kiddie, I could really use some help on this.

Bonus points if you can have it first detect if the PalmDesktop software is running on each remote computer and only re-open the software if it was open to begin with!  Also, not erroring out if one of the other computers is "turned off" would be nice...

Thanks everyone!
LVL 1
supafastrAsked:
Who is Participating?
 
AmazingTechConnect With a Mentor Commented:
We need a /d in the xcopy to only display files that are newer in the source than the destination. Also add filtering out the last line "File(s)"
Set RemoteIPs=192.168.100.208,192.168.100.243,192.168.100.215
cls
whoami
for %%a in (%RemoteIPs%) do CALL :PROCESS %%a
GOTO :EOF
 
:PROCESS
ping -n 1 %1 | find /i "reply from"
if errorlevel 1 goto noton
 
Set PalmWasRunning=Unknown
pslist \\%1 palm /accepteula
if not errorlevel 1 Set PalmWasRunning=Yes
 
:: KILL palm process
If "%PalmWasRunning%" == "Yes" pskill \\%1 palm
 
:: OVERWRITE new user data from local desktop
XCOPY /y /s "C:\Program Files\Palm1\UserData" "\\%1\C$\Program Files\Palm1\UserData\*.*"
 
::DELETE UserData files on the remote computer that are not locally found
for /f "tokens=*" %%a in ('XCOPY /d /y /l /s "\\%1\c$\Program Files\Palm1\UserData\*.*" "c:\Program Files\Palm1\UserData" ^| find /i /v "File(s)"') do (
    DEL /f /q "%%a"
)
:: Restart Palm Desktop Software if it was previously running...
::If "%PalmWasRunning%" == "Yes" 
psexec \\%1 -d -i -n 10 -u becca -p passworrd "C:\Program Files\Palm\palm.exe"
whoami
goto :EOF
 
:: Runs if computer is not on, then continues list.
:noton
ECHO %1 is not on.
goto :EOF

Open in new window

0
 
AmazingTechCommented:
PSEXEC was not intended to do this.

You can PSLIST \\{RemoteComputer} to find processes running and then use PSKILL \\{RemoteComputer} to stop a process.

But PSEXEC can run a program but not run it as the user that is logged in. You can run it as you or SYSTEM ACCOUNT and have it interact with the desktop (show it to the user) but it is not the same as if the user started it. So I think the registry settings for the application will not be the same as what the user has them set as.

Anyways this is what should work but you should test it.

Save the code as a .cmd or .bat and start it from the command line with the remote computer name.

It's been awhile since I had to deal with Palm Desktop but I think the exe was called Palm.exe. Can't remember the exact folder and data folder so you'll need to fix these.
ping -n 1 %1 | find /i "reply from"
if errorlevel 1 goto noton
 
Set PalmWasRunning=Unknown
pslist \\%1 palm
if not errorlevel 1 Set PalmWasRunning=Yes
 
If "PalmWasRunning" == "Yes" pskill \\%1 palm
XCOPY /y /s "c:\Program Files\PalmOS\UserData" "\\%1\c$\Program Files\PalmOS\UserData\*.*"
 
::DELETE files on the remote computer that is not here
for /f %%a in ('XCOPY /y /l /s "\\%1\c$\Program Files\PalmOS\UserData\*.*" "c:\Program Files\PalmOS\UserData"') do (
    DEL /f /y "%%a"
)
 
If "PalmWasRunning" == "Yes" psexec \\%1 -d -i "c:\Program Files\PalmOS\palm.exe"
 
goto :EOF
:noton
ECHO %1 is not on.

Open in new window

0
 
supafastrAuthor Commented:
That's some clean looking code.  I will try it out tomorrow or early next week.  Thanks a ton!  I forgot about the psexec is only to execute and there were different programs to list and kill processes...
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

 
supafastrAuthor Commented:
Hey Amazing, I apologize for the delay in getting back to you... I finally got the opportunity yesterday to play with it.

It looked like I had to delete the /y from the DEL command (valid and working in XCOPY command, not valid in DEL)

Just for reference, the default Palm directory for modern installs is C:\Program Files\Palm

I think I just have 2 problems now...
How do the %1 and %%a variables work?  It appears they are causing my issues....

My programming is soo rusty and I can't remember how to properly use those types of variables.  Could you let me know or send me a link to a good guide?

Also, how do I do this for a list of computers (by IP address) or is that what the %1 variable is for?

Thanks a ton, I think this will be good to go soon!

-supafastR

cls
ping 192.168.100.208 -n 1 %1 | find /i "reply from"
if errorlevel 1 goto noton
 
Set PalmWasRunning=Unknown
pslist \\192.168.100.208 palm /accepteula
if not errorlevel 1 Set PalmWasRunning=Yes
 
If "PalmWasRunning" == "Yes" pskill \\192.168.100.208 palm
XCOPY /y /s "c:\Program Files\Palm1\UserData" "\\192.168.100.208\c$\Program Files\Palm1\UserData\*.*"
 
::DELETE files on the remote computer that are not locally found
for /f %%a in ('XCOPY /y /l /s "\\192.168.100.208\c$\Program Files\Palm1\UserData\*.*" "c:\Program Files\Palm1\UserData"') do (
    DEL /f "%%a"
)
 
If "PalmWasRunning" == "Yes" psexec \\192.168.100.208 -d -i "c:\Program Files\Palm\palm.exe"
 
goto :EOF
:noton
ECHO %1 is not on.

Open in new window

0
 
AmazingTechCommented:
I see how you can get confused with this.

First off my bad with using /y with the del command the del command one of the few commands that actually uses /q.

%1 is the first parameter passed into a batch file.

So my intention was to save my code as something like PalmUpdate.cmd or .bar.  Then from a command line type in 'palmupdate {remoteipaddress}'

Your example would be:
palupdate 192.168.100.208

So now every occurance of %1 will change to 192.168.100.208

This is so it is very easy to connect to different IP or computernames.

 I actually haven't found a good site that has these things documented.  I too have learned quite a bit just by looking at some of the EE posts.

Opps it looks like I didn't reference variables correctly either.

With %1 you can get it to change within a batch file by CALLing a label instead GOTOing a label.
Set RemoteIPs=192.168.100.208,192.168.100.243,192.168.100.215
 
for %%a in (%RemoteIPs%) do CALL :PROCESS %%a
GOTO :EOF
 
:PROCESS
CLS
ping -n 1 %1 | find /i "reply from"
if errorlevel 1 goto noton
 
Set PalmWasRunning=Unknown
pslist \\%1 palm
if not errorlevel 1 Set PalmWasRunning=Yes
 
If "%PalmWasRunning%" == "Yes" pskill \\%1 palm
XCOPY /y /s "c:\Program Files\PalmOS\UserData" "\\%1\c$\Program Files\Palm\UserData\*.*"
 
::DELETE files on the remote computer that is not here
for /f %%a in ('XCOPY /y /l /s "\\%1\c$\Program Files\Palm\UserData\*.*" "c:\Program Files\Palm\UserData"') do (
    DEL /f /q "%%a"
)
 
If "%PalmWasRunning%" == "Yes" psexec \\%1 -d -i "c:\Program Files\Palm\palm.exe"
 
goto :EOF
:noton
ECHO %1 is not on.

Open in new window

0
 
supafastrAuthor Commented:
Ok, I made a few minor changes and I think we're almost there.  If you don't mind, please copy my code and make the changes to it... it's a little easier than re-parsing my code.

It does successfully kill the process on the remote computer and copy the data over.

1. It does not delete excess files from the UserData Directory because it is not reading the file path string all the way (it's stopping at the space in "Program Files").  I wonder how many thousands of hours have been lost over Microsoft making the default program directory have that space in there... argh!

2. When the psexec runs, Palm Desktop comes up with an error of: "Error. Invalid Configuration. Terminating the Palm Desktop.
- I think this may be because of the way psexec is starting the program, when I added a -s, it gave a different error that it couldn't even find the user's account.

3. How could I get this code to run where at the end the user who ran it would just see which computers copied successfully and which ones did not?  I tried playing with ECHO off and whatnot, but I'm sure you know a better way that actually works!

Thanks again!



Set RemoteIPs=192.168.100.208,192.168.100.243,192.168.100.215
cls
whoami
for %%a in (%RemoteIPs%) do CALL :PROCESS %%a
GOTO :EOF
 
:PROCESS
ping -n 1 %1 | find /i "reply from"
if errorlevel 1 goto noton
 
Set PalmWasRunning=Unknown
pslist \\%1 palm /accepteula
if not errorlevel 1 Set PalmWasRunning=Yes
 
:: KILL palm process
If "%PalmWasRunning%" == "Yes" pskill \\%1 palm
 
:: OVERWRITE new user data from local desktop
XCOPY /y /s "C:\Program Files\Palm1\UserData" "\\%1\C$\Program Files\Palm1\UserData\*.*"
 
::DELETE UserData files on the remote computer that are not locally found
for /f %%a in ('XCOPY /y /l /s "\\%1\c$\Program Files\Palm1\UserData\*.*" "c:\Program Files\Palm1\UserData"') do (
    DEL /f /q "%%a"
)
:: Restart Palm Desktop Software if it was previously running...
::If "%PalmWasRunning%" == "Yes" 
psexec \\%1 -d -i -n 10 -u becca -p passworrd "C:\Program Files\Palm\palm.exe"
whoami
goto :EOF
 
:: Runs if computer is not on, then continues list.
:noton
ECHO %1 is not on.
goto :EOF

Open in new window

0
 
supafastrAuthor Commented:
still need a little help....
0
 
AmazingTechCommented:
Sorry. I'll take a look.
0
 
AmazingTechCommented:
1. Is fixed with "Tokens=*" in the for.
2. Remotely starting a program for some other user may not be possible. I'm still looking at alternatives.
3. What is successful? Files copied OK and there aren't any extra files?
Set RemoteIPs=192.168.100.208,192.168.100.243,192.168.100.215
cls
whoami
for %%a in (%RemoteIPs%) do CALL :PROCESS %%a
GOTO :EOF
 
:PROCESS
ping -n 1 %1 | find /i "reply from"
if errorlevel 1 goto noton
 
Set PalmWasRunning=Unknown
pslist \\%1 palm /accepteula
if not errorlevel 1 Set PalmWasRunning=Yes
 
:: KILL palm process
If "%PalmWasRunning%" == "Yes" pskill \\%1 palm
 
:: OVERWRITE new user data from local desktop
XCOPY /y /s "C:\Program Files\Palm1\UserData" "\\%1\C$\Program Files\Palm1\UserData\*.*"
 
::DELETE UserData files on the remote computer that are not locally found
for /f "tokens=*" %%a in ('XCOPY /y /l /s "\\%1\c$\Program Files\Palm1\UserData\*.*" "c:\Program Files\Palm1\UserData"') do (
    DEL /f /q "%%a"
)
:: Restart Palm Desktop Software if it was previously running...
::If "%PalmWasRunning%" == "Yes" 
psexec \\%1 -d -i -n 10 -u becca -p passworrd "C:\Program Files\Palm\palm.exe"
whoami
goto :EOF
 
:: Runs if computer is not on, then continues list.
:noton
ECHO %1 is not on.
goto :EOF

Open in new window

0
 
supafastrAuthor Commented:
C:\PsTools>XCOPY /y /s "C:\Program Files\Palm1\UserData" "\\192.168.100.208\C$\P
rogram Files\Palm1\UserData\*.*"
C:\Program Files\Palm1\UserData\userdatafiles.txt
1 File(s) copied

C:\PsTools>for /F "tokens=*" %a in ('XCOPY /y /l /s "\\192.168.100.208\c$\Progra
m Files\Palm1\UserData\*.*" "c:\Program Files\Palm1\UserData"') do (DEL /f /q "%
a" )

C:\PsTools>(DEL /f /q "\\192.168.100.208\c$\Program Files\Palm1\UserData\userdat
afiles.txt" )

C:\PsTools>(DEL /f /q "1 File(s)" )
Could Not Find C:\PsTools\1 File(s)C:\PsTools>XCOPY /y /s "C:\Program Files\Palm1\UserData" "\\192.168.100.208\C$\P
rogram Files\Palm1\UserData\*.*"
C:\Program Files\Palm1\UserData\userdatafiles.txt
1 File(s) copied

C:\PsTools>for /F "tokens=*" %a in ('XCOPY /y /l /s "\\192.168.100.208\c$\Progra
m Files\Palm1\UserData\*.*" "c:\Program Files\Palm1\UserData"') do (DEL /f /q "%
a" )

C:\PsTools>(DEL /f /q "\\192.168.100.208\c$\Program Files\Palm1\UserData\userdat
afiles.txt" )

C:\PsTools>(DEL /f /q "1 File(s)" )
Could Not Find C:\PsTools\1 File(s)

0
 
supafastrAuthor Commented:
sorry, I hit paste and it deleted my comments.  Shown above is what happens.  The XCOPY copying process works, the DEL deleting does not work.
0
 
supafastrAuthor Commented:
Hey, the Palm process now sucessfully relaunches with psexec!  I don't even have to put in the username / password.  It might have been because the Palm software was having a profile issue on the computer I tested... either way, it works now!!  All we have to do is get the deleting to run properly and we're all set!
0
 
supafastrAuthor Commented:
hmmm... it also looks like it is deleting all the files on the remote computer whether they match or not... the xcopy definitely works (I put a PAUSE in to check it), but then the delete command wipes all files in the remote directory.
0
 
supafastrAuthor Commented:
Hey Amazing, sorry for the extreme delay in giving you points.  It's still not perfect, but it definitely works.... so I'm giving you an A for Amazing effort!

Thanks again so much!
Craig
0
 
AmazingTechCommented:
Hey, no problem.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.