Solved Strange Problem with script works then does not work

Mobile computing solutions Mini itx pfse...
December 16, 2015 at 17:42:50
Specs: Windows XP, HexaCore AMD FX-6100, 1400 MHz (7 x 200) / 4gb DDR
I wonder if anyone can help with a rather odd problem I discovered with a script I use in batch ?

When I run this script on Windows XP, it works fine, but when I run it on Windows 7 it only works without elevation, but with elevation ON WINDOWS 7 it just quits on me, I have turned it into a echoed test file for easier debugging but still I do not know why it refuses to run Elevated ?

:: START

@echo off
setlocal enabledelayedexpansion
set mypath=%~dp0
:: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:contig
if exist "apps\Contig.exe" (set cntig=apps\Contig.exe) else (set cntig=echo NO Contig.exe)
:: if not exist "%cntig%" goto :nocontig
:: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

set viss=if not "Windows XP"=="Windows 7"

:: SET TEST VARS TO 1 OR 0
set cnul=0
set dnul=0
set enul=1
set fnul=0
set gnul=0

if "%cnul%"=="0" (set drvs=C) else (set drvs=C&&goto :dcont)

:cntgx


:: if "%1" EQU "" goto Usage
set DO1=echo %cntig% -a -s -v %drvs%:

:Loop

%DO1% %1$Mft
%viss% %DO1% %1$LogFile
%DO1% %1$Volume
%DO1% %1$AttrDef
%viss% %DO1% %1$Bitmap
%viss% %DO1% %1$Boot
%viss% %DO1% %1$BadClus
%DO1% %1$Secure
%DO1% %1$UpCase
%DO1% %1$Extend

:LoopTest
shift

if "%1" NEQ "" (goto :Loop) else (goto :dcont)

:Usage
echo This utility will attempt to defrag the metadata of the designated drives.
:dcont
if "%drvs%"=="C" set drvs=D&&if "%dnul%"=="0" goto :cntgx
if "%drvs%"=="D" set drvs=E&&if "%enul%"=="0" goto :cntgx
if "%drvs%"=="E" set drvs=F&&if "%fnul%"=="0" goto :cntgx
:: :::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: :::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: if "%drvs%"=="F" set drvs=G && if "%gnul%"=="0" goto :cntgx
::--------------------------------------------------------
pathping 127.0.0.1 -n -q 1 -p 7000 >nul 2>&1
:: exit/B

pause
:End
endlocal

:: END

Michelle xoxoxo

If Dreams Come True Oleg Would be Famous so far he's very shy, so much for Being Famous ;) http://tinyurl.com/pnenqgb


See More: Strange Problem with script works then does not work

Report •


✔ Best Answer
December 16, 2015 at 19:42:34
With UAC, you have to launch a program in a special way to make sure it gets the full admin credentials in your account. In the English versions, this is labeled "Run as administrator." It's also referred to an elevated process, because its permission set has been "elevated" to administrator power.

How To Ask Questions The Smart Way



#1
December 16, 2015 at 19:13:13
Leave ECHO on, run the script from an elevated prompt, and see where it dies. My guess is your script isn't expecting to have the current directory be %systemroot%\system32.

How To Ask Questions The Smart Way


Report •

#2
December 16, 2015 at 19:35:21
OK, I give up. What's an elevated prompt?

=====================

M2 Get custom script or take private lessons


Report •

#3
December 16, 2015 at 19:42:01
Razor2.3 OMG I am so dumb I fogot about that, god I hate windows 7, It changes to system 32 even on a 64 bit system and yes your right, you must be psychic because right when you replied It hit me I just found 2 bugs too it looks messy but getting there.

Honestly I do not know why but I never seem to solve these silly bugs until AFTER I post a question on here it's sods law or Murphys Law ;)

:: starting debug

@echo on
set mypath=%~dp0
set "batchPath=%~0"
echo Batchpath %batchPath%
timeout 10
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
echo ERROR TEST LOG FLAG
IF NOT %1!==/go! %0 /go 1>C:\State\%~n0.log 2>&1
SHIFT

ECHO %1 %2 %3 %4 %5

:: @@@@@ Above Block is for Debugging Purposes Only @@@@@@

setlocal enabledelayedexpansion
echo Mypath %mypath%
timeout 10
cd /d %mypath%


chdir /d %mypath%
timeout 10
:: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:contig
if exist "%mypath%apps\Contig.exe" (set cntig=apps\Contig.exe) else (set cntig=:: NO Contig.exe)
if not exist "%mypath%apps\Contig.exe" goto :nocontig
:: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

set viss=if not "Windows 7"=="Windows XP"
set cnul=0
set dnul=0
set enul=0
set fnul=1
set gnul=1

if "%cnul%"=="0" (set drvs=C) else (set drvs=C&&goto :dcont)

:cntgx

pathping 127.0.0.1 -n -q 1 -p 2000 >nul 2>&1
:: if "%1%" EQU "" goto Usage
set DO1=echo %cntig% -a -s -v %drvs%:

:Loop

%DO1% %1$Mft
%viss% %DO1% %1$LogFile
%DO1% %1$Volume
%DO1% %1$AttrDef
%viss% %DO1% %1$Bitmap
%viss% %DO1% %1$Boot
%viss% %DO1% %1$BadClus
%DO1% %1$Secure
%DO1% %1$UpCase
%DO1% %1$Extend

:LoopTest
shift

if "%1" NEQ "" (goto :Loop) else (goto :dcont)

:Usage
echo This utility will attempt to defrag the metadata of the designated drives.
:dcont
if "%drvs%"=="C" set drvs=D&&if "%dnul%"=="0" goto :cntgx
if "%drvs%"=="D" set drvs=E&&if "%enul%"=="0" goto :cntgx
if "%drvs%"=="E" set drvs=F&&if "%fnul%"=="0" goto :cntgx
:: :::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: :::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: if "%drvs%"=="F" set drvs=G && if "%gnul%"=="0" goto :cntgx
::--------------------------------------------------------
pathping 127.0.0.1 -n -q 1 -p 7000 >nul 2>&1
:: exit/B

:nocontig

:: pause
:End
endlocal


Michelle

:: ending debugger

If Dreams Come True Oleg Would be Famous so far he's very shy, so much for Being Famous ;) http://tinyurl.com/pnenqgb


Report •

Related Solutions

#4
December 16, 2015 at 19:42:34
✔ Best Answer
With UAC, you have to launch a program in a special way to make sure it gets the full admin credentials in your account. In the English versions, this is labeled "Run as administrator." It's also referred to an elevated process, because its permission set has been "elevated" to administrator power.

How To Ask Questions The Smart Way


Report •

#5
December 16, 2015 at 19:45:15
Hi Mechanix2Go
Maybe my terminology is a bit out of wack, I meant when either running the Batch as ADMINISTRATOR or Using a Built in Elevation Script similar to this
http://pcloadletter.co.uk/2012/12/1...

Looks like I figured it out now and thank you both.

Michelle

If Dreams Come True Oleg Would be Famous so far he's very shy, so much for Being Famous ;) http://tinyurl.com/pnenqgb


Report •


Ask Question