?
Solved

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

Posted on 2014-01-15
6
Medium Priority
?
1,125 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 43

Accepted Solution

by:
Steve Knight earned 2000 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

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

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

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…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
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…
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…
Suggested Courses
Course of the Month12 days, 16 hours left to enroll

777 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