Get Current user's Workstation name logged into Host computer - excel

I have a host machine running windows-7 and users from the home network login using windows remote desktop connection and run some applications ,
I can visually see the log of who logged in under
Event Viewer->Windows Logs->Security->Audit Success->Details->Workstation name
Since only one connection is allowed using Remote Desktop connection, I want to display in an access database who the current user is, from the audit trail so users know if anyone is currently using the Host machine
So basically a VBA code to grab the most recent workstation that logged in, specially I am interested in Event ID-4624
I am open for other suggestions!
what I have tried so far?
Function Reachable(strComputer) As String 'Test Connectivty to computer
'On Error Resume Next
Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService = objSWbemLocator.ConnectServer(strComputer, "root\cimv2", "username", "password")
Set colItems = objWMIService.ExecQuery _
("Select * from Win32_NetworkLoginProfile")
For Each objItem In colItems
Reachable = "Full Name: " & objItem.FullName
Next
End Function

What about Environ("clientname")? At least in the RDP setup I use, it is an environment variable that names my PC that has connected to the remote desktop host computer.

Would this work?
Dim sHostName As String
sHostName = Environ$("computername")

Related

Run SQL Job Agent via Macro Excel by Windows Authentication

I have macro to run manually SQL Job Agent by using userid and Password
Sub Run_Job()
Dim con As Object
Set con = CreateObject("ADODB.Connection")
con.Open = "Provider=sqloledb; Data Source=SERVERNAME; Initial Catalog=DATABASENAME; User Id=USERNAME; Password=PASSWORD;"
con.Execute "exec msdb.dbo.sp_start_job ‘AGENTJOBNAME’"
Workbooks("WORKBOOKNAME.xlsx").Close
End Sub
But when my SQL Server must using Windows Authentication to login ,
how to create macro by using windows auth to run it?
Do small correction to your connection string
con.Open = "Provider=sqloledb; Data Source=SERVERNAME; Initial Catalog=DATABASENAME; Integrated Security=SSPI;"
It switches to integrated authentication.

Azure Point to Site VPN with Basic SKU not working on Windows 10 (ErrorCode = 720 ErrorSource = RAS)

