Computer Hope

Microsoft => Microsoft DOS => Topic started by: JohnGalt on April 09, 2008, 09:40:01 AM

Title: HELP with user input for cd location after batch file starts
Post by: JohnGalt on April 09, 2008, 09:40:01 AM
Hi everyone,
I'm new to the forum and creating batch files in general.  I did some browsing to see if I could find a solution to my problem before posting and so far found something that was very useful but not quite what I had it mind.  I'm trying to create a batch file that will prompt for a directory path and then that path would be used to point to the location to register the .dll files there.
Code: [Select]
echo This will reregister all .dll files in a given directory.
set /p chgdir="Please type the directory where the dll files are located: "
cd %chgdir%
for %m in (*.dll) do regsvr32 /s %m

I found a thread that had this option for registering .dll files in a set directory.
Code: [Select]
@echo on
for %%a in ("c:\Program Files\workfolder\*.dll" "c:\Program Files\workfolder\data*.dll") do start /B "regsvr32.exe %%a"
pause

I would like to use either method as long as I can have the directory location inputted after the batch file has started and not be dependent on creating any additional files or anything.
Title: Re: HELP with user input for cd location after batch file starts
Post by: blastman on April 09, 2008, 01:08:15 PM
hi,

Welcome to the forums.  :)


I've knocked up this simple batch for you to do the job resquested.

I don't use for loops in batch every often so it might need tweaking. I've also added some errorlevel capture so you know weather there has been a problem.

Code: [Select]
@echo off

echo.
echo.
echo.
echo.
set /p answer="Please enter the path for your .dll files (remember to add the \ \ where needed):  "

for %%a in (%answer%"*.dll" %answer%"*.dll") do start /B "regsvr32.exe /s %%a"

if /i "%errorlevel%" gtr "0" (goto pass) else goto fail

:fail
cls
echo.
echo.
echo.
echo. Unable to register dll files. please check location
echo.
echo.
pause
exit

:pass
echo.
echo.
echo.
echo. All dll files registered
echo.
echo.
pause
exit


Hope it helps.

 ;)
Title: Re: HELP with user input for cd location after batch file starts
Post by: JohnGalt on April 09, 2008, 03:04:33 PM
Works like a charm.  Thank you very much.  The only tweaking required is adding it to my main batch file.

On a side note for future use, why is this required 2 times?
Code: [Select]
(%answer%"*.dll" %answer%"*.dll")
Title: Re: HELP with user input for cd location after batch file starts
Post by: JohnGalt on April 10, 2008, 10:41:47 AM
I spoke too soon.  I'm having some serious issues with the register portion of my batch file.  After it registers the .dll files it causes the batch file to no longer function and starts behaving oddly.

Code: [Select]
@echo off
goto menu

:runmenu
pause
set option=
goto menu

:menu
cls
echo.
echo Enter 0 to EXIT without executing a command.
echo Enter 1 to run Windows Management Instrumentation (WMI) repair part 1.
echo Enter 2 to run Windows Management Instrumentation (WMI) repair part 2.
echo Enter 3 to run CCMClean (to uninstall the SMS Client ver 2.50.x only).
echo Enter 4 to reregister all .dll files in a given directory.
echo Enter 5 to run network connection refresh.
echo.
set /p option="Please enter 0,1,2,3,4,5: "
if %option%==5 goto option5
if %option%==4 goto option4
if %option%==3 goto option3
if %option%==2 goto option2
if %option%==1 goto option1
if %option%==0 goto exit
echo Unrecognized option: %option%
goto runmenu

:option5
echo.
echo Refreshing network connection.
pause
ipconfig /release
if %ERRORLEVEL%==1 goto ErrorExit1
ipconfig /flushdns
if %ERRORLEVEL%==1 goto ErrorExit1
ipconfig /registerdns
if %ERRORLEVEL%==1 goto ErrorExit1
ipconfig /renew
if %ERRORLEVEL%==1 goto ErrorExit1
echo.
echo Network connection refreshed.
goto runmenu

