Script that records softwares need a change.

bsharath
bsharath used Ask the Experts™
on
Hi,

Script that records softwares need a change.
Need a way to log the machines names which were not recorded bacause they were off or they had permission issues.

need to way to record what the exact issue was for it not to record the softwares.

regards
Sharath
@echo off
set ServerLoc=\\inm\Logs\Software_Wise
if not exist %ServerLoc% exit /b

for /F "usebackq tokens=* delims=" %%a in ("%~dp0machins.txt") do call :QueryPC %%a
exit /b

:QueryPC
set pc=%1
if exist temp1.txt del temp1.txt
for /f "tokens=*" %%A in ('reg query "\\%pc%\hklm\software\microsoft\windows\currentversion\uninstall" ^| find /i 

"currentversion\uninstall\"') do (
@echo on
    reg query "\\%pc%\%%A" | find /i "parentkeyname">NUL
    if errorlevel 1 (
        reg query "\\%pc%\%%A" | find /i "systemcomponent" | find /i "0x1">NUL
        if errorlevel 1 (
            for /f "tokens=2,*" %%B in ('reg query "\\%pc%\%%A" ^| find /i " displayname"') do (
                echo %%C>>temp1.txt
            )
        )
    )
)
sort temp1.txt>temp2.txt
set LastLine=
for /f "tokens=*" %%A in (temp2.txt) do (
  if not "%%A"=="!LastLine!" (
    if exist "%ServerLoc%\%%A.txt" (
      findstr /i /b /e /c:"%pc%" "%ServerLoc%\%%A.txt">NUL
      if ERRORLEVEL 1 (
        echo %pc%>>"%ServerLoc%\%%A.txt"
      )
    ) else (
      echo %pc%>>"%ServerLoc%\%%A.txt"
    )
    set LastLine=%%a
  )
)
if exist temp1.txt del temp1.txt
if exist temp2.txt del temp2.txt
exit /b

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Qlemo"Batchelor", Developer and EE Topic Advisor
Top Expert 2015

Commented:
That is difficult as you need to know possible failure reasons already to check against them. The error messages you get without checking before are often misleading or unprecise. I can think of this issues:
  1. machine is unreachable, e.g. off
  2. lack of permission to access the remote registry
  3. Remote Registry service not running on the target machine
  4. unsupported OS. As said, if I use reg.exe remotely applied to W7 x64 it always gives me a "network path not found" error.
I suggest we use ping to test for 1., and else just report the error message (together with the machine).


@echo off
set ServerLoc=\\inm\Logs\Software_Wise
if not exist %ServerLoc% exit /b

for /F "usebackq tokens=* delims=" %%a in ("%~dp0machins.txt") do call :QueryPC %%a
exit /b

:QueryPC
set pc=%1
del temp1.txt err.txt 2>nul
ping -n 1 -w 250 %pc% >nul 2>nul || (
  >>"%ServerLoc%\errors.txt" echo %pc% not reachable
  exit /b 1
)
for /f "tokens=*" %%A in ('reg query "\\%pc%\hklm\software\microsoft\windows\currentversion\uninstall" 2^>err.txt ^| find /i "currentversion\uninstall\"') do (
  reg query "\\%pc%\%%A" | find /i "parentkeyname">NUL
  if errorlevel 1 (
    reg query "\\%pc%\%%A" | find /i "systemcomponent" | find /i "0x1">NUL
    if errorlevel 1 (
      for /f "tokens=2,*" %%B in ('reg query "\\%pc%\%%A" ^| find /i " displayname"') do (
        echo %%C>>temp1.txt
      )
    )
  )
)
if exist err.txt (
  for /F "tokens=*" %%A in (err.txt) do >> "%ServerLoc%\errors.txt" echo %pc% - %%A
  exit /b 1
)
sort temp1.txt>temp2.txt
set LastLine=
for /f "tokens=*" %%A in (temp2.txt) do (
  if not "%%A"=="!LastLine!" (
    if exist "%ServerLoc%\%%A.txt" (
      findstr /i /b /e /c:"%pc%" "%ServerLoc%\%%A.txt">NUL
      if ERRORLEVEL 1 (
        echo %pc%>>"%ServerLoc%\%%A.txt"
      )
    ) else (
      echo %pc%>>"%ServerLoc%\%%A.txt"
    )
    set LastLine=%%a
  )
)
del temp1.txt temp2.txt err.txt 2>nul
exit /b

