다음 .VBS는 (구문을 용서하시기 바랍니다) 실행 방법에 어떤 문제없이 원하는 작업을 만듭니다 명령 : 그러나VBScript를 - 전달합니다 schtasks은
Option Explicit
Dim wshell
Set wshell = CreateObject("WScript.Shell")
wshell.Run "schtasks /create /sc once /tn ""Reminder"" /tr ""C:\Windows\System32\cmd.exe \""/c title Alert & mode con: cols=40 lines=10 & color f0 & cls & echo *** Message goes here *** & echo. & echo. & echo. & echo. & echo. & echo. & echo. & echo Press any key to exit & pause > nul\"""" /st 18:00 /sd 08/20/2016 /f"
나는 다음과 같은 변수를 통해 schtasks
명령 문자열을 전달하려고하면 :
Option explicit
dim strdate, strtime, strmessage, strtask, wshell
strdate = "08/20/2016"
strtime = "18:30"
strmessage = "Turn off pump"
WScript.Echo strdate
WScript.Echo strtime
WScript.Echo strmessage
strtask = """schtasks /create /sc once /tn """"Reminder"""" /tr """"C:\Windows\System32\cmd.exe \""""/c title Alert & mode con: cols=40 lines=10 & color f0 & cls & echo " & strmessage & " & echo. & echo. & echo. & echo. & echo. & echo. & echo. & echo Press any key to exit & pause > nul"""""""" /st " & strtime & " /sd " & strdate & " /f""" & " ,0" & " ,true"
WScript.Echo strtask
Set wshell = CreateObject("WScript.Shell")
wshell.Run strtask
내가받을 다음과 같은 오류 :
나는 왜 이것을 얻고 있는지 이해할 수 없다. 분석되는 변수는 결국 (인용 부호를 포함한) 이전 스 니펫과 동일하다. 누군가 내가 설명하지 못한 것을 설명해 줄 수 있었 을까? 안스 Wiechers '지침에
편집
감사합니다. 필자는 실행 명령 옵션을 제거하고 대신 본질적으로 외부 명령 오류가 있는지 확인하여 작동하지 않더라도 비효율적 인 스크립트를 얻을 수있었습니다. 아래 참조 :
option explicit
dim strdate, strtime, strmessage, strtask, exitcode, wshell
strdate = "08/21/2016"
strtime = "13:45"
strmessage = "Turn off pump"
WScript.Echo strdate
WScript.Echo strtime
WScript.Echo strmessage
strtask = "schtasks /create /sc once /tn ""Reminder"" /tr ""C:\Windows\System32\cmd.exe \""/c title Alert & mode con: cols=40 lines=10 & color f0 & cls & echo " & strmessage & " & echo. & echo. & echo. & echo. & echo. & echo. & echo. & echo Press any key to exit & pause > nul\"""" /st " & strtime & " /sd " & strdate & " /f"
set wshell = CreateObject("WScript.Shell")
exitcode = wshell.Run(strtask, 0, True)
if exitcode <> 0
then WScript.Echo "External command failed: " & Hex(exitcode)
End If
I을 많은 도움을 주셔서 감사합니다. 내 스크립트에서 오류 검사를 확실히 사용할 것입니다 (즉, 외부 명령의 상태를 검사 할 때 - 오류가있는 명령문을 사용하여이 작업을 수행 할 수 있습니까?) 분명히 명확하지만 배치 파일을 사용하지 않기로했습니다. 최선의 선택, 합병증에도 불구하고 나는 하나의 파일에서 모든 것을 실행하는 것을 선호한다 ... 내가 할 수 있다면, 후속 질문을 가지고있다. 왜 나는'strtask'가 나중에 실행 명령 옵션을 추가 할 때만 구문 분석을 하는가? –
외부 명령의 경우 내 대답과 같이 종료 코드를 확인해야합니다. 'On Error'는 VBScript 에러의 에러 처리만을 제어합니다. 외부 명령의 오류에 대해서는 알지 못합니다. 귀하의 추가 질문은 [documentation] (https://msdn.microsoft.com/en-us/library/d5fk67ky%28v=vs.84%29.aspx)에 의해 답변됩니다. 'Run' 메서드는 명령 문자열과 두 개의 다른 옵션을 취합니다. 명령 문자열에서 이러한 옵션을 구문 분석하지 않습니다. –
감사합니다. Ansgar! :) –