Nice programing

Windows에서 예약 된 작업을 통해 URL을로드하는 데 권장되는 방법

nicepro 2020. 12. 13. 11:06
반응형

Windows에서 예약 된 작업을 통해 URL을로드하는 데 권장되는 방법


적어도 하루에 한 번로드되는지 확인해야하는 Windows 상자에 호스팅 된 웹 페이지가 있습니다. 내 현재 계획은 Internet Explorer를 열고 URL을 입력하는 예약 된 작업을 만드는 것입니다.

"C:\Program Files\Internet Explorer\iexplore.exe" myurl.com/script_to_run_daily.aspx

이것은 설정이 간단하고 잘 작동하지만 Internet Explorer가 실제로이 URL을 열고 눌러야하기 때문에 해킹이라고 생각합니다. 이 페이지에서 다시 입력 할 필요가 없습니다. 단순히 캐시 된 데이터를 파일에 저장하기 만하면됩니다.

이를 수행하는 더 매끄러운 방법이 있습니까? 중요한 경우에는 VB.net 사이트입니다.

미리 감사드립니다!


Remus Rusanu가 지적했듯이 PowerShell은 갈 길입니다. 다음은 별도의 .ps1 파일을 작성할 필요없이 예약 된 작업을 만드는 데 사용할 수있는 간단한 한 줄입니다.

powershell -ExecutionPolicy Bypass -Command
    Invoke-WebRequest 'http://localhost/cron.aspx' -UseBasicParsing

줄 바꿈은 이러한 모든 명령 줄에서 명확성을 위해 추가되었습니다. 명령을 실행하기 전에 제거하십시오.

다음과 같이 예약 된 작업을 만들 수 있습니다. (승격 된 명령 프롬프트에서 실행)

schtasks /create /tn "MyAppDailyUpdate"
    /tr "powershell -ExecutionPolicy Bypass -Command
        Invoke-WebRequest 'http://localhost/cron.aspx' -UseBasicParsing"
    /sc DAILY /ru System

위의 내용은 PowerShell 3 이상에서 작동합니다. 이전 버전에서 작동하는 것이 필요한 경우 여기에 한 줄짜리가 있습니다.

powershell -ExecutionPolicy unrestricted -Command
    "(New-Object Net.WebClient).DownloadString(\"http://localhost/cron.aspx\")"

다음과 같이 예약 된 작업을 만들 수 있습니다. (승격 된 명령 프롬프트에서)

schtasks /create /tn "MyAppDailyUpdate"
    /tr "powershell -ExecutionPolicy unrestricted -Command
        \"(New-Object Net.WebClient).DownloadString(\\\"http://localhost/cron.aspx\\\")\""
    /sc DAILY /ru System

schtasks문의를 - 예를 들면 매일 실행하는 작업을 설정 합니다 schtasks 문서를 추가 옵션.


PowerShell 스크립트를 예약 할 수 있습니다 . PS는 매우 강력하며 전체 .Net Framework에 대한 액세스와 변경을 제공합니다. 다음은 그 예입니다.

$request = [System.Net.WebRequest]::Create("http://www.example.com")
$response = $request.GetResponse()
$response.Close()

또 다른 옵션은 VB 스크립트입니다. 예 (file.vbs로 저장) :

sSrcUrl = "http://yourdomain.com/yourfile.aspx"
sDestFolder = "C:\yourfolder\"
sImageFile = "filename.txt"
set oHTTP = WScript.CreateObject("MSXML2.ServerXMLHTTP")
oHTTP.open "GET", sSrcUrl, False
oHTTP.send ""
set oStream = createobject("adodb.stream")
Const adTypeBinary = 1
Const adSaveCreateOverWrite = 2
oStream.type = adTypeBinary
oStream.open
oStream.write oHTTP.responseBody
oStream.savetofile sDestFolder & sImageFile, adSaveCreateOverWrite
set oStream = nothing
set oHTTP = nothing
WScript.Echo "Done..."

PowerShell 5.0부터은 curl의 별칭 Invoke-WebRequest이므로 다음과 같이 예약 된 작업을 만들 수 있습니다.

Action: Start a program
Program/script: powershell
Add arguments: curl http://www.example.com/foo/bar

를 사용할 수도 Invoke-WebRequest있지만 curl더 간결합니다.


이 SuperUser.com 답변 은 훨씬 간단합니다.

cmd /c start http://example.com/somePage.html

보다 구체적으로, 다음은 Windows 예약 된 작업에서 표시되는 방식입니다.

여기에 이미지 설명 입력

그러나 이것은 아마도 백그라운드에서 기본 구성된 브라우저를 실행합니다. IE 여야하는 경우 구성해야합니다. 이것이 최선의 선택 일 것입니다. Task의 Action 단계로 직접 실행되는 솔루션이 있으면 좋습니다. 모든 정보가 바로 거기에 있습니다. 간결한 경우 훨씬 더 좋으므로 텍스트 상자를 스크롤하지 않고도 대부분의 명령을 볼 수 있습니다.

WGET / CURL-좋은 대안

If anything, WGET would be a good alternative to cmd..start..url. I'm not the first to think of this. The downside is you have to download WGET for Windows for it to work - it isn't an out-of-the-box solution. But WGET is lighter and importantly gives you more power. You can send lots of other types of URL calls. This includes different HTTP methods such as POST, custom Headers and more. Curl is a good option, instead of Wget - they have different sets of features, many overlapping.

PowerShell - not recommended

PowerShell, might be considered a "lighter" option, but you're also loading up a PowerShell (.Net AppDomain) which has a bit of lag, and also the command is a lot longer, and therefore harder to remember if you're doing this regularly. So PowerShell isn't the best option.

VBScript - not recommended

Clearly, VBScript is less recommendable. You have so much more you would need to remember, and the script is quite large. Unless you have other steps which warrant a script, don't have a completely separate resource just to do something you could have accomplished directly within a Scheduled Task.

Also, see similar questions:


cURLwget같은 가장 일반적인 명령 줄 http 요청 도구의 Windows 버전이 있습니다 . 이 중 하나를 실행하는 예약 된 작업을 확실히 만들 수 있습니다. 또한 URL 매개 변수를 즉석에서 반복하거나 생성해야하는 경우 Windows 스크립팅 호스트 스크립트 내에서이 작업을 수행했습니다.


PowerShell 4.0에서 curl로 시도한 경우 curl은 Invoke-WebRequest의 별칭이므로 다음과 같이 예약 된 작업을 만들 수 있습니다.

작업 : 프로그램 시작 프로그램 / 스크립트 : powershell 인수 추가 : curl http://www.example.com/foo/bar

매력처럼 작동했습니다!

참고 URL : https://stackoverflow.com/questions/1987345/recommended-method-for-loading-a-url-via-a-scheduled-task-on-windows

반응형