2

Well, I'm trying to do some automation using batch file to speed up my daily routine at work, and I need to solve these little questions:

  1. I want to install wget command, but using only the pure Windows Command Prompt
  2. I want to download some things stored http server online
  3. These "things" need to be downloaded and placed in the same folder that my batch file resides
  4. I want these things to be executed and my batch file to be deleted
  5. Need to perform all operations without "asking permission" of administrator

Please, can you guys do that for me? Or maybe give some help with the first steps?

5
  • 1
    Instead of wget, can you use PowerShell Invoke-WebRequest? It operates in almost exactly the same way and is in fact by default aliased to 'wget' in PowerShell. I'll write an answer with the details if you think it would be suitable.
    – Taz
    Jan 25 '16 at 0:48
  • @Taz Doesn't appear to be available in Windows 7 or Server 2008 R2. Works in 2012 R2, though, possibly also 2012, don't have it available to test. Also aliased to curl it seems - well played, Microsoft, well played. Jan 25 '16 at 1:14
  • 1
    @AaronMason Correct - It was added in Powershell 3.0 so by default it won't be there. You could install it however from here: microsoft.com/en-us/download/details.aspx?id=34595
    – Taz
    Jan 25 '16 at 1:17
  • 1
    Ok, if you can't be bothered to install v3: $curl = New-Object System.Net.WebClient; $curl.DownloadFile('http://serverfault.com/questions/751441', 'output.html')
    – jscott
    Jan 25 '16 at 1:33
  • @Taz It would be perfect! Thank you bro, i'm impressed with the speed that the answers come out, i thougt it would delay some weeks or at least days, thanks to everybody that is trying to help me! (^-^)
    – DaMonki
    Jan 25 '16 at 1:48
2

This answer depends on having PowerShell 3.0 to use the Invoke-WebRequest cmdlet instead of wget. It can be downloaded from here

You could achieve this without creating a file to run this from in the first place. I imagine you're remotely triggering this task somehow, in which case you can do the following:

powershell.exe -Command "& {Invoke-WebRequest http://google.com -OutFile C:\Path\To\File\out.html}"

This way, you leave no trace of a batch file, and you can pick the location where you would like your file to be placed.

To verify the PowerShell version installed is suitable before running the command, wrap it in an if statement like so:

powershell.exe -Command "& {if($PSversionTable.PSVersion.Major -ge 3) {Invoke-WebRequest http://google.com -OutFile C:\Path\To\File\out.html}}"
2
  • Dude, its perfect, you just solved almost all my problems with just onde code line And, sorry for continue annoying you, but... I have one more problem... Well, i work with a lot of pcs everyday and i want to "automatize" everything (yes, i'm to lazy to do my own job...). The problem is that i don't know if the computer i am working have PowerShell, can you please do something thats checks if the pc already have the needed things and, if don't, install what is missing? I will understand if you don't want to do that, you already answerd my first question and i'm am satisfect with that (^-^)
    – DaMonki
    Jan 25 '16 at 3:09
  • I've edited in a way to check if the correct version of PowerShell is installed. Unfortunately if it isn't, there's no built-in way to install it in an automated manner which wouldn't involve pulling the source with something like Invoke-WebRequest. It's a bit of a catch 22.
    – Taz
    Jan 25 '16 at 3:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.