Batch, Registry & UAC

Propaganist

New member
Local time
10:06 PM
Messages
34
Hi all,

I've written a batch file which adds registry keys (with dynamic driveletter recognition) upon startup, launches a program and deletes the keys when closing the program.

My only concern now is that when launching the batch, I get a UAC dialog for the registry changes.

Is there some way I can tell Windows through the batch file that I really don't need any dialog (for this file only)?

I don't know anything about the creation process of EXEs, but I've never seen any UAC for registry changes made by EXEs...? So it has to be possible I guess...

Thanks!
Propa
 

My Computer

Computer Manufacturer/Model Number
Custom built (XXODD XNi70d)
OS
Microsoft Windows 7 Ultimate (x64)
CPU
Intel Core 2 Duo P9700 2.80GHz (6MB Cache)
Motherboard
Intel Cantiga ICH9M Chipset + Intel GM45 Chipset
Memory
4.00GB DDR3 1.066MHz
Graphics Card(s)
Intel GMA 4500MHD; nVIDIA GeForce GT130M 512MB DDR3
Sound Card
Realtek High Definition Audio
Monitor(s) Displays
Mobile Intel 4 Series Express Chipset
Screen Resolution
1440x900 (17")
Hard Drives
320GB 7200RPM Serial-ATA (16MB cache)
Hi all,

I've written a batch file which adds registry keys (with dynamic driveletter recognition) upon startup, launches a program and deletes the keys when closing the program.

My only concern now is that when launching the batch, I get a UAC dialog for the registry changes.

Is there some way I can tell Windows through the batch file that I really don't need any dialog (for this file only)?

I don't know anything about the creation process of EXEs, but I've never seen any UAC for registry changes made by EXEs...? So it has to be possible I guess...

Thanks!
Propa

Hi Propa,

It depends where you write these keys, if your just using the HKCU (Current User) hive then you wont need UAC elevation, however every other hive will result in a UAC prompt ;)

Steven
 
Can you attach the file so that we can see how you've coded it?
 

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Dwarf Dwf/11/2012 r09/2013
OS
Windows 8.1 Pro RTM x64
CPU
Intel Core-i5-3570K 4-core @ 3.4GHz (Ivy Bridge) (OC 4.4GHz)
Motherboard
ASRock Z77 Extreme4-M
Memory
4 x 4GB DDR3-1600 Corsair Vengeance CMZ8GX3M2A1600C9B (16GB)
Graphics Card(s)
MSI GeForce GTX770 Gaming OC 2GB
Sound Card
Realtek High Definition on board solution (ALC 898)
Monitor(s) Displays
ViewSonic VA1912w Widescreen (VGA)
Screen Resolution
1440x900
Hard Drives
OCZ Agility 3 SSD 120GB SATA III x2 (RAID 0)
Samsung HD501LJ 500GB SATA II x2
Hitachi HDS721010CLA332 1TB SATA II
Iomega 1.5TB Ext USB 2.0
WD 2.0TB Ext USB 3.0
PSU
XFX Pro Series 850W Semi-Modular
Case
Gigabyte IF233
Cooling
1 x 120mm Front Inlet 1 x 120mm Rear Exhaust
Keyboard
Microsoft Comfort Curve Keyboard 3000 (USB)
Mouse
Microsoft Comfort Mouse 3000 for Business (USB)
Internet Speed
NetGear DG834Gv3 ADSL Modem/Router (Ethernet) ~4.0 Mb/s (O2)
Antivirus
Avast! 8.0.1497
Browser
IE 11
Other Info
Optical Drive: HL-DT-ST BD-RE BH10LS30 SATA Bluray
Lexmark S305 Printer/Scanner/Copier (USB)
WEI Score: 8.1/8.1/8.5/8.5/8.25
Asus Eee PC 1011PX Netbook (Windows 7 x86 Starter)
Hi Propa,