Open in new window

Author

Commented:
Thanks is the ping added to the code
Qlemo"Batchelor", Developer and EE Topic Advisor
Top Expert 2015

Commented:
Yes, it is doing a ping for testing reachability. If ping fails, or a error message is reported with the reg tool, those are logged into a single file called Errors.Txt in %ServerLoc%.
Expert Spotlight: Joe Anderson (DatabaseMX)

We’ve posted a new Expert Spotlight!  Joe Anderson (DatabaseMX) has been on Experts Exchange since 2006. Learn more about this database architect, guitar aficionado, and Microsoft MVP.

Author

Commented:
Thanks
Where does the log file stored?
Which records all these failures

Author

Commented:
I tested the code and found where it updates the log
But the txt files do not get created with software names
Qlemo"Batchelor", Developer and EE Topic Advisor
Top Expert 2015

Commented:
If there is an error reported, you will not get "software" files.

Author

Commented:
But not even for 1 i get the software listed
Qlemo"Batchelor", Developer and EE Topic Advisor
Top Expert 2015

Commented:
One of several issues with your orignal script is that the registry path for Install information might contain slashes or backslashes, or other characters not allowed in a file name. The following script replaces some of those thru a underscore, making a valid file name.

The script will now output the machine it tests, and kind of a "progress bar", because it will run for some time.

The software files are not created. I had checked for existence of a error file which exists always, and hence the script has skipped logging.
@echo off
setlocal EnableDelayedExpansion
set ServerLoc=\\inm\Logs\Software_Wise
if not exist %ServerLoc% exit /b

for /F "usebackq tokens=* delims=" %%a in ("%~dp0machins.txt") do call :QueryPC %%a
exit /b

:QueryPC
set pc=%1
del temp1.txt err.txt 2>nul
set /p .=%pc% <nul
ping -n 1 -w 250 %pc% >nul 2>nul || (
  >>"%ServerLoc%\errors.txt" echo %pc% not reachable
  echo - not reachable
  exit /b 1
)
for /f "tokens=*" %%A in ('reg query "\\%pc%\hklm\software\microsoft\windows\currentversion\uninstall" 2^>err.txt ^| find /i "currentversion\uninstall\"') do (
  set /P .=.<nul
  reg query "\\%pc%\%%A" | find /i "parentkeyname">NUL
  if errorlevel 1 (
    reg query "\\%pc%\%%A" | find /i "systemcomponent" | find /i "0x1">NUL
    if errorlevel 1 (
      for /f "tokens=2,*" %%B in ('reg query "\\%pc%\%%A" ^| find /i " displayname"') do (
        echo %%C>>temp1.txt
      )
    )
  )
)
echo,
for %%A in (err.txt) do if %%~zA GTR 0 (
  for /F "tokens=*" %%A in (err.txt) do >> "%ServerLoc%\errors.txt" echo %pc% - %%A
  exit /b 1
)
sort temp1.txt>temp2.txt
set LastLine=
for /f "tokens=*" %%A in (temp2.txt) do (
  set sw=%%A
  set sw=!sw:/=_!
  set sw=!sw:\=_!
  if not "!sw!"=="!LastLine!" (
    if exist "%ServerLoc%\!sw!.txt" (
      findstr /i /b /e /c:"%pc%" "%ServerLoc%\!sw!.txt">NUL || >>"%ServerLoc%\!sw!.txt" echo %pc%
    ) else (
      >>"%ServerLoc%\!sw!.txt" echo %pc%
    )
    set LastLine=!sw!
  )
)
del temp1.txt temp2.txt err.txt 2>nul
exit /b

