0

For the past week or so I'm trying out a new way to "deploy" a folder to another computer's desktop, download a couple of files in it and then run one of them as admin. The only thing is the file that does all this needs to be really lightweight, like under 500KB or so, or else it's useless.

What I'm doing so far is: I'm using a WinRar-created SFX archive called Program.exe that contains 2 files, the run.bat file and the winhttpjs.bat that I use to download the other files (https://github.com/npocmaka/batch.scripts/blob/master/hybrids/jscript/winhttpjs.bat)

The run.bat contains this code:

@echo off
    MKDIR "%userprofile%\Desktop\Folder1"
    CALL winhttpjs.bat "https://docs.google.com/uc?export=download&id=id1" -saveTo "%userprofile%\Desktop\Folder1\File1.bat"
    CALL winhttpjs.bat "https://docs.google.com/uc?export=download&id=id2" -saveTo "%userprofile%\Desktop\Folder1\winhttpjs.bat"
    START "%userprofile%\Desktop\Folder1\File1.bat"
    EXIT

And the File1.bat file contains the following code:

@echo off

:: BatchGotAdmin
:-------------------------------------
REM  --> Check for permissions
    IF "%PROCESSOR_ARCHITECTURE%" EQU "amd64" (
>nul 2>&1 "%SYSTEMROOT%\SysWOW64\cacls.exe" "%SYSTEMROOT%\SysWOW64\config\system"
) ELSE (
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
)

REM --> If error flag set, we do not have admin.
if '%errorlevel%' NEQ '0' (
    echo Requesting administrative privileges...
    goto UACPrompt
) else ( goto gotAdmin )
exit

:UACPrompt
    echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
    set params = %*:"=""
    echo UAC.ShellExecute "cmd.exe", "/c ""%~s0"" %params%", "", "runas", 1 >> "%temp%\getadmin.vbs"

    "%temp%\getadmin.vbs"
    del "%temp%\getadmin.vbs"
    exit 

:gotAdmin
    pushd "%CD%"
    CD /D "%~dp0"

echo This is the start of the script
echo.     
GOTO START

:START
    IF EXIST "%userprofile%\Desktop\Program.exe" (DEL "%userprofile%\Desktop\Program.exe")
    CD /D "%~dp0"
    rest of code...

The problem with this approach is the fact that, once it starts the downloaded File1.bat, that file asks for admin rights and once I click "yes" it just opens up another command prompt which asks for admin rights and that happens over and over again, like in a continuous loop. If I do not ask for admin rights the file works just as intended. So I'm guessing it's either a problem with how I'm asking for admin permissions or how it acts regarding the fact that it's a SFX archive or it might be something else entirely.

Do you guys have any idea how to make this work and as space-efficient as possible? I'm open to any idea whatsoever like changing how I download files, how I ask for admin rights, how not to use a SFX archive but something else etc

Note: I'm only using winhttpjs because of the really small file size (20KB) compared to popular alternatives like wget or curl and I'm only using it to download a couple of .bat files from Google Drive, one of it being itself (I'm using it to also download more files later in the script, but that's irrelevant). If I could somehow download the files directly from the run.bat file without needing to call on winhttpjs, or if I could modify the winhttpjs to also download the 3 files so I could skip the run.bat altogether that would be great (unfortunately BITS is slow and deprecated).

5
  • Why not use PowerShell? A simple Invoke-WebRequest could be sufficient?
    – Seth
    May 31, 2017 at 11:44
  • Powershell is not available on XP, Vista, Windows 7 May 31, 2017 at 11:46
  • 1
    Powershell 1 and are supported by Vista. Your approach is likely to be detected as win32-generic-downloader and blocked by most antiviruses.
    – Overmind
    May 31, 2017 at 11:48
  • I am able to get it digitally signed so that is not an issue. I will explore the possibility of using PowerShell (didn't know it was available on older OSs than Win8 - fail on my part) but I really want total compatibility for this, I'm not sure if PowerShell if the way to go. May 31, 2017 at 15:12
  • I suggest using wget, the PowerShell approach that is possible, that does what you want, doesn't work with version of Powershell your using on Windows XP and Windows Vista
    – Ramhound
    May 31, 2017 at 15:17

0

You must log in to answer this question.

Browse other questions tagged .