Solved

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

Posted on 2014-01-15
6
1,071 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
  • 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

863 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now