Open in new window

Author

Commented:
Thanks testing it
The script runs for 10 hrs to complete 600 systems.
Is there any wa we can speed it up
Qlemo"Batchelor", Developer and EE Topic Advisor
Top Expert 2015

Commented:
I reckon this is why the script is a logon script originally. With 600 machines, it is not recommended to start a central scan often.

There are several ways I can think of:
  1. running the scripts locally on each machine - that can be done by using psexec from www.sysinternals com.
  2. running each machine's scan in a own "thread" - that will put a high load on the executing machine, as it has to do 600 processes in-parallel.
The best option is the first one. You will need to put the script into a location which is reachable by each machine, let's say it is \\inm\Scripts\querysw.cmd. PsExec needs to be in the same folder. I have not changed the scanning process - while it is unnecessary to use the \\%pc%\HKLM\... syntax locally, it doesn't harm, and it isn't slower. You can remove that, if you like, and the script will look more like the original script then.

psexec \\pc -i -d cmd.exe ...    will start a interactive (-i) command prompt on PC, and not waiting for terminating (-w). So it should run at all machines "at once". There is some (low) probability that the output into the files will get garbled thru the massive parallel write operations, but I reckon it is worth a try.

Having said and done that all, it is much better to start a local script each time the PC is switched on. That can be implemented by using a event triggered scheduled task. Doing that will keep the busy times short and propagated over a larger time span.

@echo off
setlocal EnableDelayedExpansion
set ServerLoc=\\inm\Logs\Software_Wise
set ScriptLoc=\\inm\Scripts
if not exist %ServerLoc% exit /b
if not exist %ScriptLoc%\%~nx exit /b

if NOT "%1" == "" goto QueryPC

for /F "usebackq tokens=* delims=" %%a in ("%~dp0machins.txt") do (
  set /p .=%%a <nul
  ping -n 1 -w 250 %%a >nul 2>nul && (
    echo - spawn scanner
    %ScriptLoc%\psexec \\%%a -d -i cmd /c %ScriptLoc%\%~nx0 Scan
  ) || (
    >>"%ServerLoc%\errors.txt" echo %%a not reachable
    echo - not reachable
  )
)
exit /b 0


:QueryPC
set pc=%computername%
del temp1.txt err.txt 2>nul

for /f "tokens=*" %%A in ('reg query "\\%pc%\hklm\software\microsoft\windows\currentversion\uninstall" 2^>err.txt ^| find /i "currentversion\uninstall\"') do (
  set /P .=.<nul
  reg query "\\%pc%\%%A" | find /i "parentkeyname">NUL
  if errorlevel 1 (
    reg query "\\%pc%\%%A" | find /i "systemcomponent" | find /i "0x1">NUL
    if errorlevel 1 (
      for /f "tokens=2,*" %%B in ('reg query "\\%pc%\%%A" ^| find /i " displayname"') do (
        echo %%C>>temp1.txt
      )
    )
  )
)
echo,
for %%A in (err.txt) do if %%~zA GTR 0 (
  for /F "tokens=*" %%A in (err.txt) do >> "%ServerLoc%\errors.txt" echo %pc% - %%A
  exit /b 1
)
sort temp1.txt>temp2.txt
set LastLine=
for /f "tokens=*" %%A in (temp2.txt) do (
  set sw=%%A
  set sw=!sw:/=_!
  set sw=!sw:\=_!
  if not "!sw!"=="!LastLine!" (
    if exist "%ServerLoc%\!sw!.txt" (
      findstr /i /b /e /c:"%pc%" "%ServerLoc%\!sw!.txt">NUL || >>"%ServerLoc%\!sw!.txt" echo %pc%
    ) else (
      >>"%ServerLoc%\!sw!.txt" echo %pc%
    )
    set LastLine=!sw!
  )
)
del temp1.txt temp2.txt err.txt 2>nul
exit /b 0

Open in new window

Author

