I have a small vbs script:

Set UAC = CreateObject("Shell.Application")
UAC.ShellExecute "C:\bin\addtopath.bat",  chr(34) & "C:\bin" & chr(34), "", "runas", 1

C:\bin\addtopath.bat exists and I took some idea from this question. What happens here is that a cmd opens and instantly closes and I'm not able to identify what it says. How do I know what is wrong?

C:\bin\addtopath.bat:

pause
echo %1
pause
:: BatchGotAdmin
:-------------------------------------
REM  --> Check for permissions
>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 )

:UACPrompt
    echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
    echo UAC.ShellExecute "%~s0",  chr(34) ^& %1 ^& chr(34), "", "runas", 1 >> "%temp%\getadmin.vbs"
    pause
    "%temp%\getadmin.vbs"
    exit /B

:gotAdmin
    if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )
    pushd "%CD%"
    CD /D "%~dp0"
:--------------------------------------
echo %1
pause
setenv -a PATH %1

pause
有帮助吗?

解决方案

What are you invoking a batch file? Why don't you just do everything in VBSCRIPT?

Debugging your vbscript can be done with a debugger by using the /D /X parameters

    cscript /d /x file.vbs
    wscript /d /x file.vbs

Debugging batch files is a nightmare. Here is some help for debugging batch files: http://www.robvanderwoude.com/battech_debugging.php

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top