バッチファイルをVBSに変換しようとしています。これは私がこれまで持っていたものです。適切な書式設定に関する助言や、このVBSスクリプトが現時点では機能していない理由についての助言を探しています。ここで私はこれまで持っているものです:このバッチをVBS変換が正常に動作するようにする手助けが必要です
OPTION EXPLICIT
DIM strComputer,strSCVA,strDOSBox
strComputer = "." ' local computer
strSCVA = "scva.exe"
strDOSBox = "dosbox.exe"
' Check if scva.exe is running at startup (. = local computer)
IF isProcessRunning(strComputer,strSCVA) THEN
Call LoopStart
ELSE
cd "%~dp0../"
start /min "" "scva.exe"
Call LoopStart
END IF
Sub LoopStart
' Exits script if scva.exe is manually terminated, otherwise, calls CheckDOSBox
IF isProcessRunning(strComputer,strSCVA) THEN
Call CheckDOSBox
ELSE
WScript.Quit
END IF
Sub CheckDOSBox
' Goes to LoopStart while dosbox.exe is running, otherwise, calls Kill
IF isProcessRunning(strComputer,strDOSBox) THEN
Call LoopStart
ELSE
Call Kill
END IF
Sub Kill
' Sends command to terminate scva.exe while scva.exe is running, otherwise, exits script
IF isProcessRunning(strComputer,strSCVA) THEN
taskkill /IM scva.exe
Call Kill
ELSE
WScript.Quit
END IF
' Function to check if a process is running
FUNCTION isProcessRunning(BYVAL strComputer,BYVAL strProcessName)
DIM objWMIService, strWMIQuery
strWMIQuery = "Select * from Win32_Process where name like '" & strProcessName & "'"
SET objWMIService = GETOBJECT("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
IF objWMIService.ExecQuery(strWMIQuery).Count > 0 THEN
isProcessRunning = TRUE
ELSE
isProcessRunning = FALSE
END IF
END FUNCTION
をそしてここで、元のバッチ(私も書いた)に変換されていたファイルです:私は私の問題領域がどのように知っていないと思い
REM Runs scva.exe if it is not running; kills process after dosbox.exe is terminated
tasklist /FI "IMAGENAME eq scva.exe" 2>NUL | find /I /N "scva.exe">NUL
if "%ERRORLEVEL%"=="0" (
goto LoopStart
) else (
cd "%~dp0../"
start /min "" "scva.exe"
goto LoopStart
)
:LoopStart
REM Exits script if scva.exe is manually terminated, otherwise, goes to CheckDOSBox
tasklist /FI "IMAGENAME eq scva.exe" 2>NUL | find /I /N "scva.exe">NUL
if "%ERRORLEVEL%"=="0" (
goto CheckDOSBox
) else (
exit
)
:CheckDOSBox
REM Goes to LoopStart while dosbox.exe is running, otherwise, goes to Kill
tasklist /FI "IMAGENAME eq dosbox.exe" 2>NUL | find /I /N "dosbox.exe">NUL
if "%ERRORLEVEL%"=="0" (
goto LoopStart
) else (
goto Kill
)
:Kill
REM Sends command to terminate scva.exe while scva.exe is running, otherwise, exits script
tasklist /FI "IMAGENAME eq scva.exe" 2>NUL | find /I /N "scva.exe">NUL
if "%ERRORLEVEL%"=="0" (
taskkill /IM scva.exe
goto Kill
)
exit
VBSでプログラムを正しく起動する。私はこれをgoogledしましたが、私はその実装を理解しておらず、誰かが自分のコードでどのように動作するかを私に見せてもらえると助けになります。さらに、VBSのcd "%〜dp0 ../"に相当するものは何ですか?言い換えれば、作業ディレクトリをVBSスクリプトの現在のディレクトリに相対的に設定することと同等ですか?
これは最初の「このコードをどのように変換するのですか」という疑問がありましたが、これは実際に_good_です。 – SomethingDark
また、2つのサブ宣言がありますが、 'end sub'はありません。確かに、私の唯一のVB *の経験はVBAですが、私はあなたがそれらを必要とすると確信しています。 – SomethingDark