Commented:
Sorry by mistake closed the Q. For the psexec code i get this

The following usage of the path operator in batch-parameter
substitution is invalid: %~nx exit /b

For valid formats type CALL /? or FOR /?
The syntax of the command is incorrect.
Qlemo"Batchelor", Developer and EE Topic Advisor
Top Expert 2015

Commented:
Thanks, Modalot.

bsharath,
Line 6 is failing. See code below for correction.
There is another issue - you need to have access to the serverlocation with your account from each machine. You might have to add the switches for user and password to psexec, as in

2>nul %ScriptLoc%\psexec \\%%a -d -i -u MyDomain\MyUser -p MyPwd cmd /c %ScriptLoc%\%~nx0 Scan
@echo off
setlocal EnableDelayedExpansion
set ServerLoc=\\inm\Logs\Software_Wise
set ScriptLoc=\\inm\Scripts
if not exist %ServerLoc% exit /b
if not exist %ScriptLoc%\%~nx0 exit /b

if NOT "%1" == "" goto QueryPC

for /F "usebackq tokens=* delims=" %%a in ("%~dp0machins.txt") do (
  set /p .=%%a <nul
  ping -n 1 -w 250 %%a >nul 2>nul && (
    echo - spawn scanner
    2>nul %ScriptLoc%\psexec \\%%a -d -i cmd /c %ScriptLoc%\%~nx0 Scan
    echo.>nul
  ) || (
    >>"%ServerLoc%\errors.txt" echo %%a not reachable
    echo - not reachable
  )
)
exit /b 0


:QueryPC
set pc=%computername%
del temp1.txt err.txt 2>nul

for /f "tokens=*" %%A in ('reg query "\\%pc%\hklm\software\microsoft\windows\currentversion\uninstall" 2^>err.txt ^| find /i 

"currentversion\uninstall\"') do (
  set /P .=.<nul
  reg query "\\%pc%\%%A" | find /i "parentkeyname">NUL
  if errorlevel 1 (
    reg query "\\%pc%\%%A" | find /i "systemcomponent" | find /i "0x1">NUL
    if errorlevel 1 (
      for /f "tokens=2,*" %%B in ('reg query "\\%pc%\%%A" ^| find /i " displayname"') do (
        echo %%C>>temp1.txt
      )
    )
  )
)
echo,
for %%A in (err.txt) do if %%~zA GTR 0 (
  for /F "tokens=*" %%A in (err.txt) do >> "%ServerLoc%\errors.txt" echo %pc% - %%A
  exit /b 1
)
sort temp1.txt>temp2.txt
set LastLine=
for /f "tokens=*" %%A in (temp2.txt) do (
  set sw=%%A
  set sw=!sw:/=_!
  set sw=!sw:\=_!
  if not "!sw!"=="!LastLine!" (
    if exist "%ServerLoc%\!sw!.txt" (
      findstr /i /b /e /c:"%pc%" "%ServerLoc%\!sw!.txt">NUL || >>"%ServerLoc%\!sw!.txt" echo %pc%
    ) else (
      >>"%ServerLoc%\!sw!.txt" echo %pc%
    )
    set LastLine=!sw!
  )
)
del temp1.txt temp2.txt err.txt 2>nul
exit /b 0

Open in new window

Author

Commented:
Thanks
Thje logged in machine is a domain admin from where i will run. So can psexec take those priveledges.
what would the change be
Qlemo"Batchelor", Developer and EE Topic Advisor
Top Expert 2015

Commented:
It should already use that account, so you should not need to change anything.

Author

Commented:
No output created i get the data as below
'\\inm\Logs\Sof_Wise'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported.  Defaulting to Windows directory.

C:\WINDOWS>setlocal EnableDelayedExpansion

C:\WINDOWS>set ServerLoc=\\inm\Logs\Sof_Wise\1

C:\WINDOWS>set ScriptLoc=\\inm\Logs\Sof_Wise

C:\WINDOWS>if not exist \\inm\Logs\Sof_Wise\1 exit /b

