I have a Windows logon script running and am compiling a set of details that get logged when the user logons on. As this is a remote server, all logons are done via RDP. I need to get the IP address of the user who has logged on. I have used the following:
Function WAN_IP()
Set objxmlHTTP = CreateObject("Microsoft.XMLHTTP")
Call objxmlHTTP.open("get", "http://checkip.dyndns.org", False)
objxmlHTTP.Send()
strHTMLText = objxmlHTTP.ResponseText
Set objxmlHTTP = Nothing
If strHTMLText <> "" Then
varStart = InStr(1, strHTMLText, "Current IP Address:", vbTextCompare) + 19
If varStart Then varStop = InStr(varStart, strHTMLText, "</body>", vbTextCompare)
If varStart And varStop Then strIP = Mid(strHTMLText, varStart, varStop - varStart)
Else
strIP = "Unavailable"
End If
WAN_IP = Trim(strIP)
End Function
This, as expected, returns the external IP of the server itself and not the IP of the user who has connected.
Is anybody able to let me know how I get the IP of the user connected via RDP?
Following the response from #MarcB I used How to get the IP Address of the Remote Desktop Client? to get the idea on what to do.
I then found some example code here: http://pleasepressanykey.blogspot.com/2008/09/get-users-last-successful-and-failed.html
Related
Does anyone know of a quick and easy way to verify what website I'm currently on?
I have made some script that logs me into a website, but if the user is already logged on, it will create an error.
If anyone knows a good way to tell if they are already logged in, please let me know!
The script is as follows:
Username = InputBox("Please input username")
Password = InputBox("Please input password")
Set objShell = WScript.CreateObject("WScript.Shell")
Dim IE
Set IE = GetObject("new:{D5E8041D-920F-45e9-B8FB-B1DEB82C6E5E}")
IE.Visible = 1
IE.navigate "http://wsmmart.itg.ti.com/"
Do
WScript.Sleep 250
Loop While IE.ReadyState < 4 And IE.Busy
IE.Document.All.Item("fld2").Value = Username
IE.Document.All.Item("fld5").Value = Password
'IE.Document.All.Item("Submit").Click
The following code will loop through all open IE windows and look to see if any one of them has the term "wsmmart.itg.ti." in the url. If it finds a match it will control that window and proceed to insert your username, pw, etc. If it doesn't find a match then you could run your code to open a new window
Set objShell = CreateObject("Shell.Application")
IE_count = objShell.Windows.Count
For x = 0 To (IE_count - 1)
On Error Resume Next ' sometimes more web pages are counted than are open
my_url = objShell.Windows(x).Document.Location
If my_url Like "*" & "wsmmart.itg.ti." & "*" Then 'find an existing wsmmart web page
Set ie = objShell.Windows(x)
Exit For
Else
if x=(IE_count - 1) then
' do your stuff to open a new window
end if
End If
Next
on error goto 0
now try to insert your username, pw, etc. , put it in an if statement. if you get an error back, then you're already logged in
In my exisiting visual basic 6 application I was connecting to an ftp site. Now the other side changed protocol to ftps and changed the port to 22.
My code do not work properly. I get error vb FTP run-time error '35753' "protocol not supported for this method".
I only changed the port in my code and the url
my old url was like ftp.xxx.com.tr
I changed the url to
sftps://ftp.xxx.com.tr
I am trying to connect to the same location using filezilla and it changes the url to sftps://ftp.xxx.com.tr so I copied it. There are similar questions in stackover (Transfer PDF file to ftp server in MS access 2007) but not for ftps. This is my code
With xControl
.AccessType = icDirect
.Protocol = icFTP
.RemotePort = 22
.RequestTimeout = 50
.url = xURL
.UserName = xUserName
.Password = xPassword
.Cancel
.Execute , "DIR " & xFileName
Do While .StillExecuting
DoEvents: DoEvents: DoEvents
Loop
gLogonFtp = "Connected to Host"
End With
Thank you for your time,
Ferda
I used psftp as – wqw (Mar 11 at 13:53) suggested on his comment. Here is my new code.
This is my script file
cd to_remotedir
lcd C:\path2 'local dir
mget * *
quit
result = ChangeFileContent("*", xOnlyFileName) //here I change the content of my script file psftpcommand.bat to get a specific file
Sleep 1000
Shell "C:/path/psftp.exe -v -pw " & xPassword & " " & xUserName & "#" & xURL & ":22 -b C:/path/psftpcommands.bat"
Sleep 1000
result = ChangeFileContent(xOnlyFileName, "*")//here I rechanged the content of the file. Change file name to ->*
'In the below I check if the requested file has come
Sleep 1000
If Dir("C:\path2\" & xOnlyFileName) <> "" Then
gLogonFtp = "Successful"
frmDataTransfers.lblTransferInfoDownLoad.Caption = "Dosya Çekildi " & xOnlyFileName
frmDataTransfers.lblTransferInfoDownLoad.Refresh
End If
That's all.
Thank you for your help.
Ferda
I need to check a Windows Server (many of them a day) and just verify that Unused NIC's are disabled. This is just one of many checks I'm doing.
I'm trying to figure out how I can do this and this is my following code.
It gives me an error with objNetwork.PhysicalAdapter saying
Object doesn't support this property or method:
'objNetwork.PhysicalAdapter'
Sub CheckUnusedNICs()
WScript.Echo("Check for unused NICs")
WScript.Echo("------------------------------------")
Set colNetwork = objWMISrvc.ExecQuery("SELECT * from Win32_NetworkAdapter")
For each objNetwork in colNetwork
WScript.Echo objNetwork.AdapterTypeID & vbCrLf
WScript.Echo objNetwork.PhysicalAdapter
'If (objNetwork.AdapterTypeID = 0 AND objNetwork.PhysicalAdapter = True) Then
' WScript.Echo("Placeholder")
' End If
Next
End Sub
I'm by no means proficient in VBScript but I'm learning it as I go.
The WMI Win32_NetworkAdapter class doesn't have a PhysicalAdapter property.
Use NetConnectionStatus and ConfigManagerErrorCode properties instead.
A device would be:
Enabled and connected if:
NetConnectionStatus = 2
Enabled and no cable is plugged in if:
NetConnectionStatus = 7
Disconnected due to disabled device if:
(NetConnectionStatus = 0) and (ConfigManagerErrorCode = 22)
More details about Win32_NetworkAdapter class including the full list of the above codes can be found at:
http://msdn.microsoft.com/en-us/library/windows/desktop/aa394216(v=vs.85).aspx
I have moved a web site from Win2003 x32 to Win2008R2 x64. It works fine on the old server. The web site uses active directory to authenticate. I get this error on 2008: -2147023584 : A specified logon session does not exist. It may already have been terminated. I have tried switching to classic mode, etc. with no change. It does execute VBScript code (otherwise I wouldn't get the error).
Here is the code:
Function AuthenticateUser(UserName, Password)
On Error Resume Next
Dim oADsNamespace, oADsObject
Dim strADsNamespace, strADsPath
strADsPath = "WinNT://ibcschools.edu"
strADsNamespace = left(strADsPath, instr(strADsPath, ":"))
Set oADsObject = GetObject(strADsPath)
Set oADsNamespace = GetObject(strADsNamespace)
Set oADsObject = oADsNamespace.OpenDSObject(strADsPath, UserName, Password, 0)
Response.Write(Err.Number & " : " & Err.Description & "<br />")
If Err.Number = 0 Then
Set oADsNamespace = Nothing
Set oADsObject = Nothing
Set strADsNamespace = Nothing
Set strADsPath = Nothing
AuthenticateUser = True
Else
Set oADsNamespace = Nothing
Set oADsObject = Nothing
Set strADsNamespace = Nothing
Set strADsPath = Nothing
AuthenticateUser = False
End If
End Function
Any help would be appreciated. Thanks.
Your problem seems to be related to using WinNT provider with OpenDSObject.
Things you could try:
Replace WinNT with LDAP provider.
Try running your standalone VBS file
under IIS/ApplicationPool user privileges.
Okay, so I got it working. Before it worked without the domain name, but now requires it. I think it has something to do with the app pool logging in on the old server versus this one. I am going to work on it a little more. I don't want to change all the sites.
I’ve got a problem with Visual Basic (6) in combination with LDAP. When I try to connect to an LDAP store, I always get errors like ‘Bad Pathname’ or ‘Table does not exist’ (depending on what the code looks like).
This is the part of the code I wrote to connect:
path = "LDAP://xx.xxx.xxx.xxx:xxx/"
Logging.WriteToLogFile "Test1", logINFO
Set conn = CreateObject("ADODB.Connection")
conn.Provider = "ADsDSOObject"
conn.Properties("User ID") = "USER_ID"
conn.Properties("Password") = "PASSWORD"
conn.Properties("Encrypt Password") = True
conn.Properties("ADSI Flag") = 34
Logging.WriteToLogFile "Test2", logINFO
conn.Open "Active Directory Provider"
Logging.WriteToLogFile "Test3", logINFO
Set rs = conn.Execute("<" & path & "ou=Some,ou=Kindof,o=Searchbase>;(objectclass=*);name;subtree")
Logging.WriteToLogFile "Test4", logINFO
The logfile shows “Test1” , “Test2”, “Test3” and then “Table does not exist”, so it’s the line “Set rs = conn.Execute(…)” where things go wrong (pretty obvious…).
In my code, I try to connect in a secure way. I found out it has nothing to do with SSL/certificates though, because it’s also not possible to establish an anonymous unsecured connection. Funny thing is: I wrote a small test app in .NET in five minutes. With that app I was able to connect (anonymously) and read results from the LDAP store, no problems at all.
Does anyone have any experience with the combination LDAP and VB6 and maybe know what could be the problem? I googled and saw some example code snippets, but unfortunately none of them worked (same error messages as result). Thanks in advance!
I'm not sure how much help this will be, but I use this code to access Active Directory objects.
Set oinfo = New ADSystemInfo
sDomain = Split(oinfo.DomainDNSName, ".")
'-- Get Datasets from the Active Directory
'-- Connect to Active Directory in logged in domain
con.Open "Provider=ADsDSOObject;Encrypt Password=False;Integrated Security=SSPI;Data Source=ADSDSOObject;Mode=Read;Bind Flags=0;ADSI Flag=-2147483648"
'-- Query all serviceConnectionPoints in the Active Directory
'-- that contain the keyword "urn://tavis.net/TM/Database"
'-- and return the full path to the object
Set rst = con.Execute("<LDAP://DC=" & sDomain(0) & ",DC=" & sDomain(1) & ">;(&(objectCategory=serviceConnectionPoint)(keywords=urn://tavis.net/TM/Database));Name, AdsPath;subTree")
2 things:
The Open() method call takes additional parameters, server/username/password
The LDAP query you passed to Execute() should be:
"<" & path & "ou=Some/ou=Kindof/o=Searchbase>;(objectclass=*);name;subtree"