Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So far I have the following in my batch file:

%comspec% /c ipconfig | find "IPv4" > %HOMEPATH%\desktop\MyIP.txt
%comspec% /c start notepad %HOMEPATH%\desktop\MyIP.txt

However, when I run the batch file, MyIP.txt is empty when displayed.

On the other hand, when I run each line one after another from Windows-Start search field it works.

Any ideas how to fix it?

share|improve this question

Works fine from a batch file here.

Couple suggestions:

  • Try wrapping the HOMEPATH file paths in quotes to make up for any potential spaces:
    %comspec% /c ipconfig | find "IPv4" > "%HOMEPATH%\desktop\MyIP.txt"
  • Ensure you are running the batch file as a user who has a valid homepath and desktop (and not as say, the "System" account).
  • Try echo %HOMEPATH% alone in another batch file and launch it the same way, check the output to see if %HOMEPATH% expands to what you are expecting (tip add "pause" to the end of the batch to have it wait for you to hit a key).
share|improve this answer
+1 for spaces; would most likely fail on an XP machine ("documents and settings" being part of %HOMEPATH%) without quotes. – panhandel Jun 13 '13 at 17:47
when I just run %HOMEPATH% in a batch file it shows me the following: \Users\60021601 Putting C:\ in front or adding quotes around the destination doesn't make a difference. – user231056 Jun 13 '13 at 18:35
Is your user name really "60021601"? What does echo %homepath%show if you just run it manually at a command prompt? Have you tried running it as a different user? – Ƭᴇcʜιᴇ007 Jun 13 '13 at 18:39
To be honest, my main priority is to display the IP in a notepad window and I would like to avoid saving the txt file on the desktop. Is this possible? – user231056 Jun 13 '13 at 18:43
@techie007 yes, that is my user name. Running as a different user shows a correct name as well. – user231056 Jun 13 '13 at 18:46

Do you have to use a batch file? As per your requirements, the following code saved as GetIP.vbs and executed will launch Notepad and print your IP address(es) in it without saving as a text file first:

Set colItems = GetObject("winmgmts:\\.\root\CIMV2").ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled=TRUE", , 48)
For Each objItem In colItems
    If InStr(objItem.IPAddress(0), ":") = 0 Then
        strIP = "Description: " & objItem.Description & vbCR & "IP Address : " & objItem.IPAddress(0) & vbNewLine
    End If
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "Notepad"
WScript.Sleep 100
WshShell.AppActivate "Notepad"
WshShell.SendKeys strIP
share|improve this answer
wow, what a great script! working nicely but is it possible to tweak it to display only IPv4 addresses (one per line) and omit IPv6? To take it one step further, it would even be better if it would specify the adapter type (LAN or WiFi) for each IP. Lastly, will this work for XP and 7? I wish I knew VBScript to make these changes. Thanks again for your help. – user231056 Jun 14 '13 at 16:33
Have edited the script to include the network adapter description as well as print only IPv4 addresses. It should work fine on XP+ (on XP IPv6 isn't installed by default), but I checked only in Win7. – Karan Jun 14 '13 at 18:18
i just tested the new version and it's showing the description now but if I am connected with both wifi and lan, it only shows wifi info. Is there a way to show both? – user231056 Jun 14 '13 at 18:41
Did the old version handle both correctly? I can't test your scenario at present. Can you try deleting WHERE IPEnabled=TRUE from the SELECT statement and see if that helps? – Karan Jun 14 '13 at 22:03

Save the below given code as batch file in system32 folder.
For Windows 7 keep batch file in C:\Windows\System32 .

@echo                         IP INFORMATION
@echo                         By:Aswin Sha

@ipconfig/all | find "Subnet Mask"
@ipconfig/all | find "IPv4" 
@ipconfig/all | find "Default Gateway"
@ipconfig/all | find "Host Name"
@ipconfig/all | find "DNS Suffix Search List"
@ipconfig/all | find "Physical Address"
@ipconfig/all | find "DHCP Enabled"
@ipconfig/all | find "DHCP Server"
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .