|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Getting servernameAnyone 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 > Anyone know how I programmatically obtain the name of the host machine, in You mean like calling gethostbyaddr? You can see ifa > form suitable for subsequently using in CreateObject? > 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 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. 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. 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. 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. > > "Andy" <andrewjellis@hotmailnospam.com> wrote in message In that case, the problem is much simpler. You don't have to use a hostname, 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. 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. By host machine, do you mean the name of the computer running your program?
If so, yes: Environ$("COMPUTERNAME") -- Show quoteHide quoteRegards, Rick Raisley heavymetal-A-T-bellsouth-D-O-T-net "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
Other interesting topics
Unicode Support in VB6
dhrichclient3 requests best way to write a VB-app with several languages Keeping 2 listboxes in sync - VB6 ListBox - Limit Selection Rectangle Width In-Process and Out-of-Process Best method to have 2 checkboxes for 1 item array dimensions and size error "&&" string curiosity Command Line |
|||||||||||||||||||||||