Home All Groups Group Topic Archive Search About
Author
8 Jul 2009 12:48 PM
Andy
Anyone know how I programmatically obtain the name of the host machine, in a
form suitable for subsequently using in CreateObject?

(VB6 + SP6)

Thanks in advance

Author
8 Jul 2009 1:19 PM
mayayana
> Anyone know how I programmatically obtain the name of the host machine, in
a
> form suitable for subsequently using in CreateObject?
>

   You mean like calling gethostbyaddr? You can see if
this is what you need:
  www.jsware.net/jsware/vbcode.php5#htp

  It's a userControl for doing IP -> hostname translation.
That can be turned into an ActiveX control if for some
reason you have to access a component with Dispatch
interface. There's a version like that here, designed for
use with VBScript:
  www.jsware.net/jsware/scripts.php5#jshttp
Are all your drivers up to date? click for free checkup

Author
8 Jul 2009 2:41 PM
Andy
Thanks for your help - I downloaded the code from the first link you sent,
but I think it might be a little over the top for what I need.

If I go into VB's Help, then 'About Microsoft VB..', and click on System
Info, I get a whole load of info, including the System Name, which, on my
development machine, is 'ANDREW'.

If I now write code in my app, such as

Dim xlApp as Object
Set xlApp = CreateObject("Excel.Application", "ANDREW")

and set a breakpoint immediately after that, I can run the code up to the
breakpoint, look in Task Manager, and sure enough, there's a copy of Excel in
the list of processes.  So I need a way of programmatically finding 'ANDREW'.
Here's why...

My app will run on an ethernet LAN, and there may be several instances
running on different machines.  The app uses Winsock to determine whether
it's the only running instance, by broadcasting a packet and waiting for a
reply.  If it gets nothing, that means it's designated 'server' in the
context of what the app has to do.  (Perhaps I should have said 'System Name'
instead of 'servername' in my OP, but I lifted the latter term from MSDN help
on the CreateObject function.)  If the app gets a reply to the broadcast,
that reply will be from the 'server', and it should include the server's
System Name, for subsequent use in a call to CreateObject.  This is so that a
reference to the object model *on that specific server* can be retrieved
using CreateObject.
Author
8 Jul 2009 2:56 PM
Bill McCarthy
Hi Andy,

Look for GetComputerName API . If you don't need unicode, it's as simple as
calling:

Public Declare Function GetComputerName Lib "kernel32" Alias
"GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Dim name as String
Dim length as Long
length = 255
name = Space$(length)
GetComputerName name, length





Show quoteHide quote
"Andy" <andrewjellis@hotmailnospam.com> wrote in message
news:D89576D3-5EB1-4357-A460-FA1198C054BA@microsoft.com...
> Thanks for your help - I downloaded the code from the first link you sent,
> but I think it might be a little over the top for what I need.
>
> If I go into VB's Help, then 'About Microsoft VB..', and click on System
> Info, I get a whole load of info, including the System Name, which, on my
> development machine, is 'ANDREW'.
>
> If I now write code in my app, such as
>
> Dim xlApp as Object
> Set xlApp = CreateObject("Excel.Application", "ANDREW")
>
> and set a breakpoint immediately after that, I can run the code up to the
> breakpoint, look in Task Manager, and sure enough, there's a copy of Excel
> in
> the list of processes.  So I need a way of programmatically finding
> 'ANDREW'.
> Here's why...
>
> My app will run on an ethernet LAN, and there may be several instances
> running on different machines.  The app uses Winsock to determine whether
> it's the only running instance, by broadcasting a packet and waiting for a
> reply.  If it gets nothing, that means it's designated 'server' in the
> context of what the app has to do.  (Perhaps I should have said 'System
> Name'
> instead of 'servername' in my OP, but I lifted the latter term from MSDN
> help
> on the CreateObject function.)  If the app gets a reply to the broadcast,
> that reply will be from the 'server', and it should include the server's
> System Name, for subsequent use in a call to CreateObject.  This is so
> that a
> reference to the object model *on that specific server* can be retrieved
> using CreateObject.
Author
8 Jul 2009 3:10 PM
mayayana
Oh, sorry, that's a very different thing. hopefully
someone will pipe up to tell you how to get
a computername across a network.

  But I wonder if you might also may have other problems
with that code. CreateObject *for .Net* has a location
parameter but CreateObject in VB only has a ServerName
parameter.
Which is actually ServerName.ClassName.  Excel
is the *COM* server. Application is the class. And that
would be a different thing from the computer name of the
box where you're designating a running instance as the
"server" for other host machines.



