Jump to content

Which computer is the VI running on?


Recommended Posts

Posted (edited)

Here's a trick I've used to tell which computer my Labview exe is running on:

post-4616-0-45250700-1308918347_thumb.pn

Most of the computers at my workplace have two ethernet connections, local and network. All network addresses around here begin with "172" so I use that to distinguish the two.

This works as long as the connection of interest (Local, preferably, since that connection is not so intermittent :wacko:) is maintained. Alternatively - on SOME computers but not all - I've found that using the network address works, even when IP number 0 is fed to the IP to String function. That function knows, on some computers, the computer's name (e.g. "Paulsdesktop") even when fed a 0.

But I'm sure somebody out there has a better way to tell which computer you're running on. What is it?

Edited by torekp
Posted

Or, you could do something like this (if you are using Windows OS):

post-2411-0-63817100-1308934363_thumb.pn

If you need the IP address, get the AddressList from the IPHostEntry, index the first element and use ToString to convert it to an IP string.

Posted (edited)

A custom windows environment variable could do the trick. Attached is code that I have used a couple times to see which machine it's on.

J2ifr.png

Keep in mind, LabVIEW will not see a new variable without being restarted.

//Edit

Not good if you're only interested in IP address obviously.

Edited by jkuehn
Posted

Thanks guys. I don't really need the IP addresses; that was just the only way I knew how to ID the computer.

John, can I do your trick in LV 8.5? I can't seem to find the "Environment" property.

jkuehn, How do I tell Windows to set a custom environment variable? Is there a Windows system file that I edit?

Posted

jkuehn, How do I tell Windows to set a custom environment variable? Is there a Windows system file that I edit?

It varies a bit from OS to OS, but it's something along the lines of this (Windows 7). Right click Computer -> Properties -> Advanced System Settings -> Advanced Tab -> Environment Variables...

Then you are presented with user variables and system variables that you can modify all you want.

  • Like 1
Posted (edited)

something along the lines of this (Windows 7). Right click Computer -> Properties -> Advanced System Settings -> Advanced Tab -> Environment Variables...

Yup, thanks. Basically the same on XP. Instead of defining a custom variable, though, I just put

cmd /c echo %ComputerName%

in the string, and otherwise identical to your block diagram. :thumbup1: Thanks again.

Edited by torekp

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.