scripting

smokes2345

New member
Local time
5:15 PM
Messages
7
(Admin, feel free to move to more appropriate thread)

I wrote a script to download and update some files on my system when i was using my xp installation. It reads a list of URLs and descriptors from a txt file then downloads the files using wget for windows then looks up a key in the registry to tell where to extract the files to. The script worked fine under xp but under 7 it seems to fail when trying to lookup the registry key. I tried a couple of things to get it working but can't seem to figure it out, the attached file is the original version that was working under xp.
 

Attachments

My Computer

Computer Manufacturer/Model Number
Self-Built
OS
Windows 7 Ultimate x64
CPU
PhenomII X4 940
Motherboard
ASUS M4A785-M
Memory
OCZ DDR2 1066 2x2GB
Graphics Card(s)
Radeon HD 4670
Sound Card
On-board
PSU
700W OCZ 80+
Cooling
~120cm CPU fan + 1x 80cm case fan (in) + 120cm PSU fan (out)
Hi smokes2345,

For reference, here is the code:

Code:
@echo off
set urlFile=addons.list.txt
set tmpFile=tmp.updater.zip
set computer=%computername%
set regpath="HKLM\Software\Wow6432Node\Blizzard Entertainment\World of Warcraft"
set regkey=InstallPath
if not exist cache mkdir cache
::reg query "%regpath%" /v %regkey%
echo REGPATH %regpath%
pause
FOR /F "tokens=3* delims= " %%a in ('Reg Query %regpath% /v "%regkey%" ^| find /i "%regkey%"') do set installDir=%%a
echo Installdir is %installDir%
pause
for /F "tokens=1,2" %%a in (%urlFile%) do (
echo Installing %%a to %installDir%\Interface\Addons\...
wget -N %%b -P cache )
start /D "%installDir%" Launcher.exe
for /r cache %%X in (*) do (
echo Inflating %%X
7za x "%%X" -o"%installDir%\Interface\Addons\" -y )
REM ::if not exist "cache\%%a.zip" ( move %%a.tmp.zip cache\%%a.zip ) ELSE ( if NOT "cache\%%a.zip" EQU "%%a.tmp.zip" ( move %%a.tmp.zip cache\%%a.zip ) ELSE del %%a.tmp.zip ))
::start /D "%installDir%" Launcher.exe

Looking through the code, I can see that it refers to the HKLM branch of the registry. Are you running the file as a standard user? If so, try running it in elevated mode. Right-click on it and select Run as administrator and provide administrative credentials. See how that goes, but I'm sure that a scripting guru will drop by soon.
 

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)
Running the query by hand as admin or regular user works fine, the script returns a syntax error for the query when run in the script. I tried changing some of the encapsulation (moved the ' around) and now the query completes but then the shell says it can't find 'FIND'.
 

My Computer

Computer Manufacturer/Model Number
Self-Built
OS
Windows 7 Ultimate x64
CPU
PhenomII X4 940
Motherboard
ASUS M4A785-M
Memory
OCZ DDR2 1066 2x2GB
Graphics Card(s)
Radeon HD 4670
Sound Card
On-board
PSU
700W OCZ 80+
Cooling
~120cm CPU fan + 1x 80cm case fan (in) + 120cm PSU fan (out)
Moving the ' and " around i got it to run without error but the installDir variable is empty at the end of the loop. I think adjusting the tokens and delim might fix it. new code:

@echo off
set urlFile=addons.list.txt
set tmpFile=tmp.updater.zip

set computer=%computername%
set regpath="HKLM\Software\Wow6432Node\Blizzard Entertainment\World of Warcraft"
set regkey=InstallPath

if not exist cache mkdir cache
::reg query "%regpath%" /v %regkey%
echo REGPATH %regpath%

FOR /F "tokens=3* delims= " %%a in ("Reg Query %regpath% /v %regkey% ^| find /i %regkey%") do (set installDir=%%a;echo %%a)
echo Installdir is %installDir%

pause
for /F "tokens=1,2" %%a in (%urlFile%) do (
echo Installing %%a to %installDir%\Interface\Addons\...
wget -N %%b -P cache )

start /D "%installDir%" Launcher.exe

for /r cache %%X in (*) do (
echo Inflating %%X
7za x "%%X" -o"%installDir%\Interface\Addons\" -y )
REM ::if not exist "cache\%%a.zip" ( move %%a.tmp.zip cache\%%a.zip ) ELSE ( if NOT "cache\%%a.zip" EQU "%%a.tmp.zip" ( move %%a.tmp.zip cache\%%a.zip ) ELSE del %%a.tmp.zip ))

::start /D "%installDir%" Launcher.exe
 

My Computer

Computer Manufacturer/Model Number
Self-Built
OS
Windows 7 Ultimate x64
CPU
PhenomII X4 940
Motherboard
ASUS M4A785-M
Memory
OCZ DDR2 1066 2x2GB
Graphics Card(s)
Radeon HD 4670
Sound Card
On-board
PSU
700W OCZ 80+
Cooling
~120cm CPU fan + 1x 80cm case fan (in) + 120cm PSU fan (out)
Back
Top