我有一个.bat
文件来启动Windows服务。当我手动运行它时,它工作正常,但如果从任务计划程序运行它,则会出现以下错误。
'psexec64.exe' is not recognized as an internal or external command,
operable program or batch file.
The system cannot find the file sessid.txt.
Press any key to continue . . .
我尝试了以下情况
psexec64.exe
和psexec.exe
psexec
路径仍然没有运气
@echo off
setlocal enabledelayedexpansion
set username=user1
set usr=bdomain\user1
set password=2018
set machine=192.168.1.16
psexec64.exe \\%machine% -u %usr% -p %password% query session %username%>D:\Service_Start\sessid.txt
set /a counter=0
for /F "tokens=* skip=1" %%a in (sessid.txt) do (
for %%b in (%%a) do (
set /a counter+=1
if !counter! == 3 (
psexec64.exe \\192.168.1.16 -u bdomain\user1 -p 2018 -i %%b -d net start OracleServiceTest
)
)
)
pause;
答案 0 :(得分:0)
按如下所示修改了代码,并且可以正常工作
setlocal enabledelayedexpansion
set username=user1
set usr=bdomain\user1
set password=2018
set machine=192.168.1.16
D:\PSTools\psexec64.exe \\%machine% -u %usr% -p %password% query session %username%>D:\Service_Start\sessid.txt
set /a counter=0
for /F "tokens=* skip=1" %%a in (D:\Service_Start\sessid.txt) do (
for %%b in (%%a) do (
set /a counter+=1
if !counter! == 3 (
D:\PSTools\psexec64.exe \\192.168.1.16 -u bdomain\user1 -p 2018 -i %%b -d net start OracleServiceTest
)
)
)