I am trying to connect to Azure vNET Gateway and I am not having success. It ends with ErrorCode = 720 ErrorSource = RAS. Anyone experienced this issue before for the following scenario?
Azure vNET Gateway configured with Basic SKU.
VpnStrategy is SSTP for Windows 10
Authentication: Client certificate (self signed)
Both the root and client certificates are in current user personal store. They are resolved ok.
Root cert is stored in trusted root path of current user
Root cert is saved in Azure vpn gateway user configuration without line breaks
Don't wish to create other SKU to save $$ on poc
Deleted all the WAN Miniport adapters and rebooted the machine with no success. They get recreated automatically
I can't share certificates (root or client) in this forum since I am revealing the vpn gateway endpoint in the logs (for security reason)
Event logs from local machine in the order of execution:
CoId={3285D778-432A-4746-B74C-8B95FECEB53E}: The user SYSTEM has started dialing a Connection Manager connection using a per-user connection profile named az-aks-vnet-v2. The connection settings are:
Dial-in User = P2SDemoClientCert
VpnStrategy = SSTP
DataEncryption = Require
PrerequisiteEntry =
AutoLogon = No
UseRasCredentials = Yes
Authentication Type = EAP <Microsoft: Smart Card or other certificate>
Ipv4DefaultGateway = No
Ipv4AddressAssignment = By Server
Ipv4DNSServerAssignment = By Server
Ipv6DefaultGateway = Yes
Ipv6AddressAssignment = By Server
Ipv6DNSServerAssignment = By Server
IpDnsFlags =
IpNBTEnabled = Yes
UseFlags = Private Connection
ConnectOnWinlogon = No.
CoId={3285D778-432A-4746-B74C-8B95FECEB53E}: The user SYSTEM is trying to establish a link to the Remote Access Server for the connection named az-aks-vnet-v2 using the following device:
Server address/Phone Number = azuregateway-b80c0077-e69d-4f0c-8f50-baa0c7a6e23e-0fe0aceeddbb.vpn.azure.com
Device = WAN Miniport (SSTP)
Port = VPN1-1
MediaType = VPN.
CoId={3285D778-432A-4746-B74C-8B95FECEB53E}: The user SYSTEM has successfully established a link to the Remote Access Server using the following device:
Server address/Phone Number = azuregateway-b80c0077-e69d-4f0c-8f50-baa0c7a6e23e-0fe0aceeddbb.vpn.azure.com
Device = WAN Miniport (SSTP)
Port = VPN1-1
MediaType = VPN.
CoId={3285D778-432A-4746-B74C-8B95FECEB53E}: The link to the Remote Access Server has been established by user SYSTEM.
CoId={3285D778-432A-4746-B74C-8B95FECEB53E}: The user SYSTEM dialed a connection named az-aks-vnet-v2 which has failed. The error code returned on failure is 720.
VPN logs:
******************************************************************
Operating System : Windows NT 10.0
Dialer Version : 7.2.18362.1
Connection Name : az-aks-vnet-v2
All Users/Single User : Single User
Start Date/Time : 6/22/2020, 10:31:31
******************************************************************
Module Name, Time, Log ID, Log Item Name, Other Info
For Connection Type, 0=dial-up, 1=VPN, 2=VPN over dial-up
******************************************************************
[cmdial32] 10:31:31 03 Pre-Init Event CallingProcess = C:\WINDOWS\system32\rasautou.exe
[cmdial32] 10:31:40 04 Pre-Connect Event ConnectionType = 1
[cmdial32] 10:31:40 06 Pre-Tunnel Event UserName = P2SDemoClientCert Domain = DUNSetting = b80c0077-e69d-4f0c-8f50-baa0c7a6e23e Tunnel DeviceName = TunnelAddress = azuregateway-b80c0077-e69d-4f0c-8f50-baa0c7a6e23e-0fe0aceeddbb.vpn.azure.com
[cmdial32] 10:31:42 21 On-Error Event ErrorCode = 720 ErrorSource = RAS
Thanks in advance for the help.
The problem is resolved, I just needed a break from computer and take a long evening walk! This is what I did to fix the problem-
Open Device Manager
Go to Network Adapters
Uninstall all the adapters name starts with "WAN Miniport". Repeat the step for every “WAN Miniport driver” installed
I didn't reboot the machine.
Right click “Network adapters” and select “Scan for hardware changes”
All of the WAN Miniport adapters will reappear immediately
I was able to connect to the VPN Gateway after the above steps and connect to VM with private ip.
Thanks to svenvdveen for the solution with the exception of no reboot. I followed the same instruction (twice) before and I rebooted the machine but didn't have luck!
I ran into a similar issue with Azure Basic Gateway.
For anyone reading this, I suggest you start by simply uninstalling the Wan Miniport (Ikev2). Then try to connect to your VPN again. It worked in my case :).
(Windows 11)

Error while creating Sybase Connection from VB

I am trying to connect to Sybase ASE from VB and getting following error
Function createConnection() As ADODB.Connection
Dim ConnectString As String Dim ConnString As String
Set conn = New ADODB.Connection
.Mode = adModeReadWrite
.ConnectionTimeout = 15
.ConnectionString = "Provider=ASEOLEDB;" & _
"Server Name=" & Range("DBServerName") & _
";Initial Catalog=db;" & _
"User Id=user;" & _
"Password=password"
.Open
End With
Set createConnection = conn
End Function
Any help would be much appreciated.
I would suggest you fist to check odbcad as described here.
If you can find any mention of ASEOLEDB there, then you just have problem either with the app using wrong type of drivers (32-bit vs 64-bit) or with a connection string.
But as the error message suggests, you might be missing just the provider - same problem as here. These libraries are usually part of these installations:
SAP/Sybase ASE
SAP/Sybase ASE PC Client CD
SAP/Sybase ASE SDK
All of these can be acquired on SAP portal, however you need a login to that place as this software is accessible only on purchase. You can find here a link of PC Client CD content (Sybase infocenter website) and a manual on OLEDB here.
Unfortunately only freely downloadable ASE is for Linux, which is useless for you. Maybe you can find on that W7 machine installation media ...
Download & Install Provider
http://devzone.advantagedatabase.com/dz/content.aspx?key=20&Release=19&Product=15
use below commands to register provider
regsvr32 sybdrvodb.dll
regsvr32 sybdrvodb64.dll
Details:
http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.infocenter.dc20116.1550/html/aseodbc/aseodbc43.htm