Show quoteHide quote
> Thanks for your help - I downloaded the code from the first link you sent,
> but I think it might be a little over the top for what I need.
>
> If I go into VB's Help, then 'About Microsoft VB..', and click on System
> Info, I get a whole load of info, including the System Name, which, on my
> development machine, is 'ANDREW'.
>
> If I now write code in my app, such as
>
> Dim xlApp as Object
> Set xlApp = CreateObject("Excel.Application", "ANDREW")
>
> and set a breakpoint immediately after that, I can run the code up to the
> breakpoint, look in Task Manager, and sure enough, there's a copy of Excel
in
> the list of processes.  So I need a way of programmatically finding
'ANDREW'.
>  Here's why...
>
> My app will run on an ethernet LAN, and there may be several instances
> running on different machines.  The app uses Winsock to determine whether
> it's the only running instance, by broadcasting a packet and waiting for a
> reply.  If it gets nothing, that means it's designated 'server' in the
> context of what the app has to do.  (Perhaps I should have said 'System
Name'
> instead of 'servername' in my OP, but I lifted the latter term from MSDN
help
> on the CreateObject function.)  If the app gets a reply to the broadcast,
> that reply will be from the 'server', and it should include the server's
> System Name, for subsequent use in a call to CreateObject.  This is so
that a
> reference to the object model *on that specific server* can be retrieved
> using CreateObject.
Author
8 Jul 2009 3:29 PM
Bill McCarthy
Nope., that's all entirely WRONG.  CreateObject in VB6 lets you specify the
machine name.  Please look at the VB6 documentation if in doubt.

Show quoteHide quote
"mayayana" <mayaXXy***@rcXXn.com> wrote in message
news:Of%23eg69$JHA.1376@TK2MSFTNGP02.phx.gbl...
>   Oh, sorry, that's a very different thing. hopefully
> someone will pipe up to tell you how to get
> a computername across a network.
>
>  But I wonder if you might also may have other problems
> with that code. CreateObject *for .Net* has a location
> parameter but CreateObject in VB only has a ServerName
> parameter.
> Which is actually ServerName.ClassName.  Excel
> is the *COM* server. Application is the class. And that
> would be a different thing from the computer name of the
> box where you're designating a running instance as the
> "server" for other host machines.
>
>
>
>> Thanks for your help - I downloaded the code from the first link you
>> sent,
>> but I think it might be a little over the top for what I need.
>>
>> If I go into VB's Help, then 'About Microsoft VB..', and click on System
>> Info, I get a whole load of info, including the System Name, which, on my
>> development machine, is 'ANDREW'.
>>
>> If I now write code in my app, such as
>>
>> Dim xlApp as Object
>> Set xlApp = CreateObject("Excel.Application", "ANDREW")
>>
>> and set a breakpoint immediately after that, I can run the code up to the
>> breakpoint, look in Task Manager, and sure enough, there's a copy of
>> Excel
> in
>> the list of processes.  So I need a way of programmatically finding
> 'ANDREW'.
>>  Here's why...
>>
>> My app will run on an ethernet LAN, and there may be several instances
>> running on different machines.  The app uses Winsock to determine whether
>> it's the only running instance, by broadcasting a packet and waiting for
>> a
>> reply.  If it gets nothing, that means it's designated 'server' in the
>> context of what the app has to do.  (Perhaps I should have said 'System
> Name'
>> instead of 'servername' in my OP, but I lifted the latter term from MSDN
> help
>> on the CreateObject function.)  If the app gets a reply to the broadcast,
>> that reply will be from the 'server', and it should include the server's
>> System Name, for subsequent use in a call to CreateObject.  This is so
> that a
>> reference to the object model *on that specific server* can be retrieved
>> using CreateObject.
>
>
Author
8 Jul 2009 6:22 PM
Nobody
"Andy" <andrewjellis@hotmailnospam.com> wrote in message
news:D89576D3-5EB1-4357-A460-FA1198C054BA@microsoft.com...
> My app will run on an ethernet LAN, and there may be several instances
> running on different machines.  The app uses Winsock to determine whether
> it's the only running instance, by broadcasting a packet and waiting for a
> reply.  If it gets nothing, that means it's designated 'server' in the
> context of what the app has to do.

In that case, the problem is much simpler. You don't have to use a hostname,
you can specify an IP address in the second parameter to CreateObject(), so
get the IP from the packet that you received from Winsock, which is in
RemoteHostIP Property.
Author
8 Jul 2009 3:23 PM
Rick Raisley
By host machine, do you mean the name of the computer running your program?
If so, yes:

Environ$("COMPUTERNAME")

--
Regards,

Rick Raisley
heavymetal-A-T-bellsouth-D-O-T-net

Show quoteHide quote
"Andy" <andrewjellis@hotmailnospam.com> wrote in message
news:96872E98-ECDB-4C46-91AC-43FE4A917536@microsoft.com...
> Anyone know how I programmatically obtain the name of the host machine, in
> a
> form suitable for subsequently using in CreateObject?
>
> (VB6 + SP6)
>
> Thanks in advance

Bookmark and Share