C:\WINDOWS>if not exist \\inm\Logs\Sof_Wise\Sof_Wise_Psexec.bat
 exit /b

C:\WINDOWS>if NOT "" == "" goto QueryPC

C:\WINDOWS>for /F "usebackq tokens=* delims=" %a in ("\\inm\logs\Sof_Wise\machines.txt") do (
set /p .=%a  0<nul
 ping -n 1 -w 250 %a   1>nul 2>nul  && (
echo - spawn scanner
 \\inm\Logs\Sof_Wise\psexec \\%a -d -i cmd /c \\inm\Logs\Sof_Wise\Sof_Wise_Psexec.bat Scan 2>nul
 echo.1>nul
)  || (
echo %a not reachable 1>>"\\inm\Logs\Sof_Wise\1\errors.txt"
 echo - not reachable
)
)

C:\WINDOWS>(
set /p .=pc439  0<nul
 ping -n 1 -w 250 pc439   1>nul 2>nul  && (
echo - spawn scanner
 \\inm\Logs\Sof_Wise\psexec \\pc439 -d -i cmd /c \\in-ict-
dsm\Logs\Software_Wise\Software_Wise_Psexec.bat Scan 2>nul
 echo.1>nul
)  || (
echo pc439 not reachable 1>>"\\inm\Logs\Sof_Wise\1\errors.
txt"
 echo - not reachable
)
)
pc439 - spawn scanner

Open in new window

Qlemo"Batchelor", Developer and EE Topic Advisor
Top Expert 2015

Commented:
For debugging, remove the 2>nul from psexec, and change the cmd /c to cmd /k. You should see the messages from psexec locally, and  of cmd on the remote machine.

Author

Commented:
I pit a pause at the end to see whats going in but the command prompt closes
"Batchelor", Developer and EE Topic Advisor
Top Expert 2015
Commented:
Sorry, I needed some spare time for testing ...
The script is more reliable now, and gives more feedback. You should be able to see where an error appears, if any. In addition, the script waits until all scans are finished (managed via the %pc%.active file).
Attention, the machine list is now contained in machines.lst, because that is much easier then to just delete all *.txt files when testing ...

@echo off
setlocal EnableDelayedExpansion
set ServerLoc=\\inm\Logs\Software_Wise
set ScriptLoc=\\inm\Scripts

if not exist "%ServerLoc%"            (@echo ServerLoc not reachable& exit /b 1)
if not exist "%ScriptLoc%\%~nx0"      (@echo Script not found&        exit /b 1)
if not exist "%ScriptLoc%\psexec.exe" (@echo PsExec not found&        exit /b 1)

if NOT "%1" == "" goto QueryPC

for /F "usebackq tokens=* delims=" %%a in ("%~dp0machines.lst") do (
  set /p .=%%a <nul
  ping -n 1 -w 250 %%a >nul 2>nul && (
    echo - spawn scanner
    %ScriptLoc%\psexec \\%%a -d -i cmd /c %ScriptLoc%\%~nx0 Scan
    echo,>nul
  ) || (
    >>"%ServerLoc%\errors.txt" echo %%a not reachable
    echo - not reachable
  )
)
echo,
echo Wait for completion 
:loop
  dir %serverloc%\*.active >nul 2>nul || exit /b 0 
  set /p .=.<nul
  ping -n 6 127.0.0.1 >nul
goto loop


@REM This part will be executed on the remote machine!
:QueryPC
set pc=%computername%
del %temp%\temp1.txt %temp%\err.txt 2>nul
copy nul "%ServerLoc%\%pc%.active" >nul

