运行 在 HTA 应用程序中以管理员身份使用 JS 功能

Run as admin inside HTA app for JS function

所以我为我的 HTA 应用程序创建了以下功能,删除了一些文件夹,下载了一个新文件夹并在桌面上创建了一个快捷方式。它工作正常,当我尝试添加 运行 作为管理员功能时出现问题,以管理员身份执行以下命令。

这是我从批处理文件中获取的 运行 管理员代码:

if not "%1"=="am_admin" (powershell start -verb runas '%0' am_admin & exit /b)

我尝试将以下代码添加到我的函数中,位于顶部:

<script type="text/javascript" language="javascript">

function Run() {
var WShell = new ActiveXObject('WScript.Shell');
WShell.Run('cmd /c if not "%1"=="am_admin" (powershell start -verb runas '%0' am_admin & exit /b)', 0, true);


WShell.Run('cmd /c PING localhost -n 5 >NUL', 0, true);
WShell.Run('cmd /c start mshta.exe "\\fs\FIle Share\SA Support\ZverTools\programayendebaWAIT.hta"', 0, true);
WShell.Run('cmd /c PING localhost -n 1 >NUL', 0, true);
WShell.Run('cmd /c taskkill /F /IM CustomDeclaration.exe /T', 0, true);
WShell.Run('cmd /c taskkill /F /IM Nasamartleoba.exe /T', 0, true);
WShell.Run('cmd /c taskkill /F /IM Aqti.exe /T', 0, true);
WShell.Run('cmd /c taskkill /F /IM customDeclaration.exe /T', 0, true);
WShell.Run('cmd /c taskkill /F /IM nasamartleoba.exe /T', 0, true);
WShell.Run('cmd /c taskkill /F /IM aqti.exe /T', 0, true);
WShell.Run('cmd /c taskkill /F /IM customdeclaration.exe /T', 0, true);
WShell.Run('cmd /c PING localhost -n 1 >NUL', 0, true);
WShell.Run('cmd /c taskkill /F /IM Nasamartleoba /T', 0, true);
WShell.Run('cmd /c taskkill /F /IM Aqtebi /T', 0, true);
WShell.Run('cmd /c taskkill /F /IM aqtebi /T', 0, true);
WShell.Run('cmd /c taskkill /F /IM aqtebi.exe /T', 0, true);
WShell.Run('cmd /c taskkill /F /IM Aqtebi.exe /T', 0, true);
WShell.Run('cmd /c taskkill /F /IM CustomDeclaration /T', 0, true);
WShell.Run('cmd /c taskkill /F /IM Aqti /T', 0, true);
WShell.Run('cmd /c taskkill /F /IM CustomDeclarationUpdate.exe /T', 0, true);
WShell.Run('cmd /c taskkill /F /IM CustomDeclaration.exe /T', 0, true);
WShell.Run('cmd /c taskkill /F /IM CustomDeclaration.exe /T', 0, true);
WShell.Run('cmd /c taskkill /F /IM CustomDeclaration.exe /T', 0, true);
WShell.Run('cmd /c taskkill /F /IM CustomDeclaration.exe /T', 0, true);
WShell.Run('cmd /c PING localhost -n 1 >NUL', 0, true);
WShell.Run('cmd /c RD /S /Q "C:\saagento\CustomDeclaration"', 0, true);
WShell.Run('cmd /c RD /S /Q "C:\saagento\Custom Declaration"', 0, true);
WShell.Run('cmd /c RD /S /Q "C:\CustomDeclaration"', 0, true);
WShell.Run('cmd /c RD /S /Q "C:\Custom Declaration"', 0, true);
WShell.Run('cmd /c PING localhost -n 3 >NUL', 0, true);
WShell.Run('cmd /c xcopy "\\fs\FIle Share\SA Support\saagento prog\CustomDeclaration" "C:\saagento\CustomDeclaration" /E /I /S /Y /D', 0, true);
WShell.Run('cmd /c xcopy "\\fs\FIle Share\SA Support\ZverTools\CustomDeclarationUpdate.exe - V.lnk" "%USERPROFILE%\Desktop" /y', 0, true);
WShell.Run('cmd /c del /f "%USERPROFILE%\Desktop\CustomDeclarationUpdate.exe - Shortcut.lnk"', 0, true);
WShell.Run('cmd /c del /f "%USERPROFILE%\Desktop\CustomDeclarationUpdate.exe - Shortcut (2).lnk"', 0, true);
WShell.Run('cmd /c del /f "%USERPROFILE%\Desktop\CustomDeclarationUpdate - Shortcut.lnk"', 0, true);
WShell.Run('cmd /c del /f "%USERPROFILE%\Desktop\CustomDeclarationUpdate - Shortcut (2).lnk"', 0, true);
WShell.Run('cmd /c del /f "%USERPROFILE%\Desktop\CustomDeclaration.exe - Shortcut.lnk"', 0, true);
WShell.Run('cmd /c del /f "%USERPROFILE%\Desktop\CustomDeclaration.exe - Shortcut (2).lnk"', 0, true);
WShell.Run('cmd /c del /f "%USERPROFILE%\Desktop\CustomDeclaration - Shortcut.lnk"', 0, true);
WShell.Run('cmd /c del /f "%USERPROFILE%\Desktop\CustomDeclaration - Shortcut (2).lnk"', 0, true);
WShell.Run('cmd /c start "" "\\fs\FIle Share\SA Support\ZverTools\killlaProgramayendebawait.vbs"', 0, true);
WShell.Run('cmd /c rundll32 user32.dll,MessageBeep', 0, true);
}

</script>

但由于某些原因它不会工作,如果您通过 bat 文件执行它,它会工作,但如果您尝试从 HTA 应用程序执行它,它会给出以下错误:预期')'。

我认为你应该在 () 周围使用一些特殊字符?

你只是没有考虑到批处理没有去除传入的报价。

从批处理文件中,考虑到需要删除引号 %0,调用将是

    set p=%0                                                                                    
    set p=!p:"=!
    SET code=""""start -verb runas '%p%'""""
    mshta.exe vbscript:Execute("CreateObject(""WScript.Shell"").Run ""powershell -noexit -command %code%"",0,false:close")

如果您只需要信任级别那么

    :: 0x40000  Admin 0x20000 - User
    runas /trustlevel:0x20000 "powershell.exe -noexit -ExecutionPolicy Bypas -command Some-Command-Line"