I'm using the code below to retrieve some information from remote pcs. Although I have authorized access to most of the pcs but not all.
I have a list of pc names, and my winforms will read it from there.
So my question is, how do I know if I have authorized access to certain pcs?
Const HKEY_LOCAL_MACHINE = &H80000002
objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & line & "\root\default:StdRegProv")
strISC = "Software\Microsoft\Internet Explorer"
On Error Resume Next
objReg.GetStringValue(HKEY_LOCAL_MACHINE, strISC, "svcKBNumber", strKB)
On Error Resume Next
objReg.GetStringValue(HKEY_LOCAL_MACHINE, strISC, "svcVersion", strsvcVersion)
On Error Resume Next
by the way, I know this is actually in vbscript but I was able to use it in vb.net also.
Related
I could use some advice on how to handle a strange issue that happens to my users.
Issue:
All of my users are on laptops that use VPN to connect to our network. When they disconnect from the VPN and reconnect the network drive also disconnects till they open the drive or folder through file explorer. When this happens and they don't re-establish the connection to the network drive they end up with 3304 error.
Error Handling?
What I'd like to do is setup some sort of error handler to tell them thats what happened with a potential link they could click on to re establish the connection. OR even better just have the VBA code identify that error 3304 has occurred and re-establish the connection automatically for them and no pop up error happen at all.
Has anyone done this? I've done some research but nothing I've found quite fits the criteria for this issue. Looking for any advice or push in the right direction.
I was thinking of something like this where either they get a pop up with a link or skip the pop up all together and find a way to re-connect the drive in the background.
On Error GoTo ErrHandler
'Error Handler
ErrHandler:
If Err.Number = 3304 Then
MsgBox "Error Number:" & Err.Number & vbCrLf & _
"Error Description: " & Err.Description & vbCrLf & _
"This error is due to your VPN being disconnected and reconnected"
Else
End If
We faced that issue a couple months ago. We took the route of actually just showing an informative MsgBox to tell the users what to do to solve by themselves calling a function into the 'Workbook_Open' event that fails if a Central Code for the Company its not found with the Dir() function:
Function IsVPNOn(ByVal strCentralCodePath As String) As Boolean
Dim retBoolean As Boolean
On Error Resume Next
If IsError(Dir(strCentralCodePath & g_strCentralCodeName)) Then
MsgBox "The VPN seems to be disconnected." & vbCr & vbCr & _
"Please check VPN connection if Company toolbar is needed.", _
vbCritical + vbOKOnly, "Company Ribbon"
retBoolean = False
Else
retBoolean = True
End If
IsVPNOn = retBoolean
End Function
Not gonna lie, the second option with skipping and reconnecting without the user being even aware of the problem seems more classy, but it is way trickier as you have to deal with connections inside your code.
I have this code that find who has a file opened. The files are on network drives that use our old username as authenication. Our username use to be john.doe, it is now a number 12345. The code does not find a username. Is there something I'm overlooking or need to do to find out who has the file opened? Curious if and when we are on the actual new network that host the username 12345, that we will be able to find see the username 12345. The error message i do get is:
"The trust relationship between this workstation and the primary domain failed"
Public Shared Function GetFileOwner(ByVal strFileName)
Try
Dim objSD As Object = Nothing
Dim objWMIService = GetObject("winmgmts:")
Dim objFileSecuritySettings =
objWMIService.Get("Win32_LogicalFileSecuritySetting='" & strFileName & "'")
Dim intRetVal = objFileSecuritySettings.GetSecurityDescriptor(objSD)
If intRetVal = 0 Then
GetFileOwner = objSD.Owner.Name
Else
GetFileOwner = "Unknown"
End If
Catch ex As Exception
MsgBox("Error :" & Date.Today.ToString & " " & ex.Message)
GetFileOwner = "Unknown"
End Try
End Function
Do you know that this option is available on your server? You can easily do this..
Open the Computer Management snap-in on your file server (or connect to the server remotely from the management console running on your computer) and go to System Tools -> Shared Folders -> Open files. The list of files opened on the remote server is displayed on the right side of the window.
Many times i tried to access my server on the domain and it gave me that error, domains hate custom made apps :)
I'm running a routine in Outlook that will check the "Sent" folder and will look thru public folders to see if emails in "Sent" folder need to be moved to public folder. That's working well.
The problem is that I want this routine to be executed only if Outlook is connected to exchange via the company LAN on Wifi. Reason being that when employees are at home using Outlook, they sometimes don't want that routine to be executed.
So the question being how to detect that Outlook is connected thru company LAN or WIFI?
I've found a way to detect if I'm connected to my company network by using this sub and associated function. For that I try to access a file on the company server. This is not that elegant but it got me that far
Sub TestNetwork()
Dim connected As Boolean
connected = CheckForNetwork()
If connected = False Then
MsgBox ("not connected")
Else
MsgBox ("connected")
End If
End Sub
Function CheckForNetwork() As Boolean
On Error GoTo end
If Len(Dir("\\company_name\company_name\company_name-000\Employee\ _
Employee Name\*.*")) > 0 Then
CheckForNetwork = True
End If
Exit Function
end:
End Function
This will tell me if I'm connected to our company server or not but it won't tell me if it's connected via my home network, a public WiFi spot in an airport or anywhere else.
I need to find out if Outlook is connected via company network or any other connection.
I'll greatly appreciate any help on that matter
Thanks to the suggestion of Sorceri, I found an easy way to retrieve the actual IP adress of a computer. With that I'll be able to detect if the IP adress belongs to my company LAN of if the computer is connected to the Internet via another connection. Inspiration comes frome here: http://www.myengineeringworld.net/2014/12/get-public-ip-local-ip-mac-address-vba.html?m=1 and the final code is as follows
With the following code I first detect if Outlook is online or offline and the I retrieve the IP adress with the GetMyPublicIP function
Sub enligne_horsligne()
'olCachedConnectedDrizzle 600 The account is using cached Exchange code such that headers are downloaded first, followed by the
'bodies and attachments of full items.
'olCachedConnectedFull 700 The account is using cached Exchange mode on a Local Area Network or a fast connection with the Exchange server.
'The user can also select this state manually, disabling auto-detect logic and always downloading full items
'regardless of connection speed.
'olCachedConnectedHeaders 500 The account is using cached Exchange mode on a dial-up or slow connection with the Exchange server, such
'that only headers are downloaded. Full item bodies and attachments remain on the server.
'The user can also select this state manually regardless of connection speed.
'olCachedDisconnected 400 The account is using cached Exchange mode with a disconnected connection to the Exchange server.
'olCachedOffline 200 The account is using cached Exchange mode and the user has selected Work Offline from the File menu.
'olDisconnected 300 The account has a disconnected connection to the Exchange server.
'olNoExchange 0 The account does not use an Exchange server.
'olOffline 100 The account is not connected to an Exchange server and is in the classic offline mode.
'This also occurs when the user selects Work Offline from the File menu.
'olOnline 800 The account is connected to an Exchange server and is in the classic online mode.
Dim myNamespace As Outlook.NameSpace
Dim adresse_IP As String
Dim mpfInbox As Outlook.folder
Set myNamespace = Application.GetNamespace("MAPI")
If (myNamespace.ExchangeConnectionMode = 700 Or myNamespace.ExchangeConnectionMode = 600 Or myNamespace.ExchangeConnectionMode = 700) Then
MsgBox ("Outlook is online")
MsgBox (Environ("userdomain") & "\" & Environ("username"))
Else
MsgBox ("Outlook is offline")
MsgBox (Environ("userdomain") & "\" & Environ("username"))
End If
adresse_IP = GetMyPublicIP()
MsgBox ("The IP adrress is " & adresse_IP)
End Sub
The function GetMyPublicIP is
Function GetMyPublicIP() As String
'source: http://www.myengineeringworld.net/2014/12/get-public-ip-local-ip-mac-address-vba.html?m=1
Dim HttpRequest As Object
On Error Resume Next
'Create the XMLHttpRequest object.
Set HttpRequest = CreateObject("MSXML2.XMLHTTP")
'Check if the object was created.
If Err.Number <> 0 Then
'Return error message.
GetMyPublicIP = "Could not create the XMLHttpRequest object!"
'Release the object and exit.
Set HttpRequest = Nothing
Exit Function
End If
On Error GoTo 0
'Create the request - no special parameters required.
HttpRequest.Open "GET", "http://myip.dnsomatic.com", False
'Send the request to the site.
HttpRequest.Send
'Return the result of the request (the IP string).
GetMyPublicIP = HttpRequest.ResponseText
End Function
I have been using folder browser for VBA, I could paste the code of it, but bottom line is that I get returned file name as a string.
Is there any way to access drawing properties (i.e number of layouts) without open?
Public Sub TestFileDialog()
dwgname = FileBrowseOpen("C:", "*", ".dwg", 1) 'dwgname is typeof string
End Sub
Its only the first step (use of FileBrowseOpen function is shown, but also i can use FolderBrowse and collect all .dwg inside of folder),actually i had in mind to batch export all layouts of selected .dwgs to currenty open one. Is there any chance for that?
To effectively read a .dwg file you'll need to open AutoCAD, otherwise the information is not accessible. Some properties may be, such as author, but not number of layouts...
But you can use AutoCAD Console (accoreconsole.exe) to run a headless AutoCAD and use APIs to read any information you need. This is really fast for reading lot's of files and the user will not see it running (but it needs to be installed anyway).
http://aucache.autodesk.com/au2012/sessionsFiles/3338/3323/handout_3338_CP3338-Handout.pdf
you could stay in VBA and use ObjectDBX
it leads to a very similar approach as accoreconsole.exe on in .NET does, i.e you won't see any drawing open in UI since it works on the database itself
It requires adding library reference (Tools->References) to "AutoCAD/ObjectDBX Common XX.Y Type Library", where "XX.Y" is "19.0" for AutoCAD 2014
a minimal functioning code is
Sub main()
Dim myAxDbDoc As AxDbDocument
Dim FullFileName As String
FullFileName = "C:\..\mydrawing.dwg" '<== put here the full name of the file to be opened
Set myAxDbDoc = AxDb_SetDrawing(FullFileName)
MsgBox myAxDbDoc.Layers.Count
End Sub
Function AxDb_SetDrawing(FullFileName As String) As AxDbDocument
Dim DBXDoc As AxDbDocument
Set DBXDoc = Application.GetInterfaceObject("ObjectDBX.AxDbDocument.19") '<== place correct AutoCAD version numeber ("19" works for AutoCAD 2014)
On Error Resume Next
DBXDoc.Open FullFileName
If Err <> 0 Then
MsgBox "Couldn't open" & vbCrLf & vbCrLf & FullFileName, vbOKOnly + vbCritical, "AxDB_SetDrawing"
Else
Set AxDb_SetDrawing = DBXDoc
End If
On Error GoTo 0
End Function
Still, you must have one AutoCAD session running from which make this sub run! But you should have it since talked about "currently open" drawing
I have a VB6 application which someone wrote, which does not work for only some users who try to use it.
This is the code running which returns an error:
On Error GOTO error_handler
..
Set db = New ADODB.Connection
db.Open "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=****;Password=****; Initial Catalog=***;Data Source=****,1433"
error_handler:
If db.Error.count then
strDBErrors = "No access to Main Database."
For Each err In db.errors
strDBErrors = strDBErrors & vbCrLf & err.Description
Next
MsgBox strDBErrors
After this code runs, I get two Boxes of error. One which states a Runtime Error 3709, And the other which has Two lines: one of it is my Custom error message, and the second if this: "Logon Failed for user the user".
This only happens to one user on a specific computer on which this program is installed. It does not happen on any other computer with any other user.
I tried reinstalling the program with that user on that computer, but it did not work.
Any ideas?
Not quite sure what the problem was,
but I just erased the user on Active Directory and created it again, and it worked.
The user wasn't a member of any deny groups though.