:option4
set answer=
echo.
echo This will reregister all .dll files in a given directory.
echo A system restart is recommended after this is completed.
echo.
set /p answer="Please enter the directory path where the .dll files are located (i.e. c:\windows\system32\): "
for %%a in (%answer%"*.dll" %answer%"*.dll") do start /B "regsvr32.exe /s %%a"
rem if %ERRORLEVEL%==1 goto ErrorExit1
goto runmenu

:option3
echo.
echo Starting CCMClean now.  Rerun CCMClean if any errors occur.
c:\temp\ccmclean.exe
if %ERRORLEVEL%==1 goto ErrorExit1
goto runmenu

:option2
echo.
echo Running WMI repair part 2.
winmgmt /clearadap
if %ERRORLEVEL%==1 goto ErrorExit1
winmgmt /kill
if %ERRORLEVEL%==1 goto ErrorExit1
winmgmt /unregserver
if %ERRORLEVEL%==1 goto ErrorExit1
winmgmt /regserver
if %ERRORLEVEL%==1 goto ErrorExit1
winmgmt /resyncperf
if %ERRORLEVEL%==1 goto ErrorExit1
echo.
echo WMI repair complete.
goto runmenu

:option1
echo.
echo Running WMI repair part 1.  If prompted, type: Y
net stop winmgmt
rd /s /q %systemroot%\system32\wbem\repository
if %ERRORLEVEL%==1 goto ErrorExit1
goto runmenu

:ErrorExit1
echo.
echo Last command failed to execute.
echo Rerun that option or choose another option.
goto runmenu

:exit
echo.
echo Exiting program.  Rerun program as needed.
pause
set option=



Below is a copy & paste from the cmd window.  It should have gone to :runmenu and paused but it did not.  It didn't even go the :menu but instead went back to my current dir path but the dos environment was then acting odd and not allowing me to run the batch file correctly or even exit.
Code: [Select]
Enter 0 to EXIT without executing a command.
Enter 1 to run Windows Management Instrumentation (WMI) repair part 1.
Enter 2 to run Windows Management Instrumentation (WMI) repair part 2.
Enter 3 to run CCMClean (to uninstall the SMS Client ver 2.50.x only).
Enter 4 to reregister all dll files in a specific directory.
Enter 5 to run network connection refresh script.

Please enter 0,1,2,3,4,5: 4

This will reregister all .dll files in a given directory.
A system restart is recommended after this is completed.

Please enter the directory path where the .dll files are located (i.e. c:\window
s\system32\): C:\Program Files\Internet Explorer\MUI\0409
Press any key to continue . . . Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\xu855c\My Documents\Executables\RDMI>Microsoft Windows
 XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\xu855c\My Documents\Executables\RDMI>Microsoft Windows
 XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\xu855c\My Documents\Executables\RDMI>Microsoft Windows
 XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\xu855c\My Documents\Executables\RDMI>




^C
C:\Documents and Settings\xu855c\My Documents\Executables\RDMI>

C:\Documents and Settings\xu855c\My Documents\Executables\RDMI>C:\Documents and
Settings\xu855c\My Documents\Executables\RDMI>C:\Documents and Settings\xu855c\M
y Documents\Executables\RDMI>

If someone can take a look and find out where I'm going wrong I would really appreciate it.
Maybe I'm being too ambitious or something...  ???
Title: Re: HELP with user input for cd location after batch file starts
Post by: blastman on April 10, 2008, 11:58:00 AM
hey,

what i do when I'm having trouble finding a fault in a batch file is to first remove or 'rem' out the @echo off line so you can see each command run.

I also like to add pauses and a brief description at every step.

ie,

Code: [Select]
:menu
echo just got to main menu
pause
and so on.

another good tip is to run your batch file from a command prompt, that way unless you have exit at the end the window will remain open allowing to you see the last command that was run.

I don't have .dll to register myself and so can't replicate the fault.

I hope this has been of some help to you.

Blastman