1.

Solve : Issues Passing in Variables to *.CMD's?

Answer»

Where to start:

I'm trying to right a *.cmd with my coding experience being in Java. I need something that will, upon initial click from user execute a listed *.exe stored on a mapped network drive(I KNOW how to do this). After executing, it adds something to the HKCU\..\Run(Got this down). And finally Also adds the file itself plus a passable numeric value. An example registry entry would be something like "\\192.168.0.1\TestFile.cmd 2" to the registry. After this, I'd add a prompt to reboot machine.

What I need the file to do is based upon the value being passed back in, perform an IF/THEN/(possibly ELSE). Basically Pseudo would be something like...

.....

IF Passed_In_Variable != 2 {
Execute THIS_FILE.EXE
REG ADD="HKCU\..\Run\THIS_FILE_RUNS_ON_REBOOT"
REG ADD="HKCU\..\Run\THE_NAME_OF_THE_CONTROLLING_FILE.CMD 2" /f
}

Else {
REG DEL="HKCU\..\Run\THIS_FILE_RUNS_ON_REBOOT"
REG DEL="HKCU=\..\Run\THE_NAME_OF_THE_CONTROLLING_FILE.CMD"
REG ADD="HKCU\..\Run\THIS_FILE_RUNS_ON_REBOOT_NEXT"
}

}


In any event, that should be the short of it, and I hope it makes sense.. the biggest thing I need to know and cant seem to find is how to pass VALUES into a *.cmd and how they are interpretted.

Kthx-PatrickOk, so I've been tinkering on and off today.. this is what I've come up with so far.. and from what I can tell by running "@echo on" it seems to run the first section, irregardless of the fact that the value being passed in does NOT equal 1... This might give a rough idea of exactly what I'm trying to accomplish..

CODE: [Select]
@echo on

echo This is a test Unattended GS SETUP
pause

IF(%1) == 1 Goto SECTION2

:SECTION2
SET KEY=HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
REM REG DEL %KEY% /V GS_NAV_INS /D "I:\GS\NAV2k5\NAVSETUP.EXE" /f
REG ADD %KEY% /V GS_CUSTOMIZER /D "\\10.34.7.1\gsiso\CUSTOMIZER2_0_1\customizer.exe" /f
REG ADD %KEY% /V GS_CONTROLLER /D "I:\Test2.CMD Complete" /f
echo The Test has been successfully completed...
pause
exit
:END





H:\Documents\GS\SymNRT.exe
SET KEY=HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
REG ADD %KEY% /V GS_NAV_INS /D "I:\GS\NAV2k5\NAVSETUP.EXE" /f
REG ADD %KEY% /V GS_CONTROLLER /D "I:\Test2.CMD 1" /f
echo PHASE 1 has been completed of the test
pause
exit



This is just basic.. eventually I'd like to make the installs silent as well, but for now, just getting the executables to run would feel like a small victory!

ARGH... I just posted as you were composing your post
.. BTW, I cleared up the error in my REG DEL bit.. anyways, what I'm staring at blankly atm is:

Code: [Select]
@echo on

echo This is a test Unattended GS SETUP
pause

IF (%1)==(1) Goto SECTION2

:SECTION2
SET KEY=HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
REG DELETE %KEY% /V GS_NAV_INS /f
REG ADD %KEY% /V GS_CUSTOMIZER /D "\\10.34.7.1\gsiso\CUSTOMIZER2_0_1\customizer.exe" /f
REG ADD %KEY% /V GS_CONTROLLER /D "I:\Test2.CMD Complete" /f
echo The Test has been successfully completed...
pause
exit
:END





H:\Documents\GS\SymNRT.exe
SET KEY=HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
REG ADD %KEY% /V GS_NAV_INS /D "I:\GS\NAV2k5\NAVSETUP.EXE" /f
REG ADD %KEY% /V GS_CONTROLLER /D "I:\Test2.CMD 1" /f
echo Phase 1 has been completed of the test
pause
exit






