?
Solved

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

Posted on 2009-02-12
15
Medium Priority
?
1,229 Views
Last Modified: 2012-05-06
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!
0
Comment
Question by:supafastr
  • 9
  • 6
15 Comments
 
LVL 21

Expert Comment

by:AmazingTech
ID: 23626200
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
 
LVL 1

Author Comment

by:supafastr
ID: 23629481
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
 
LVL 1

Author Comment

by:supafastr
ID: 23752400
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 21

Expert Comment

by:AmazingTech
ID: 23753357
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
 
LVL 1

Author Comment

by:supafastr
ID: 23757825
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
 
LVL 1

Author Comment

by:supafastr
ID: 23814102
still need a little help....
0
 
LVL 21

Expert Comment

by:AmazingTech
ID: 23814239
Sorry. I'll take a look.
0
 
LVL 21

Expert Comment

by:AmazingTech
ID: 23817401
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
 
LVL 1

Author Comment

by:supafastr
ID: 23859188
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
 
LVL 1

Author Comment

by:supafastr
ID: 23859199
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
 
LVL 1

Author Comment

by:supafastr
ID: 23859227
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
 
LVL 1

Author Comment

by:supafastr
ID: 23859350
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
 
LVL 21

Accepted Solution

by:
AmazingTech earned 2000 total points
ID: 23859706
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
 
LVL 1

Author Closing Comment

by:supafastr
ID: 31546218
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
 
LVL 21

Expert Comment

by:AmazingTech
ID: 24776235
Hey, no problem.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses
Course of the Month16 days, 6 hours left to enroll

850 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