PC Review


Reply
Thread Tools Rate Thread

Check programmatically if live to server

 
 
J.J.
Guest
Posts: n/a
 
      29th Jan 2009
I want to test if the end user is connected to his usual server or working
remotely as part of a conditional statement. DriveExists tests if there is a
drive. Sample code speaks only about floppies. Unfortunately I do not know
what exactly it looks for and have no way of testing to a server if it will
return a False value if the user is not actively hooked up or True as the
default mapping remains on the local machine.
I had thought about using IsReady as it tests if there is media in the
drive. I'd like to get this code piece working before field testing.
Any advise would be appreciated and maybe someone has another suggestion.
Thank you
 
Reply With Quote
 
 
 
 
dymondjack
Guest
Posts: n/a
 
      29th Jan 2009
http://vbnet.mvps.org/index.html?cod...tworkalive.htm

This was brought up in a thread not too long ago. I saved the link but
haven't gotten around to doing anything with it yet. Might be worth checking
out.
--
Jack Leach
www.tristatemachine.com

- "A designer knows he has reached perfection not when there is nothing left
to add, but when there is nothing left to take away." - Antoine De Saint
Exupery


"J.J." wrote:

> I want to test if the end user is connected to his usual server or working
> remotely as part of a conditional statement. DriveExists tests if there is a
> drive. Sample code speaks only about floppies. Unfortunately I do not know
> what exactly it looks for and have no way of testing to a server if it will
> return a False value if the user is not actively hooked up or True as the
> default mapping remains on the local machine.
> I had thought about using IsReady as it tests if there is media in the
> drive. I'd like to get this code piece working before field testing.
> Any advise would be appreciated and maybe someone has another suggestion.
> Thank you

 
Reply With Quote
 
J.J.
Guest
Posts: n/a
 
      29th Jan 2009
Sorry Jack, while one of the subfunctions supposedly asks the exact question
I am looking for, the code calls on a non-existent function. I keep coming
accross another non-exixtent function in VB called GetIsNetworkAvailable.
Any other ideas ?
 
Reply With Quote
 
dymondjack
Guest
Posts: n/a
 
      29th Jan 2009
