Solved

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

Posted on 2014-01-15
6
1,094 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Suggested Solutions

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

749 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