I created a scheduled task on my local machine as follows :
RUN AS : SYSTEM - whether user is logged in or not.
Triggers :
- daily at 9am.
- at system startup
Actions :
- Start a Program.
- c:\ProgramData\Lansweeper\lspush.exe
- Arguments : <Your LS Server>
Conditions :
- Wake computer to run this task.
- Removed all "only run on AC" type conditions.
Settings :
- allow to be run on demand. (important. I'll explain later.)
- Run as soon as possible after a scheduled start is missed.
- stop if it runs more than 1 hr.
- if it doesn't end when requested, force it to stop.
You have to have the LSPush.exe installed in the directory above for this to work.
Once you have it working on your local machine, export it into an XML file.
I use the following script to push the 2 files to a remote machine and install it.
You need this script, psexec, and a file called servers.txt in the same directory. I called this directory LSPUSH.
servers.txt contains a 1 per line list of your target machines.
You want a subdirectory off this folder called CLIENT, that contains lspush.exe, and the xml file from above. I called this Lansweeper.xml. I name any new version of the lspush client lspush.exe and drop it here. That way I don't have to modify the scripts. There is a txt file named after the current version in the clients directory as well.
The below copies the 2 files out. It deletes any task called lansweeper if it exists, then creates the task to run lspush, and finally runs it. I included the delete line in case I updated the xml file.
@echo off
set INSTALL_NAME=lspush.exe
set SERVER_NAME=<YOUR LS SERVER IP OR NAME GOES HERE>
for /F "usebackq delims==" %%I in ("servers.txt") do Call :begin %%I
goto :EOF
:begin
set srv=%1
:get info
mkdir \\%srv%\C$\ProgramData\Lansweeper\
robocopy \\<server>\C$\<path to script>\LSPush\Client \\%srv%\C$\ProgramData\Lansweeper\ %INSTALL_NAME% /r:0 /w:0
robocopy \\<server>\C$\<path to script>\LSPush\Client \\%srv%\C$\ProgramData\Lansweeper\ Lansweeper.xml /r:0 /w:0
psexec \\%srv% c:\windows\system32\SCHTASKS /Delete /TN Lansweeper /F
psexec \\%srv% c:\windows\system32\SCHTASKS /Create /XML "C:\ProgramData\Lansweeper\Lansweeper.xml" /TN Lansweeper
echo %srv% %errorlevel% >> results.txt
psexec \\%srv% c:\windows\system32\SCHTASKS /Run /TN Lansweeper
REM pause
The pause is in there in case I want to review the run 1 machine at a time. A file called results.txt will be created during the run, with standard windows error codes. 0 is good.
If you want to scan a machine remotely with this, and you're getting errors from the web client, you can run this for machines with the scheduled task above installed (note the text file "servers - scan.txt" for this one.) :
(this is why we set it to be run on demand.)
@echo off
set INSTALL_NAME=lspush.exe
set SERVER_NAME=<YOUR LS SERVER IP OR NAME GOES HERE>
for /F "usebackq delims==" %%I in ("servers - scan.txt") do Call :begin %%I
goto :EOF
:begin
set srv=%1
:get info
echo.
echo %srv%
schtasks /run /s %srv% /tn Lansweeper
echo.
pause
If you update lansweeper, and want to update the LSPUSH file for the clients, just run this one. (from the same dir you created on your server above, with the psexec, etc in it.
@echo off
set INSTALL_NAME=lspush.exe
set SERVER_NAME=<YOUR LS SERVER IP OR NAME GOES HERE>
for /F "usebackq delims==" %%I in ("server_update.txt") do Call :begin %%I
goto :EOF
:begin
set srv=%1
:get info
xcopy \\detv-lswp\C$\Scripts\Custom\LSPush\Client\%INSTALL_NAME% \\%srv%\c$\ProgramData\Lansweeper\ /E /Y
psexec \\%srv% c:\windows\system32\SCHTASKS /Run /TN Lansweeper
REM pause
You can create a report under file and registry scanning to look for the following to find out which machines have this installed. This report shows file version for me.
C:\ProgramData\Lansweeper\Lspush.exe
This DOES NOT WORK FOR XP or 2003 series machines. They did task scheduling differently.
I run this from an elevated command prompt on the server, with my domain admin ID currently logged in as the user to the server. It sometimes fails on a non-elevated prompt.
Questions, let me know.