我试图通过PSExec在远程PC上运行一个batch file(在我刚刚写入'记事本'的batch file中)。 下面的psexec命令在我的笔记本电脑上运行,但是在远程PC上无法执行任何操作。 我甚至没有看到在远程机器上的进程列表上运行“记事本”。
c:Program Files (x86)PSTools>psexec -u administrator -p force \135.20.230.160 -s -d cmd.exe /c -c "C:Amtrabogus.bat" PsExec v2.11 - Execute processes remotely copyright (C) 2001-2014 Mark Russinovich Sysinternals - www.sysinternals.com cmd.exe started on 135.24.237.167 with process ID 1520.
任何人都可以帮助我,我哪里错了吗?
谢谢,
Microsoft.SharePoint.PowerShellpipe理单元:不正确的Windows PowerShell版本3.0。 当前控制台支持Window PowerShell 2.0版
没有看到文件系统变化的PowerShell – “找不到path”
你有一个额外的-c你需要摆脱:
psexec -u administrator -p force \135.20.230.160 -s -d cmd.exe /c "C:Amitrabogus.bat"
这里是我现在的解决方案,可以在一个给定的机器或者机器列表上远程运行任何代码。
@echo off :: by Ralph Buchfelder,thanks to Mark Russinovich and Rob van der Woude for their work! :: requires PsExec.exe to be in the same directory (download from http://technet.microsoft.com/de-de/sysinternals/bb897553.aspx) :: troubleshoot remote commands with PsExec arguments -i or -s if neccessary (see http://forum.sysinternals.com/pstools_forum8.html) :: will run *in parallel* on a list of remote pcs (if given); to run serially please remove 'START "" CMD.EXE /C' from the psexec call :: help if '%1' =='-h' ( echo. echo %~n0 echo. echo Runs a command on one or many remote machines. If no input parameters echo are given you will be asked for a target remote machine. echo. echo You will be prompted for remote credentials with elevated privileges. echo. echo UNC paths and local paths can be supplied. echo Commands will be executed on the remote side just the way you typed echo them,so be sure to mind extensions and the path variable! echo. echo Please note that PsExec.exe must be allowed on remote machines,ie echo not blocked by firewall or antivirus solutions. echo. echo Syntax: %~n0 [^<inputfile^>] echo. echo inputfile = a plain text file ^(one hostname or ip address per line^) echo. echo. echo Example: echo %~n0 mylist.txt exit /b 0 ) :checkAdmin >nul 2>&1 "%sYstemROOT%system32cacls.exe" "%sYstemROOT%system32configsystem" if '%errorlevel%' neq '0' ( echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%getadmin.vbs" echo UAC.ShellExecute "%~s0","","runas",1 >> "%temp%getadmin.vbs" "%temp%getadmin.vbs" del "%temp%getadmin.vbs" exit /B ) set ADMINTESTDIR=%WINDIR%system32Test_%rANDOM% mkdir "%ADMINTESTDIR%" 2>NUL if errorlevel 1 ( cls echo ERROR: This script requires elevated privileges! echo. echo Launch by Right-Click / Run as Administrator ... pause exit /b 1 ) else ( rd /s /q "%ADMINTESTDIR%" echo Running with elevated privileges... ) echo. :checkRequirements if not exist "%~dp0PsExec.exe" ( echo PsExec.exe from Sysinternals/Microsoft not found echo in %~dp0 echo. echo Download from http://technet.microsoft.com/de-de/sysinternals/bb897553.aspx echo. pause exit /B ) :environment setlocal echo. echo %~n0 echo _____________________________ echo. echo Working directory: %cd% echo Script directory: %~dp0 echo. SET /P REMOTE_USER=DomainAdministrator : SET "psCommand=powershell -Command "$pword = read-host 'Kennwort' -Assecurestring ; ^ $BSTR=[System.Runtime.InteropServices.Marshal]::securestringToBSTR($pword); ^ [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)"" for /f "usebackq delims=" %%p in (`%psCommand%`) do set REMOTE_PASS=%%p if NOT DEFINED REMOTE_PASS SET /P REMOTE_PASS=Password : echo. if '%1' =='' goto menu SET REMOTE_LIST=%1 :inputMultipleTargets if not exist %rEMOTE_LIST% ( echo File %rEMOTE_LIST% not found goto menu ) type %rEMOTE_LIST% >nul if '%errorlevel%' neq '0' ( echo Access denied %rEMOTE_LIST% goto menu ) set batchProcessing=true echo Batch processing: %rEMOTE_LIST% ... ping -n 2 127.0.0.1 >nul goto runOnce :menu if exist "%~dp0last.computer" set /p LAST_COmpuTER=<"%~dp0last.computer" if exist "%~dp0last.listing" set /p LAST_LISTING=<"%~dp0last.listing" if exist "%~dp0last.directory" set /p LAST_DIRECTORY=<"%~dp0last.directory" if exist "%~dp0last.command" set /p LAST_COMMAND=<"%~dp0last.command" if exist "%~dp0last.timestamp" set /p LAST_TIMESTAMP=<"%~dp0last.timestamp" echo. echo. echo (1) select target computer [default] echo (2) select multiple computers echo ----------------------------------- echo last target : %LAST_COmpuTER% echo last listing: %LAST_LISTING% echo last path : %LAST_DIRECTORY% echo last command: %LAST_COMMAND% echo last run : %LAST_TIMESTAMP% echo ----------------------------------- echo (0) exit echo. echo ENTER your choice. echo. echo. :mychoice SET /P mychoice=(0,1,...): if NOT DEFINED mychoice goto promptSingleTarget if "%mychoice%"=="1" goto promptSingleTarget if "%mychoice%"=="2" goto promptMultipleTargets if "%mychoice%"=="0" goto end goto mychoice :promptMultipleTargets echo. echo Please provide an input file echo [one IP address or hostname per line] SET /P REMOTE_LIST=Filename : goto inputMultipleTargets :promptSingleTarget SET batchProcessing= echo. echo Please provide a hostname SET /P REMOTE_COmpuTER=Target computer : goto runOnce :runOnce cls echo Note: Paths are mandatory for CMD-commands (eg dir,copy) to work! echo Paths are provided on the remote machine via PUSHD. echo. SET /P REMOTE_PATH=UNC-Path or folder : SET /P REMOTE_CMD=Command with params: SET REMOTE_TIMESTAMP=%DATE% %TIME:~0,8% echo. echo Remote command starting (%rEMOTE_PATH%%rEMOTE_CMD%) on %rEMOTE_TIMESTAMP%... if not defined batchProcessing goto runOnceSingle :runOnceMulti REM do for each line; this circumvents PsExec's @file to have stdouts separately SET REMOTE_LOG=%~dp0log%rEMOTE_LIST% if not exist %rEMOTE_LOG% md %rEMOTE_LOG% for /F "tokens=*" %%A in (%rEMOTE_LIST%) do ( if "%rEMOTE_PATH%" =="" START "" CMD.EXE /C ^(%~dp0PSEXEC -u %rEMOTE_USER% -p %rEMOTE_PASS% -h -accepteula \%%A cmd /c "%rEMOTE_CMD%" ^>"%rEMOTE_LOG%%%A.log" 2^>"%rEMOTE_LOG%%%A_debug.log" ^) if not "%rEMOTE_PATH%" =="" START "" CMD.EXE /C ^(%~dp0PSEXEC -u %rEMOTE_USER% -p %rEMOTE_PASS% -h -accepteula \%%A cmd /c "pushd %rEMOTE_PATH% && %rEMOTE_CMD% & popd" ^>"%rEMOTE_LOG%%%A.log" 2^>"%rEMOTE_LOG%%%A_debug.log" ^) ) goto restart :runOnceSingle SET REMOTE_LOG=%~dp0log if not exist %rEMOTE_LOG% md %rEMOTE_LOG% if "%rEMOTE_PATH%" =="" %~dp0PSEXEC -u %rEMOTE_USER% -p %rEMOTE_PASS% -h -accepteula \%rEMOTE_COmpuTER% cmd /c "%rEMOTE_CMD%" >"%rEMOTE_LOG%%rEMOTE_COmpuTER%.log" 2>"%rEMOTE_LOG%%rEMOTE_COmpuTER%_debug.log" if not "%rEMOTE_PATH%" =="" %~dp0PSEXEC -u %rEMOTE_USER% -p %rEMOTE_PASS% -h -accepteula \%rEMOTE_COmpuTER% cmd /c "pushd %rEMOTE_PATH% && %rEMOTE_CMD% & popd" >"%rEMOTE_LOG%%rEMOTE_COmpuTER%.log" 2>"%rEMOTE_LOG%%rEMOTE_COmpuTER%_debug.log" goto restart :restart echo. echo. echo Batch completed. Finished with last errorlevel %errorlevel% . echo All outputs have been saved to %~dp0log%rEMOTE_TIMESTAMP%. echo %rEMOTE_PATH% >"%~dp0last.directory" echo %rEMOTE_CMD% >"%~dp0last.command" echo %rEMOTE_LIST% >"%~dp0last.listing" echo %rEMOTE_COmpuTER% >"%~dp0last.computer" echo %rEMOTE_TIMESTAMP% >"%~dp0last.timestamp" SET REMOTE_PATH= SET REMOTE_CMD= SET REMOTE_LIST= SET REMOTE_COmpuTER= SET REMOTE_LOG= SET REMOTE_TIMESTAMP= ping -n 2 127.0.0.1 >nul goto menu :end SET REMOTE_USER= SET REMOTE_PASS=
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。