It depends where you write these keys, if your just using the HKCU (Current User) hive then you wont need UAC elevation, however every other hive will result in a UAC prompt ;)

Steven
That's odd... The keys are all going in HKCU but I still get a dialog..

Can you attach the file so that we can see how you've coded it?
The file is my workaround for a highly portable Virtual DJ Installation. By running it through this batch, it enables me to run one single installation from usb on every possible computer.

Anyway, here you go.

(PS: I do have a valid license)

/EDIT: attachment removed
 
Last edited:

My Computer

Computer Manufacturer/Model Number
Custom built (XXODD XNi70d)
OS
Microsoft Windows 7 Ultimate (x64)
CPU
Intel Core 2 Duo P9700 2.80GHz (6MB Cache)
Motherboard
Intel Cantiga ICH9M Chipset + Intel GM45 Chipset
Memory
4.00GB DDR3 1.066MHz
Graphics Card(s)
Intel GMA 4500MHD; nVIDIA GeForce GT130M 512MB DDR3
Sound Card
Realtek High Definition Audio
Monitor(s) Displays
Mobile Intel 4 Series Express Chipset
Screen Resolution
1440x900 (17")
Hard Drives
320GB 7200RPM Serial-ATA (16MB cache)
Ok. I got some sort of breakthrough...

If I run the batch as Administrator, none of the dialogs appear, but running cmd as Administrator also changes the initial working directory.

This is fixed by inserting cd /d %~dp0 to the very beginning of the file (or just after @echo off).

So now I don't have registry dialogs anymore, but I have to select Run as Administrator & confirm...

Any other ideas to completely hide all dialogs?
 

My Computer

Computer Manufacturer/Model Number
Custom built (XXODD XNi70d)
OS
Microsoft Windows 7 Ultimate (x64)
CPU
Intel Core 2 Duo P9700 2.80GHz (6MB Cache)
Motherboard
Intel Cantiga ICH9M Chipset + Intel GM45 Chipset
Memory
4.00GB DDR3 1.066MHz
Graphics Card(s)
Intel GMA 4500MHD; nVIDIA GeForce GT130M 512MB DDR3
Sound Card
Realtek High Definition Audio
Monitor(s) Displays
Mobile Intel 4 Series Express Chipset
Screen Resolution
1440x900 (17")
Hard Drives
320GB 7200RPM Serial-ATA (16MB cache)
Do you have to have the BAT file create the REG file?
 

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Dell OP7010
OS
Windows 7 Enterprise (x64); Windows Server 2008 R2 (x64)
Memory
16GB
Monitor(s) Displays
4 Dell 24" LCD
Screen Resolution
1280x1024
Keyboard
Dell
Mouse
Dell Optical
Internet Speed
40meg
Do you have to have the BAT file create the REG file?
Yes, the bat file catches the working driveletter, which is necessary for the registry keys.
 

My Computer

Computer Manufacturer/Model Number
Custom built (XXODD XNi70d)
OS
Microsoft Windows 7 Ultimate (x64)
CPU
Intel Core 2 Duo P9700 2.80GHz (6MB Cache)
Motherboard
Intel Cantiga ICH9M Chipset + Intel GM45 Chipset
Memory
4.00GB DDR3 1.066MHz
Graphics Card(s)
Intel GMA 4500MHD; nVIDIA GeForce GT130M 512MB DDR3
Sound Card
Realtek High Definition Audio
Monitor(s) Displays
Mobile Intel 4 Series Express Chipset
Screen Resolution
1440x900 (17")
Hard Drives
320GB 7200RPM Serial-ATA (16MB cache)
Got it!

Instead of calling REGEDIT, I need to call REG(.exe), which doesn't interfere with UAC.

So

Code:
START /WAIT REGEDIT /S

becomes

Code:
REG IMPORT

:)
 

My Computer

Computer Manufacturer/Model Number
Custom built (XXODD XNi70d)
OS
Microsoft Windows 7 Ultimate (x64)
CPU
Intel Core 2 Duo P9700 2.80GHz (6MB Cache)
Motherboard
Intel Cantiga ICH9M Chipset + Intel GM45 Chipset
Memory
4.00GB DDR3 1.066MHz
Graphics Card(s)
Intel GMA 4500MHD; nVIDIA GeForce GT130M 512MB DDR3
Sound Card
Realtek High Definition Audio
Monitor(s) Displays
Mobile Intel 4 Series Express Chipset
Screen Resolution
1440x900 (17")
Hard Drives
320GB 7200RPM Serial-ATA (16MB cache)
Ok I understand now. Yes there is a way to make it work transparent however the Batch would need to be converted to VBScript. It would take a bit of time to convert it and then add the extra code to make it work as you need it. I have a lot of the code already written (saved somewhere, I need to look for it).

I don't have the time tonight to re-write it and then I don't have the means to test it. Maybe if no-one here comes up with a better idea I can look at it over the weekend. I will keep re-viewing this thread.
 

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Dell OP7010
OS
Windows 7 Enterprise (x64); Windows Server 2008 R2 (x64)
Memory
16GB
Monitor(s) Displays
4 Dell 24" LCD
Screen Resolution
1280x1024
Keyboard
Dell
Mouse
Dell Optical
Internet Speed
40meg
Ok I understand now. Yes there is a way to make it work transparent however the Batch would need to be converted to VBScript. It would take a bit of time to convert it and then add the extra code to make it work as you need it. I have a lot of the code already written (saved somewhere, I need to look for it).

I don't have the time tonight to re-write it and then I don't have the means to test it. Maybe if no-one here comes up with a better idea I can look at it over the weekend. I will keep re-viewing this thread.

Got it already. See my previous post.
 

My Computer

Computer Manufacturer/Model Number
Custom built (XXODD XNi70d)
OS
Microsoft Windows 7 Ultimate (x64)
CPU
Intel Core 2 Duo P9700 2.80GHz (6MB Cache)
Motherboard
Intel Cantiga ICH9M Chipset + Intel GM45 Chipset
Memory
4.00GB DDR3 1.066MHz
Graphics Card(s)
Intel GMA 4500MHD; nVIDIA GeForce GT130M 512MB DDR3
Sound Card
Realtek High Definition Audio
Monitor(s) Displays
Mobile Intel 4 Series Express Chipset
Screen Resolution
1440x900 (17")
Hard Drives
320GB 7200RPM Serial-ATA (16MB cache)
For further reference if anyone wants to build something similar, here's a dummy code. You only need to modify the red parts:

Code:
@ECHO OFF

:: Are we intruders?
REG QUERY [COLOR=Red]HKCU\Software\SOFTWARE TREE[/COLOR] /v [COLOR=Red]SOME SOFTWARE KEY (eg Version)[/COLOR] > nul 2>&1
IF %ErrorLevel%==0 GOTO Error
IF %ErrorLevel%==1 GOTO Ok

:Ok
:: I really dislike loops
SET del=

:: How about getting the driveletter?
set ltr=%cd:~0,3%

:: Write to temporary REG
ECHO Adding keys...
> %TEMP%.\TEMPREG.REG ECHO Windows Registry Editor Version 5.00
>>%TEMP%.\TEMPREG.REG ECHO.

[COLOR=Green]:: Use and copy the following line to add more trees (copy it below your keys for another tree!)[/COLOR]
>>%TEMP%.\TEMPREG.REG ECHO [[COLOR=Red]HKEY_CURRENT_USER\Software\SOFTWARE TREE[COLOR=Black]][/COLOR][/COLOR]

[COLOR=Green]:: Use and copy the following line to add more keys (copy it below the right tree!)[/COLOR]
>>%TEMP%.\TEMPREG.REG ECHO "[COLOR=Red]KEY NAME[/COLOR]"="[COLOR=Red]VALUE[/COLOR]"

[COLOR=Green]:: For a key that requires a path, let's point it using the current drive letter (if your path contains spaces, enclose it with speech marks. eg \"Program Files"\\Software)[/COLOR]
>>%TEMP%.\TEMPREG.REG ECHO "[COLOR=Red]KEYNAME[/COLOR]"="%ltr%\[COLOR=Red]path[/COLOR]\\[COLOR=Red]path[/COLOR]"

:: Merge Temporary REG with Registry
REG IMPORT %TEMP%.\TEMPREG.REG

:: We're not doing this without purpose... Start program! (if your path contains spaces, enclose it with speech marks. eg \"Program Files"\Software)
echo Starting program...
start /wait %CD%\[COLOR=Red]path[/COLOR]\[COLOR=Red]program[/COLOR].exe
GOTO Regdelete

:Error
echo There are already some registry keys for this program!
echo.
SET /P del=Do you want to overwrite all registry keys and start the application (Y/N)?
if /i {%del%}=={Y} (GOTO Regdelete)
if /i {%del%}=={Yes} (GOTO Regdelete)
GOTO End

:Regdelete
:: Everybody's tired, let's delete the keys
ECHO Deleting keys...
> %TEMP%.\TEMPREG.REG ECHO Windows Registry Editor Version 5.00
>>%TEMP%.\TEMPREG.REG ECHO.

:: Copy this line for every created tree
>>%TEMP%.\TEMPREG.REG ECHO [-[COLOR=Red]HKEY_CURRENT_USER\Software\[/COLOR][COLOR=Red]SOFTWARE TREE[/COLOR]]

REG IMPORT %TEMP%.\TEMPREG.REG
DEL %TEMP%.\TEMPREG.REG

if /i {%del%}=={Y} (GOTO Ok)
if /i {%del%}=={Yes} (GOTO Ok)

:End
:: Let's end this. Clear out the last variable.
SET ltr=
Save it as something.bat
 
Last edited:

My Computer

Computer Manufacturer/Model Number
Custom built (XXODD XNi70d)
OS
Microsoft Windows 7 Ultimate (x64)
CPU
Intel Core 2 Duo P9700 2.80GHz (6MB Cache)
Motherboard
Intel Cantiga ICH9M Chipset + Intel GM45 Chipset
Memory
4.00GB DDR3 1.066MHz
Graphics Card(s)
Intel GMA 4500MHD; nVIDIA GeForce GT130M 512MB DDR3
Sound Card
Realtek High Definition Audio
Monitor(s) Displays
Mobile Intel 4 Series Express Chipset
Screen Resolution
1440x900 (17")
Hard Drives
320GB 7200RPM Serial-ATA (16MB cache)
Hello Propaganistas, glad you got it sorted; thanks for the info!
 

My Computer

Computer Manufacturer/Model Number
* BFK Customs *
OS
W 7 64-bit Ultimate
CPU
Intel Q9550 Yorkfield
Motherboard
ASUS P5Q Pro
Memory
8GB Dominator 8500C5D
Graphics Card(s)
ATI : XFX 5870
Sound Card
Realtek HD Audio 7-1
Monitor(s) Displays
1x 47" LCD HDMI & 3x 26" LCD HDMI
Screen Resolution
1920x1080P & 1920x1200
Hard Drives
1x 80GB Intel X25-M G2 SSD : 1x 500GB & 1x 640GB WD Caviar Black(s)
PSU
Corsair 620HX
Case
Cooler Master RC-690
Cooling
Tuniq Tower 120, 2x 140mm and 3x 120mm case fans
Keyboard
Microsoft 500
Mouse
Razer Diamondback 3G
Internet Speed
14 Mb/s
Other Info
1x Koutech 3Gb/s SATA HDD Hot Swap Rack
Back
Top