![](/img/trans.png)
[英]How can I trigger an autoit python script on a windows device remotely?
[英]How can I remotely execute a script in Windows?
我想讓一個Windows 2003服務器觸發一個腳本來在另一個Windows Server 2008計算機中觸發另一個腳本。
我被告知Powershell可以做到這一點,這很好,但我需要更具體的細節。
有沒有人對此有任何提示?
謝謝!
來自SysInternals的psexec
查看AT命令的語法。 您可以使用它來安排在遠程計算機上運行的進程。
AT命令安排命令和程序在指定的時間和日期在計算機上運行。 必須運行Schedule服務才能使用AT命令。
AT [\\computername] [ [id] [/DELETE] | /DELETE [/YES]]
AT [\\computername] time [/INTERACTIVE]
[ /EVERY:date[,...] | /NEXT:date[,...]] "command"
\\computername Specifies a remote computer. Commands are scheduled on the
local computer if this parameter is omitted.
id Is an identification number assigned to a scheduled
command.
/delete Cancels a scheduled command. If id is omitted, all the
scheduled commands on the computer are canceled.
/yes Used with cancel all jobs command when no further
confirmation is desired.
time Specifies the time when command is to run.
/interactive Allows the job to interact with the desktop of the user
who is logged on at the time the job runs.
/every:date[,...] Runs the command on each specified day(s) of the week or
month. If date is omitted, the current day of the month
is assumed.
/next:date[,...] Runs the specified command on the next occurrence of the
day (for example, next Thursday). If date is omitted, the
current day of the month is assumed.
"command" Is the Windows NT command, or batch program to be run.
最簡單的使用方式將分兩步進行
一個。 將cygwin安裝到遠程PC
灣 運行ssh hudson @ mcs'/cygdrive/c/path_to_script.bat'
談到PsExec
,我強烈建議改用Cygwin / OpenSSH。
SSH具有多種優勢(超過PsExec
工具甚至是定制服務)。
例如,嘗試使用PsExec
並實現這些bash
/ ssh
命令行的功能:
ssh user@remotehost "find . -name something" 2> all.errors.txt
ssh user@remotehost "grep -r something ."
if [ "$?" == "0" ]
then
echo "FOUND"
else
echo "NOT FOUND"
fi
祝好運!
SSH將(!)遠程stdout / stderr / exit狀態傳輸到本地 shell進行檢查
(將遠程執行集成到本地腳本邏輯中的殺手級功能和常見要求)
Cygwin / OpenSSH提供標准的 POSIX shell環境
(有效的時間投入,基本工具,跨平台准備,兼容的習慣等)
您仍然可以/始終運行所有本機 Windows應用程序
(包括cmd
處理器自動執行*.bat
文件)
您可以使用公鑰配置無密碼身份驗證
(考慮無人值守的自動化任務)
小費
最初有一個問題我遇到了問題:
后台sshd
服務必須在用戶的圖形會話中執行應用程序
(使應用程序窗口出現在桌面環境中)。
對我來說可接受的解決方案是直接在用戶的GUI會話中運行sshd
服務
(用戶登錄時自動啟動,按照鏈接查看配置文件更改):
/usr/sbin/sshd -f /home/user/sshd_config
http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/Q_22959948.html接受的解決方案是:
我提供的是一個帶參數的腳本......在這種情況下它需要4. 1)服務器:如果你傳遞-server它只會做那個服務器2)列表:你可以提供服務器的列表文件。 3)服務:您要修改的服務的名稱4)詳細:此處不使用。
我確實有一些錯誤,我在下面的代碼中更改了。 使用剪切/粘貼代碼到名為Set-RemoteService.ps1的文件中。 確保將executionpolicy設置為運行腳本...默認情況下不會。 您可以使用set-executionpolicy cmdlet執行此操作。 PS> Set-Executionpolicy“RemoteSigned”運行您執行的腳本PS> C:\\ PathToScript \\ Set-RemoteService.ps1 -list c:\\ ServerList.txt -service“DHCP”
######################### Param($ server,$ list,$ service,[switch] $ verbose)if($ Verbose){$ VerbosePreference =“Continue”} if($ list){foreach($ srv in(get-content $ list)){$ query =“Select * from Win32_Service where Name ='$ service'”$ myService = get-WmiObject -query $ query -computer $ srv $ myService.ChangeStartMode(“Automatic”)$ myService.Start()}} if($ server){$ query =“Select * from Win32_Service where Name ='$ service '“$ myService = get-WmiObject -query $ query -computer $ server $ myService.ChangeStartMode(”Automatic“)$ myService.Start()}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.