Batch File Opens CMD, then Closes It.

August 24, 2011 at 01:07:27
Specs: Windows 7 32-bit, 3.00gb
Hi . . .
I'm not sure if this is exactly the right place to post this problem, but here goes . . .

I wanted to make a shortcut to change my IP address to static or dynamic, depending on which I've already got it set to . . .

So I made a little script in a batch file to do this, but when I run it, the CMD opens briefly (for less than a second) before closing itself straight away . . .

When I check my IP address settings, nothing changes . . .

Am I doing something wrong . . . ??

I haven't coded much before, just used AutoHotkey if anyone's heard of that, I nabbed these little bits of code from here and there on the internet to make sure that I was doing it right . . .

[Batch File]
@echo off
echo Please wait
ipconfig>temp0
type temp0 | findstr /i "address" >temp1
for /f "tokens=15" %%i IN (temp1) do (
echo @echo off>fix.bat
echo if not %%i==192.168.xx.xx set j=192.168.xx.xx>>fix.bat
echo if not %%i==192.168.xx.xx netsh int ip set address "local area connection" static %%j%% 255.255.255.0 192.168.xx.xx 1 >>fix.bat
echo if not %%i==192.168.xx.xx netsh interface ip set dns "Local Area Connection" static 192.168.xx.xx >>fix.bat
echo if %%i==192.168.xx.xx netsh interface ip set address "Local Area Connection" dhcp >>fix.bat
echo if %%i==192.168.xx.xx netsh interface ip set dns "Local Area Connection" dhcp >>fix.bat
call fix.bat
)
del /q temp0
del /q temp1
del /q fix.bat
exit
[/Batch File]

One other note, I have full administrative privileges and have even tried running this as administrator . . .

Any help would be greatly appreciated, thanks for looking . . . !!

Chris . . .


See More: Batch File Opens CMD, then Closes It.

Report •


#1
August 24, 2011 at 01:30:38
I would suggest that, whilst debugging your batch file, you omit the "echo off" statements, so that you can see what is happening. I'd also suggest that you do not, for the moment, delete the temporary files. It may be that an examination of them will reveal the problem to you.

Once you have the program working you can then reinstate the cleaning up and the supression of output from the program.


Report •

#2
August 24, 2011 at 06:55:09
192.168.xx.xx
I love how you're hiding a non-routable IP address, as if we'd care your PC is on 192.168.1.101. :3

Also, it looks like you're making things far too difficult for yourself. Ignore what the settings are and just set the configuration to should be. Netsh can work out the details.

How To Ask Questions The Smart Way


Report •

Related Solutions


Ask Question