【发布时间】:2023-05-24 04:45:01
【问题描述】:
所以我为我的 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 应用程序执行它,则会出现以下错误:Expected')'。
我认为你应该在 () 周围使用一些特殊字符?
【问题讨论】:
-
你搞砸了引用,转义
%0周围的单引号。 -
我是新手,对不起。在这种情况下如何转义单引号?
-
在 JS 中,反斜杠 (
\) 是转义字符,即您使用\'%0\',或者在允许的情况下使用双引号。 -
它修复了上面列出的错误,但由于某种原因,它不会提示询问管理员用户名和密码的窗口。它只是跳过代码的第一部分(要求管理员凭据的部分)并继续以普通用户身份执行其余代码。有没有其他方法可以以管理员身份执行列出的功能?
标签: javascript function hta runas