Solved

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

Posted on 2014-01-15
6
1,060 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 43

Accepted Solution

by:
Steve Knight earned 500 total points
Comment Utility
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
Comment Utility
This did it perfectly.

Thanks for all the help.
0
 
LVL 43

Expert Comment

by:Steve Knight
Comment Utility
No problem, good luck with it.
Steve
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
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 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…

772 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

11 Experts available now in Live!

Get 1:1 Help Now