Pages - Menu

2020年2月26日 星期三

[AutoIT]執行命令提示字元並編輯桌面圖式

前言

工作上用到,不想每台電腦都操作一次。
會動到桌面上的捷徑、環境變數、檔案複製,光靠批次檔沒辦法做。
只好搞AutoIT了。



正文

1.先建立資料夾
2.增加系統環境變數
3.複製nas的檔案到剛剛建立的資料夾
4.判斷安裝的Creo版本是哪個,有就繼續沒有則離開。
5.找到桌面捷徑後,按下內容,修改開始位置為剛剛建立的資料夾。


#Include <GuiListView.au3>
#include <MsgBoxConstants.au3>
;執行命令CMD
$CMD = "mkdir D:\Creo_Work"
RunWait(@ComSpec & " /c " & $CMD)
delay(1000)
;修改環境變數
$CMD = "setx /m PTC_WF_ROOT D:\Creo_Work"
RunWait(@ComSpec & " /c " & $CMD)
delay(1000)
;~ 複製Config.pro至資料夾
$CMD = "copy \\192……\config.pro D:\Creo_Work\"
RunWait(@ComSpec & " /c " & $CMD)
delay(1000)
;尋找桌面上的捷徑
$strProcessM20 ="Creo Parametric 4.0 M020" ;需要操作的桌面圖示名稱
$strProcessM90 = "Creo Parametric 4.0 M090"
$strProcessM100 = "Creo Parametric 4.0 M100"
$handle = WinGetHandle("Program Manager") ;桌面視窗控制代碼
$ctrl = ControlGetHandle("Program Manager","","SysListView321")  ;控制元件控制代碼
$seIndex = ControlListView($handle,"",$ctrl,"FindItem",$strProcessM20) ;獲取需要操作的圖示在父控制元件中的順序號,可以使用Accexplorer檢視
If $seIndex = -1 Then
   $seIndex = ControlListView($handle,"",$ctrl,"FindItem",$strProcessM90)
   If $seIndex = -1 Then
      $seIndex = ControlListView($handle,"",$ctrl,"FindItem",$strProcessM100)
      If $seIndex = -1 Then
         MsgBox($MB_SYSTEMMODAL, "", "M020,M090,M100 Not Found")
         Exit
      EndIf
   EndIf
EndIf
;MsgBox($MB_SYSTEMMODAL, "", "M020,M090,M100 Found")
;Exit
$seIconX=_GUICtrlListView_GetItemPositionX($ctrl, $seIndex)
$seIconY=_GUICtrlListView_GetItemPositionY($ctrl, $seIndex)
MouseMove($seIconX+10,$seIconY+10)
MouseClick("right", $seIconX+10,$seIconY+10, 2)
send("R")
Sleep(1000)
send("{TAB}")
Sleep(1000)
send("D:\Creo_Work")
func delay($val)
   Sleep($val)
EndFunc

ref.
使用AutoIt通過桌面圖示點選的方式執行程式
ControlListView
need to execute cmd commands
If...ElseIf...Else...EndIf
批處理bat實現建立、複製、刪除檔案及資料夾
如何利用 [CMD 批次檔 .bat] 設定環境變數 永久與暫時
MsgBox
Send
如何使用AutoIt(*.au3)腳本在CMD窗口中發出命令?

沒有留言:

張貼留言