0

Here is my script

echo Log In %DATE% at %TIME% with %USERNAME% FROM %COMPUTERNAME% >> \\CORONA\SHARE2\TYLER\"IP DIR"\IPS.TXT
IPCONFIG |FIND "IP" > \\CORONA\SHARE2\TYLER\"IP DIR"\IPS.TXT

Basically I need to have this on our network. I will have a task sequence set up to run this every time a user on our domain logs in...

I need it to log in the document ips.txt (doesn't have to be that name, it can be anything. the location however is where it needs to be) Needs to log the IP, the date, the time, which user, and from what computer.

Any suggestions? i get the error in line 1 char 10.

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
  • I suggest removing the **vbscript** tag and replacing it with the **windows** and **batch-file** tags. – DavidRR Dec 14 '13 at 02:58

2 Answers2

0

It looks as though you are trying to create Windows Batch File (rather than a VBScript File).

So, use a .bat extension for your file, rather than .vbs. And then try this content for your new batch file:

@echo off

setlocal
set LOGFILE=\\CORONA\SHARE2\TYLER\IP DIR\IPS.LOG

for /f "usebackq delims=: tokens=2" %%i in (`ipconfig ^| findstr Address`) do (
set IP=%%i
)

echo Log In %DATE% at %TIME% as %USERNAME% from %COMPUTERNAME% with IP address%IP%>> "%LOGFILE%"

Expected Output

Log In Fri 12/13/2013 at 21:50:35.48 as somebody from COMPNAME with IP address 192.168.1.101

Documentation

Here is documentation for the For keyword.

DavidRR
  • 18,291
  • 25
  • 109
  • 191
  • A problem with using `ipconfig` like this is that the address returned may not be the one you want, as my computer returns 4 addresses and the code above will always take the last one. – foxidrive Dec 15 '13 at 01:14
  • @foxidrive - Is `ping %COMPUTERNAME%` more reliable? Or can you suggest another utility that is ubiquitous on the Windows OS? (Arguably, this is not the most straightforward problem for a Windows batch file.) – DavidRR Dec 15 '13 at 01:23
  • I added some code in an answer, which could be used to get the IP address. – foxidrive Dec 15 '13 at 01:56
0

Here is a method to get IP addesses of the local machine's connection for IPv4 and IPv6 as well as gateway IP address.

@echo off
 WMIC NICConfig where "IPEnabled='True'" get Description, IPAddress, IPSubnet, DefaultIPGateway /value|FIND "="
pause

As David noted in his comment you can use ping %computername% but this gives the IPv6 address on my Windows 8.1 machine.

foxidrive
  • 40,353
  • 10
  • 53
  • 68
  • Thanks for the pointer to **WMIC**. Here's a [WMIC reference](http://ss64.com/nt/wmic.html). I took note that *"To run WMIC requires administrator rights."* I wonder if that might be a problem for the OP. Another concern: If the user's machine is configured for DHCP, there may be delay acquiring an IP address after logging in. So, it may not be possible to capture the IP address at the point of logging in as the OP desires. – DavidRR Dec 16 '13 at 01:08
  • @davidrr It seems to me now that he wants to log the incoming IP address and not the one of the local machine (which is what my suggestion, and also ipconfig, lists). The %computername% variable will only give the local machine, too. – foxidrive Dec 16 '13 at 04:35
  • foxidrive - You could be right...I think the OP needs to further clarify his goals. – DavidRR Dec 16 '13 at 14:12