I have this issue which I did not find an answer to it.
I am creating a small app which SUPPOSE to be easy and it is about getting 4 things (User Name, Pc Name, Domain Name, and IP Address)
I have over 35 pc's connected to a domain, and diff user may logged in to a single pc.
I want the ability that my exe could run from network path \\server\folder\myexe.exe instead of copy the file to each pc local HDD.
I create the program and build it, and put the exe on the UNC, I dblclick on it from my pc (Vista), it works fine.
I tried to run the exe from another pc (XP SP2) it gives security warning "Unhandled exception has occurred in your application, if you click continue, the application will ignore this error and attemp to continue. If you click quit, the application will close immediately
Index was outside the bounds of the array.
here is original code
Dim wsNet As Object wsNet = CreateObject("WScript.Network") txt_UserName.Text = wsNet.UserName txt_DomainName.Text = wsNet.UserDomain txt_PcName.Text = wsNet.ComputerName Dim _HostName = System.Net.Dns.GetHostName() Dim _IPAdress = System.Net.Dns.GetHostAddresses(_HostName)(0).ToString txt_IP.Text = _IPAdress
- The above code works fine on my pc (Vista) if I put it on local HDD or UNC
- The above code also works fine on every pc (XP SP2) if copied to local HDD but will give the mentioned error if run from UNC
- I had comment the first 5 lines, and test it from UNC and the exe works fine on every pc. so, I thought that
CreateObject("WScript.Network") is giving this, here is my tests.
My.User.CurrentPrincipal.Identity.Name.ToString ' <-- Gives Error My.User.Name ' <-- Works from develpment pc and not from other work station Environment.UserDomainName ' <-- Gives Error
I even tried GetUserName() and GetUserNameEx() API and they both gives Error
here is my final code which is working fine except for the domain name.
txt_UserName.Text = Environment.UserName Dim _HostName = System.Net.Dns.GetHostName() txt_PcName.Text = _HostName Dim _IPAdress = System.Net.Dns.GetHostAddresses(txt_PcName.Text)(0).ToString txt_IP.Text = _IPAdress
what else I can use to get the Domain Name?