AND yes, there's always JScript, but... at the age of 22, I'd like to learn where it all started too :-P farq'n structured programming anywho...

-PatrickFigured I'd go ahead and create an account :-P I might be here awhile it seems Sorry about deleting my post. One of these days we'll get on the same wavelength. You could try an unconditonal goto after the IF to send it to the other section. If section2 RUNS you have an exit which will shutdown the command window. The way you have it structured, the other section will never run since it will fall thru to section2 regardless of the value of %1.

Also, the ":end" label is never referenced. You can lose it.

Hope this helps. If you know JScript, stick to it. It has much more functionality. here.. I got to tinkering after my post, and a bit more research.. and.. well I ended up breaking the file down into three parts.. a controller, and basically the resolutions to the IF statement..
Controller:
Code: [Select]
@echo on

echo This is a test Unattended GS SETUP
pause

IF (%1)==(1) CALL F:\Test3.CMD

CALL F:\Test4.CMD

pause
exit




Test3.CMD

Code: [Select]
@echo on

SET KEY=HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
REG DELETE %KEY% /V GS_NAV_INS /f
REG ADD %KEY% /V GS_CUSTOMIZER /D "\\10.34.7.1\gsiso\CUSTOMIZER2_0_1\customizer.exe" /f
REG ADD %KEY% /V GS_CONTROLLER /D "I:\Test2.CMD Complete" /f
echo The Test has been successfully completed...
pause
exit


and Test4.CMD
Code: [Select]
@echo on



E:\Documents\GS\SymNRT.exe
SET KEY=HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
REG ADD %KEY% /V GS_NAV_INS /D "I:\GS\NAV2k5\NAVSETUP.EXE" /f
REG ADD %KEY% /V GS_CONTROLLER /D "I:\Test2.CMD 1" /f
echo Phase 1 has been completed of the test
pause
exit



It appears to work beautifully.. NOW.. how the *censored* could I condense this to one solitary file? Anyways, as to why I'm using this.. well.. at work, I have to load some software onto computers at the time of purchase.. generally removing an install of norton, reinstalling it, and adding some software via a 3rd party tool.. The eventual goal is to automate the whole process using silent install switches.. hopefully figuring out the product code of the version of norton that's on there and using the wise unistaller to get rid of it.. as opposed to the SYMNRT.EXE tool(which requires a prompt)..

heres why.. first, not everyone knows that much about the computers, and during busy periods, people from other depts could help.. but they say they don't know how.. easy tool.. simple minds.. good solution.. and... the clincher.. the guys that'd have to approve the usage of this tool don't know jscript.. however, they do know command/batch files.. so.. they are unwilling to learn what I know.. I learn what they know, we're happy, right??

Code: [Select]
@echo on
echo This is a test Unattended GS SETUP
pause

IF (%1)==(1) goto test3
goto test4

:test3
SET KEY=HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
REG DELETE %KEY% /V GS_NAV_INS /f
REG ADD %KEY% /V GS_CUSTOMIZER /D "\\10.34.7.1\gsiso\CUSTOMIZER2_0_1\customizer.exe" /f
REG ADD %KEY% /V GS_CONTROLLER /D "I:\Test2.CMD Complete" /f
echo The Test has been successfully completed...
pause
exit

:test4
E:\Documents\GS\SymNRT.exe
SET KEY=HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
REG ADD %KEY% /V GS_NAV_INS /D "I:\GS\NAV2k5\NAVSETUP.EXE" /f
REG ADD %KEY% /V GS_CONTROLLER /D "I:\Test2.CMD 1" /f
echo Phase 1 has been completed of the test
pause
exit


The "controller" section decides whether to run test3 or test4. Test3 ends with an exit statement, so there is no danger of falling thru to test4. In either case, be aware that the command window will close upon completion.

I'll guess that your registry statments are correct. Generally I prefer updating the registry (and then only if I'm dragged kicking and screaming) interactively or with a Windows Script.

Hope this helps.



Discussion

No Comment Found