Solved

VBScript or Bat file to pull IP and Hostname and put into Microsoft Outlook Subject Line

Posted on 2014-01-15
6
1,104 Views
Last Modified: 2014-01-16
We would like to get a vbscript or bat file that can pull the computers IP address plus the hostname of the computer and put this into the subjectline on a new email.

The reason behind this is to help streamline support with those customers who never want to give us the correct information in their tickets.

Is this even possible?

We have a third party app that we can add this to their support icon in their system tray as an option for them to click and easily send us the email.
0
Comment
Question by:considerscs
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 43

Expert Comment

by:Steve Knight
ID: 39783938
Well before getting more complicated does a mailto: link work for the customer, you should be able to get them to run something like:

mailto:user@domain.com?subject=subject line

so you could use that from a batch file together with the IP, depending upon whether you want an internal IP etc.  There are a number of ways I suggest there depending upon what works for you -- there could quite easily be 2,3,4 or more IP addresses on a particular machine, e.g. virtual network cards for XP mode, VMWare etc, wireless at same time as wired etc.

Some of the ways I get the IP there you can see which IP is being used to get to a certain host for instance, i.e. maybe to get back to where you want to connect to them from.

http://scripts.dragon-it.co.uk/links/batch-get-tcpip-subnet

@echo off
for /f "tokens=3,4 delims= " %%a in ('route print ^| find " 0.0.0.0"') do (set gateway=%%a) & (set ipaddress=%%b)
START "mailto:helpdesk@mydomain.com?subject=Computer:%computername%.Domain:%userdomain%.User:%username%.IP:%ipaddress%"

which will send an email with something like this:

Computer:PCNAME.Domain:domain.local.User:stephen.IP:xxx.xxx.xxx.xxx

You could do without the variable of properly configured email if you have an SMTP host available by sending straight to that, lots of ways, e.g. this is one I use:

http://scripts.dragon-it.co.uk/links/email-from-batch

Steve
0
 
LVL 17

Expert Comment

by:Chris Millard
ID: 39783946
Try this VBScript. I've literally just cobbled it together from code I found using Google, so it might need tweaking:-

dim NIC1, Nic, StrIP, CompName
Set NIC1 = GetObject("winmgmts:").InstancesOf("Win32_NetworkAdapterConfiguration")
For Each Nic in NIC1
if Nic.IPEnabled then
StrIP = Nic.IPAddress(i)
Set WshNetwork = WScript.CreateObject("WScript.Network")
CompName= WshNetwork.Computername
set oShell = CreateObject("WScript.Shell")
oShell.Run "mailto:someone@somewhere.com?subject=Hostname=%22"&CompName&"%22%20IP=%22"&StrIP&"%22"
wscript.quit
end if
next

Open in new window

0
 
LVL 1

Author Comment

by:considerscs
ID: 39783948
Yes we want to pull all local IPv4 addresses from the machines.

We want the script to run and pull this information plus the host name and start their outlook (we use exchange), then open a new email with the hostname and ip address in the subject.  Then they can type their issue and hit send.
0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
LVL 43

Accepted Solution

by:
Steve Knight earned 500 total points
ID: 39784016
Please try mine if you haven't already or variation of it for starters.  If you want all IP's that can be got from ipconfig output easily but suspect what I have suggested might be the 'right' IP anyway?

Problem with using ipconfig output is different languages and IPv4 Address vs IP Address for instance but checking for "IP" in the line should be good for most then exclude IPv6, i.e.

@echo off
setlocal enabledelayedexpansion
set ipaddress=
for /f "tokens=2 delims=:" %%a in ('ipconfig ^| find "IP" ^| find /v "v6"') do set ipaddress=!ipaddress!%%a
START "" "mailto:helpdesk@mydomain.com?subject=Computer:%computername%.Domain:%userdomain%.User:%username%.IP:%ipaddress%"

Open in new window


Steve
0
 
LVL 1

Author Closing Comment

by:considerscs
ID: 39786041
This did it perfectly.

Thanks for all the help.
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 39786206
No problem, good luck with it.
Steve
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question