Drivers to connect to an Oracle Database using VBA

I'm trying to connect to an Oracle Database from an Excel application and whithout a DNS. I found on a website that it's possible to use ADO, so this is why I tried to do. I'm new to this so I juste copied what I found on this website.
Here is my code so far :
Sub ADOtest()
Dim connection As New ADODB.connection
connection.ConnectionString = "UID = user1; PWD= my_pwd; DRIVER = {Microsoft ODBC for Oracle; Server= localhost; Database= orcl.my_domain;"
connection.Open
End sub
When I run this code, I get an error saying that the driver was not found.
The problem is that I have no idea of what I have to do with the driver (how to install it and configure it). Plus, I don't know which one I should use : I've read that there is a driver from Microsoft, another one from Oracle and also I've seen something about providers like msdaora.
The program will be used by many users, so I would like to choose the solution that is the lightest (not much to install on computers).
Thank you !
For COM based ADO (ADODB) you can use the OLE DB Providers.
One is from Oracle, called "Oracle Provider for OLE DB". You can download it from 32-bit Oracle Data Access Components (ODAC) and NuGet Downloads (assuming your Excel is 32-bit). The connection string would be
"Provider=OraOLEDB.Oracle;Data Source=orcl;User ID=myUsername;Password=myPassword"
The other one is from Microsoft. Please note, this provider is deprecated, you should not use it for new projects. Usually it should be available on your Windows. Be aware, like the provider from Oracle it also requires an Oracle Client to be installed on the PC! The connection string would be
"Provider=MSDAORA;Data Source=orcl;User ID=myUsername;Password=myPassword"
The data source is usually defined in tnsnames.ora file or at a LDAP server, for example:
orcl.my_domain =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(Host = localhost)(Port = 1521))
(CONNECT_DATA =
(SERVICE_NAME = orcl)
)
)
If you don't have such entry you can put everything into the connection string, e.g.
"Provider=OraOLEDB.Oracle;Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host=localhost)(Port=1521))(CONNECT_DATA=(SERVICE_NAME=orcl)));User ID=myUsername;Password=myPassword"
Perhaps you have to enclose the data source value by double-quotes ("), I am not sure.
So, in any case you would have to install an Oracle Client at all PC's.
Where is your database server hosted? In your question you say Server=localhost;, this would be quite unlikely, i.e. it is in contradiction to The program will be used by many users. I doubt everybody has an Oracle Database server installed on his local host.

Error 4005 when running ExtractFile in a scheduled agent

I have a scheduled LotusScript agent that I want to loop through documents in a view and extract the attached file(s) to a folder on the server:
'extract file
If Not IsEmpty(rtitem.embeddedObjects) Then
ForAll o In rtitem.EmbeddedObjects
If (o.Type = EMBED_ATTACHMENT) Then
Call o.ExtractFile("\\TestServer\TestFolder\"+o.name)
End If
End ForAll
End If
This agent works fine when ran through the Notes client. However, when the agent is scheduled I get the following error: "Error: 4005 - Notes error: Logon failure: unknown user name or bad password". It errors at the "Call o.ExtractFile(..." line above.
I've tried changing the security level on the agent to "Allow restricted operations with full admin rights" and "Run as Web user" but the error persists.
Any thoughts are greatly appreciated.
This appears to be a network error and not an error within Lotus Notes. Make sure the account under which the server is running has access to the share.
This is very common issue: If you are going to extract the file on
some location then also check the drive is exists on server or not.
Make sure you have proper rights to create a file on the folder, it means folder should have full access.
Agent should have proper rights.

Resources