setlocal DisableDelayedExpansion
for /f "tokens=*" %%A in (
  'reg query "hklm\software\microsoft\windows\currentversion\uninstall" 2^>%temp%\err.txt ^| find /i "currentversion\uninstall\"'
) do (
  set /P .=.<nul
  reg query "%%A" >nul 2>nul || @echo Error @ "%%A" >con
  reg query "%%A" | find /i "parentkeyname" >NUL
  if errorlevel 1 (
    reg query "%%A" | find /i "systemcomponent" | find /i "0x1" >NUL
    if errorlevel 1 (
      for /f "tokens=2,*" %%B in ('reg query "%%A" ^| find /i " displayname"') do (
        >>%temp%\temp1.txt echo %%C
      )
    )
  )
)
endlocal
echo,
for %%A in (%temp%\err.txt) do if %%~zA GTR 0 (
  for /F "tokens=*" %%A in (%temp%\err.txt) do >> "%ServerLoc%\errors.txt" echo %pc% - %%A
  del "%ServerLoc%\%pc%.active" 2>nul >nul
  exit /b 1
)
sort %temp%\temp1.txt /o %temp%\temp2.txt
set LastLine=
for /f "tokens=*" %%A in (%temp%\temp2.txt) do (
  set /P .=*<nul
  set sw=%%A
  set sw=!sw:/=_!
  set sw=!sw:\=_!
  set sw=!sw::=_!
  rem @echo,%%A   =>  !sw!
  if not "!sw!"=="!LastLine!" (
    if exist "%ServerLoc%\!sw!.txt" (
      findstr /i /b /e /c:"%pc%" "%ServerLoc%\!sw!.txt">NUL || >>"%ServerLoc%\!sw!.txt" echo %pc%
    ) else (
      >>"%ServerLoc%\!sw!.txt" echo %pc%
    )
    set LastLine=!sw!
  )
)
del %temp%\temp1.txt %temp%\temp2.txt err.txt 2>nul
del "%ServerLoc%\%pc%.active" 2>nul >nul
exit /b 0

Open in new window

Author

Commented:
Thanks i dont know why its not working
I removed echo and paused but it does not show whats happening
Can you give the change to pause after each machine run please
Qlemo"Batchelor", Developer and EE Topic Advisor
Top Expert 2015

Commented:
Insert a pause between line 21 and 22 to get a per-machine execution.

Remember - to see what is happening in the second part (:QueryPC), you need to look on the remote machine itself!

Author

Commented:
I get this
'\\dsm\logs\Software_Wise'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported.  Defaulting to Windows directory.

C:\WINDOWS>setlocal EnableDelayedExpansion

C:\WINDOWS>set ServerLoc=\\dsm\logs\Software_Wise

C:\WINDOWS>set ScriptLoc=\\dsm\logs\software_wise

C:\WINDOWS>if not exist "\\dsm\logs\Software_Wise" ()

C:\WINDOWS>if not exist "\\dsm\logs\software_wise\Software_Wise_latest.ba
t" ()

C:\WINDOWS>if not exist "\\dsm\logs\software_wise\psexec.exe" ()

C:\WINDOWS>if NOT "" == "" goto QueryPC

C:\WINDOWS>for /F "usebackq tokens=* delims=" %a in ("\\dsm\logs\Software
_Wise\machines.txt") do (
set /p .=%a  0<nul
 ping -n 1 -w 250 %a   1>nul 2>nul  && (
echo - spawn scanner
 \\dsm\logs\software_wise\psexec \\%a -d -i cmd /c \\dsm\logs\soft
ware_wise\Software_Wise_latest.bat Scan
 echo, 1>nul
)  || (
echo %a not reachable 1>>"\\dsm\logs\Software_Wise\errors.txt"
 echo - not reachable
)
)

C:\WINDOWS>(
set /p .=Sopk  0<nul
 ping -n 1 -w 250 Sopk   1>nul 2>nul  && (
echo - spawn scanner
 \\dsm\logs\software_wise\psexec \\Sopk -d -i cmd /c \\dsm\
logs\software_wise\Software_Wise_latest.bat Scan
 echo, 1>nul
)  || (
echo Sopk not reachable 1>>"\\dsm\logs\Software_Wise\errors.txt"

 echo - not reachable
)
)
Sopk - spawn scanner

