My UAC function
Moderator: DosItHelp
Re: My UAC function
You extra computing code, does not make sense to me - sorry I am a retard? Could you explain what it does exactly and in details?
It could be handy some day
It could be handy some day
Re: My UAC function
Sorry penpen, that does not work. Any other idea? (My batch file)
Re: My UAC function
Adrianvdh wrote:I need the technique to be like mine, the if errorlevel statement must be in the function.
And I need the use switches.
Sorry if old age has made me cynical,
but this sounds to me like a request for assistance with a school's homework exercise,
where the requirement is not to achieve a particular result,
but to demonstrate the correct syntax for using errorlevel and switches as taught in the last lesson.
Re: My UAC function
alan_b wrote:Adrianvdh wrote:I need the technique to be like mine, the if errorlevel statement must be in the function.
And I need the use switches.
Sorry if old age has made me cynical,
but this sounds to me like a request for assistance with a school's homework exercise,
where the requirement is not to achieve a particular result,
but to demonstrate the correct syntax for using errorlevel and switches as taught in the last lesson.
NO! This they DO NOT teach at school. I am in Grade 9, I failed Grade 9 Last year so ya. Grade 10 we learn Java, etc.
I work on a personal project I work on in my own spare time (for the last year). But I can't really debug it until I fix the UAC function problem. So any idea anyone?
Re: My UAC function
aGerman wrote:Try to write a simplified example (whole batch code) that shows the problem.
Regards
aGerman
Re: My UAC function
What do you mean. I have explained it enough haven't I? The problem is the errorlevel from the choice.exe is interfering with the UAC function.
How do I change this?
i really don't want to use "set /p" for user input on a menu.
How do I change this?
i really don't want to use "set /p" for user input on a menu.
Re: My UAC function
Why on earth are you wasting time with code such as
That sort of code was appropriate when Windows 3.?? was a simple GUI that was run under the real operating system COMMAND.COM.
If you are writing code that is affected by User Access Control then your Batch commands are run by the CLI CMD.EXE running under the real operating system Windows Vista onwards.
CMD.EXE allows code such as
Just accept that many commands such as "choice" will affect %errorlevel%,
but you can use SET to allocate the current value of errorlevel to a "variable" which will remain fixed regardless of subsequent changes to errorlevel
Code: Select all
choice /C 12r /N /M "Make your selection: "
if errorlevel 3 cls & goto restart
if errorlevel 2 ( set mainmenuvar=Text1
goto mainmenuloginput )
That sort of code was appropriate when Windows 3.?? was a simple GUI that was run under the real operating system COMMAND.COM.
If you are writing code that is affected by User Access Control then your Batch commands are run by the CLI CMD.EXE running under the real operating system Windows Vista onwards.
CMD.EXE allows code such as
Code: Select all
set mylevel=%errorlevel%
choice /C 12r /N /M "Make your selection: "
if %mylevel%==3 (cls & goto restart)
if %mylevel%==2 ( set mainmenuvar=Text1
goto mainmenuloginput )
Just accept that many commands such as "choice" will affect %errorlevel%,
but you can use SET to allocate the current value of errorlevel to a "variable" which will remain fixed regardless of subsequent changes to errorlevel
Re: My UAC function
@alan_b:
Do I need to set var=%errorlevel% befor I call the UAC Function? because your code does not work
Still get the same problem:
I tried this:
and the errorlevel returned as 0
Then I tried:
After the goto mainmenuloginput is executed the errorlevel must mess up, and it does it return a 1 after the function is called. Any idea?
Do I need to set var=%errorlevel% befor I call the UAC Function? because your code does not work
Still get the same problem:
I tried this:
Code: Select all
set choice=%errorlevel%
choice /C 123456itr /N /M "Make your selection: "
echo %choice%
pause
and the errorlevel returned as 0
Then I tried:
Code: Select all
choice /C 12 /N /M "Make your selection: "
echo %123%
echo %errorlevel%
pause
goto mainmenu
if "%errorlevel%"=="2" ( set mainmenuvar=Msg
goto mainmenuloginput )
if "%errorlevel%"=="1" ( set mainmenuvar=Msg
goto mainmenuloginput )
:mainmenuloginput
if "%logmode%"=="Enabled" call :checkfileUAC "/l" if "%logtype%"=="Detailed" echo [%time%] [%mainmenuvar%]>>"%logdir%"
if "%errorlevel%"=="2" goto Test2
if "%errorlevel%"=="1" goto Test1
After the goto mainmenuloginput is executed the errorlevel must mess up, and it does it return a 1 after the function is called. Any idea?
Re: My UAC function
penpen wrote:Code: Select all
choice /C 12 /N /M "Make your selection: "
set "errno=%errorlevel%"
:: ...
::replace: if errorlevel 2 goto Test2
if %errno% GEQ 2 goto Test2
::replace: if errorlevel 1 goto Test1
if %errno% GEQ 1 goto Test1
If you have to execute it in a subenvironment where delayed expansion is enabled then replace all percent signs with exclamation marks.
Re: My UAC function
Adrianvdh wrote:I tried this:Code: Select all
set choice=%errorlevel%
choice /C 123456itr /N /M "Make your selection: "
echo %choice%
pause
and the errorlevel returned as 0
The errorlevel wasn't initialized, it could be anything.
You have to save the errorlevel into the choice variable AFTER you have executed choice(.exe) to get its returned errorlevel:
Code: Select all
choice /C 123456itr /N /M "Make your selection: "
set choice=%errorlevel%
echo %choice%
pause
If you store the errorlevel immidiately as i've suggested and use it later (errno, see post above) then its content would be that of the errorlevel after using choice.Adrianvdh wrote:Then I tried:Code: Select all
choice /C 12 /N /M "Make your selection: "
echo %123%
echo %errorlevel%
pause
goto mainmenu
if "%errorlevel%"=="2" ( set mainmenuvar=Msg
goto mainmenuloginput )
if "%errorlevel%"=="1" ( set mainmenuvar=Msg
goto mainmenuloginput )
:mainmenuloginput
if "%logmode%"=="Enabled" call :checkfileUAC "/l" if "%logtype%"=="Detailed" echo [%time%] [%mainmenuvar%]>>"%logdir%"
if "%errorlevel%"=="2" goto Test2
if "%errorlevel%"=="1" goto Test1
After the goto mainmenuloginput is executed the errorlevel must mess up, and it does it return a 1 after the function is called. Any idea?
Additionally i don't think the errorlevel messed up: I think the errorlevel is 1 because you have typed 1 at the choice prompt.
Btw: It seems, there is a typo: A missing && (or something like that) in the if line right after the :mainmenuloginput (between the call and the second if), which results in handling the if as parameters of the call, so they are never executed.
Note:
It computes the sum of all positive natural numbers up to %~2 (n):Adrianvdh wrote:You extra computing code, does not make sense to me - sorry I am a retard? Could you explain what it does exactly and in details?
It could be handy some day.
1+2+3+4+5+...+...+(n-1)+n==n*(n+1)/2
penpen
Re: My UAC function
THANK YOU penpen I GOT IT TO WORK NOW. I AM SO HAPPY
So this is suitable:
So this is suitable:
Code: Select all
if "%logmode%"=="Enabled" if "%logtype%"=="Detailed" call :checkfileUAC "/l" && echo [%time%] [%mainmenuvar%]>>"%logdir%"
Re: My UAC function
Adrianvdh wrote:@alan_b:
Do I need to set var=%errorlevel% befor I call the UAC Function? because your code does not work
My code does work - it merely failed to address your situation due to your inadequate specification.
You specified a function with label :checkfileUAC
That function seems to terminate with either an "Exit /b" or possibly "goto Errorwritefiles"
A bit later you have code that is unusable because there is no label or any indication of how it might be invoked.
You then seem to complain that CHOICE is having a bad effect upon errorlevel and always exits at the "first label:"
The first label at the top of the topic is :checkfileUAC
You have many more labels afterwards, including :mainmenuloginput.
It would have been useful to have specified the name of what you called the first label.
You did NOT show what code route led to the execution of CHOICE
and I assumed that you had done things that you expected to result in errorlevel having some particular value,
and that you had not realised that CHOICE is one of many commands that alter errorlevel and caused an exit to the un-named first label,
hence I pointed out that before you allowed CHOICE to change the value of errorlevel you could capture the current value of errorlevel with
SET mylevel=%errorlevel%
Re: My UAC function
@alan_b
All I can say now is sorry for wasting your time, but the problem is fixed But anyway thanks
All I can say now is sorry for wasting your time, but the problem is fixed But anyway thanks