Here's some code I pulled out of an old db. This must have been shortly
after I first started playing around with vba because I don't seemed to have
saved any information on where the code actually came from (I found it
somewhere, and I generally try to save at least the link to it if the author
didn't include copyright notes), so hopefully I don't get crucified for not
giving credit (if anyone happens to recognize the code and can point me to
the link I'll be sure to save it for future use, if its more than a few days
since this post email it to me because I'll probably loose track of the post
itself).

I *think* this is everything required, though the db that I pulled this from
had a module called modAPIs where I piled anything to do with an API (not
generally a good idea, being that I didn't document much about which
constants when to which apis, etc, etc).

Use at your own risk...


'CODE START

'Declarations for checking the Network Drive Available
Private Declare Function prn_WNetGetConnection _
Lib "mpr.dll" Alias "WNetGetConnectionA" _
(ByVal LocalName$, _
ByVal RemoteName$, _
cbRemoteName&) _
As Long

Private Declare Function prn_WNetAddConnection _
Lib "mpr.dll" Alias "WNetAddConnectionA" _
(ByVal NewPath$, _
Password, _
LocalName&) _
As Long

'Constants for Get/Add Network Connections
Const ERROR_NO_ERROR = 0
Const ERROR_ACCESS_DENIED = 5
Const ERROR_BAD_NETPATH = 53
Const ERROR_BAD_NET_NAME = 67
Const ERROR_ALREADY_ASSIGNED = 85
Const ERROR_INVALID_PASSWORD = 56
Const ERROR_MORE_DATE = 234
Const ERROR_INVALID_ADDRESS = 487
Const ERROR_BAD_DEVICE = 1200
Const ERROR_CONNECTION_UNAVAIL = 1201
Const ERROR_DEVICE_ALREADY_REMEMBERED = 1202
Const ERROR_NO_NET_OR_BAD_PATH = 1203
Const ERROR_NO_NETWORK = 1222
Const ERROR_NOT_CONNECTED = 2250


'==============================================================================
'Checks to see if a drive or printer on the netwrok is available
'Accepts Drive as "C:", "LPT3:" or "\\Network_server\drive"
'Returns True(-1) on Success, False (0) on Faliur
'==============================================================================
Public Function at_CheckNet%(DriveOrPrinter$)
On Error GoTo Err_CN
Dim xMsg As String
Dim xBtns As Variant
Dim xTitle As String
'=========================
Dim dwError&
Dim RemoteNamesz&
Dim RemoteName$
'=========================
at_CheckNet = True
If InStr(DriveOrPrinter, "\\") < 1 Then 'local named resource
RemoteName = String(255, 0)
RemoteNamesz = Len(RemoteName)
dwError = prn_WNetGetConnection(DriveOrPrinter, RemoteName, RemoteNamesz)
If dwError = ERROR_CONNECTION_UNAVAIL Or _
dwError = ERROR_NOT_CONNECTED Or _
dwError = ERROR_NO_NETWORK Then
at_CheckNet = 0
End If
Else 'a network address is supplied to the function
'we supply a null password, which may be required & a null connection
'connection name, since we're not actually connecting, just checking
'the connection. Will return ERROR_DEVICE_ALREADY_REMEMBERED if
'available
dwError = prn_WNetAddConnection(DriveOrPrinter, Null, 0&)
If dwError = ERROR_NO_NETWORK Or _
dwError = ERROR_NOT_CONNECTED Or _
dwError = ERROR_CONNECTION_UNAVAIL Or _
dwError = ERROR_NO_NET_OR_BAD_PATH Or _
dwError = ERROR_ACCESS_DENIED Or _
dwError = ERROR_BAD_NETPATH Or _
dwError = ERROR_BAD_NET_NAME Or _
dwError = 1231 Then 'added
at_CheckNet = 0
End If
End If
'=========================
Exit_CN:
Exit Function
'=========================
Err_CN:
'Err Handling Here
Resume Exit_CN
Resume
End Function



'CODE END



--
Jack Leach
www.tristatemachine.com

- "A designer knows he has reached perfection not when there is nothing left
to add, but when there is nothing left to take away." - Antoine De Saint
Exupery


"J.J." wrote:

> Sorry Jack, while one of the subfunctions supposedly asks the exact question
> I am looking for, the code calls on a non-existent function. I keep coming
> accross another non-exixtent function in VB called GetIsNetworkAvailable.
> Any other ideas ?

 
Reply With Quote
 
Dale Fye
Guest
Posts: n/a
 
      29th Jan 2009
Did you change all of the function declaration statements to Public?

I copied the code from that site and pasted it into a new code module a
couple of days ago, after seeing it in the same thread mentioned by
DymondJack. After changing the function declarations to Public, I was able
to run it without any difficulties.
--
HTH
Dale

email address is invalid
Please reply to newsgroup only.



"J.J." wrote:

> Sorry Jack, while one of the subfunctions supposedly asks the exact question
> I am looking for, the code calls on a non-existent function. I keep coming
> accross another non-exixtent function in VB called GetIsNetworkAvailable.
> Any other ideas ?

 
Reply With Quote
 
dymondjack
Guest
Posts: n/a
 
      30th Jan 2009
*If* I remember correctly, the function that Dale is talking about (the one I
first mentioned), was noted in the previous post as being very quick. I do
know, when using the code I pulled out of the db (the one I advise caution
using), it takes a while for the server to send a response back.

Therefore, I would definately suggest trying this one instead. I have
none-too-fond memories of sitting there twiddling my thumbs for however long
while waiting to see if the server connection was found.

I *think* there was a comment about GetIsNetworkAvailable that mentioned it
being almost instantaneous, which is why I saved the link (I knew the one I
had took forever).

Again, I still haven't gotten around to trying it, but when you make a
decision between the two, I would probably go with GetIsNetworkAvailable.

--
Jack Leach
www.tristatemachine.com

- "A designer knows he has reached perfection not when there is nothing left
to add, but when there is nothing left to take away." - Antoine De Saint
Exupery


"Dale Fye" wrote:

> Did you change all of the function declaration statements to Public?
>
> I copied the code from that site and pasted it into a new code module a
> couple of days ago, after seeing it in the same thread mentioned by
> DymondJack. After changing the function declarations to Public, I was able
> to run it without any difficulties.
> --
> HTH
> Dale
>
> email address is invalid
> Please reply to newsgroup only.
>
>
>
> "J.J." wrote:
>
> > Sorry Jack, while one of the subfunctions supposedly asks the exact question
> > I am looking for, the code calls on a non-existent function. I keep coming
> > accross another non-exixtent function in VB called GetIsNetworkAvailable.
> > Any other ideas ?

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Check programmatically for installed runtimes (.NET / J# / C++) Ralf Abramowitsch Microsoft Dot NET 0 15th Oct 2007 06:39 AM
How to programmatically check if a workbook is protected t? uno@korsmaa Microsoft Excel Programming 2 15th Sep 2004 09:23 PM
Programmatically check directory permissions Steven Microsoft C# .NET 4 14th Jun 2004 05:05 AM
Is there a way to programmatically check names? John Riddle Microsoft Outlook Form Programming 1 11th Sep 2003 03:16 PM
How to programmatically check names? news.acedsl.com Microsoft Outlook Form Programming 0 8th Sep 2003 12:16 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:41 AM.