Starting my batch-file looks like this:
start "" "%PROGRAMFILES%\program.exe"
If i am putting there a %1
at the end:
start "" "%PROGRAMFILES%\program.exe" %1
, i am able to open a non-specifif file, if i change "always open with" and link this to my batch-file.
But there is a problem - i would like to run my program as an administrator. If i create a link to my programm, give this link admin-rights and define that my filetype-ending should be opend with the "link to the program" it completely ignores the admin-rights.
Therefore i found an other solution:
:: 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"
set params = %*:"=""
echo UAC.ShellExecute "%PROGRAMFILES%\program.exe", "/c %~s0
%params%", "", "runas", 1 >> "%temp%\getadmin.vbs"
"%temp%\getadmin.vbs"
del "%temp%\getadmin.vbs"
exit /B
:gotAdmin
pushd "%CD%"
CD /D "%~dp0"
With the help of this code my batch-file runs as administrator and the program starts, but the file doesn´t open in window. If tried several things with adding a "%1", but it doesn´t work.
Any idea?
Thanks for Help!