PsExec v1.96 - Execute processes remotely
Copyright (C) 2001-2009 Mark Russinovich
Sysinternals - www.sysinternals.com


cmd started on Sopk with process ID 5064.

C:\WINDOWS>Pause
Press any key to continue . . .

Open in new window

Qlemo"Batchelor", Developer and EE Topic Advisor
Top Expert 2015

Commented:
... and that is ok. On Sopk, you should see a cmd box running, displaying the progress dots or asterisks.

Author

Commented:
After that Pause the cmd prompt closes...
Qlemo"Batchelor", Developer and EE Topic Advisor
Top Expert 2015

Commented:
Yes, it does, if no scan is active anymore, that is no  *.active file is in the ServerLoc.

Author

Commented:
I tried with 50 machines and for all i get
not reachable
in the errors.txt
Even though the machines are Online
And some names are not in the errors.txt for those the output is not created
Qlemo"Batchelor", Developer and EE Topic Advisor
Top Expert 2015

Commented:
All names of machines not reachable should be in the errors.txt.
"Not reachable" can mean:
  • Name cannot be resolved to corresponding IP address
  • machine is not answering within 250 milliseconds
  • machine is off
You can change the -w 250 in the first ping to a higher number, but that will slow down scanning if machines are not available.

You should test with each error case only, that is with a machine you can't see any scanning, but there is no errors.txt entry; then pinging a machine you are certain is online but reported as not reachable.

This kind of scanning process cannot be made foolproof and 100% reliable, because of the nature of tests and diversity of problems which can arise.

Author

Commented:
Ok i increased the sec to 500
and placed 10 machine names in the txt file
5 are pinging and 5 are not. the 5 machines that are not pininging i got those names in the errors.txt
and the other 5 no data captured no idea what happened.
I have 3 files, the script. machines.txt and psexec in a folder in UNC path. and i am running the script via UNC path
Any clues why all are failing
Qlemo"Batchelor", Developer and EE Topic Advisor
Top Expert 2015

Commented:
Not at all.
- The script (first part) is checking if psexec is in the script folder, and if any folder is missing.
- psexec would output if it could not start the batch file, e.g. because it has no access to the share

Change the cmd /c of psexec to cmd /k, run it for one of the machines which should be reachable and you can log in physically (at least per RDP), and then look at the cmd box appearing. It should output errors, and that will give us a trace what is going on. (Close the cmd prompt when you are ready.)

Author

Commented:
I changed the /c to /k but no change
For example i have taken my machine and the machine i am runing the script on as both are Xp machines and did work before.
But still no output
In the cmd prompt i can see not reachable
But in this case the errors.txt itself is not created.

Could there be a ping issue?
Qlemo"Batchelor", Developer and EE Topic Advisor
Top Expert 2015

Commented:
If "not reachable" is displayed, the ping did not succeed. And it *has to* be logged in errors.txt. As soon as the script has access to the server location, there is nothing I can see why it should not log errors. And if "not reachable", nothing else happens, of course, because the script thinks it is useless to run a script on a non-existing or switched-off machine.

Why isn't the local machine reachable? Do you block ICMP, e.g. in Windows Firewall?

Author

Commented:
Not sure why its not running on local machine too

I have these lines as this

setlocal EnableDelayedExpansion
set ServerLoc=\\dsm\Logs\Software_Wise
set ScriptLoc=\\dsm\logs\software_wise

I have the machines.txt and psexec.exe both in the same folder as the script

I get the lines as this

echo phos not reachable 1>>"\\dsm\Logs\Software_Wise\errors.txt"

 echo - not reachable
)
)
phos - spawn scanner


But the errors.txt is not created where as in the cmd it says not reachable
Qlemo"Batchelor", Developer and EE Topic Advisor
Top Expert 2015

Commented:
You are intermixing the debugging output (echoing of each line as it is executed) with the output of the script itself. The line "phos - spawn scanner" tells me that it is (trying) running psexec. The lines before are echos because of @echo off removed.

Author

Commented:
Thank you... :-)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial