Code: Select all
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; WhereAmI.ahk
; Created by: TXShooter with help from https://www.reddit.com/r/AutoHotkey/comments/6haneq/external_ip_address/
; Purpose: To write a file to the MS OneDrive cloud folder the system's pertinent information for tracking purposes and other uses like a psuedo dyndns.
; Run EXE at startup in the System Tray with Tool Tips giving updated information.
;
; Date: 2018.03.25
; Revision: 1
; Synopsis: When executed, this script will perform the following in sequence:
; 1) Read from the system Registry where the Microsoft OneDrive folder is located,
; 2) Start a timer to cycle every X minutes (i.e. 15 minutes)
; 3) Loop the following at the start of each timed cycle:
; A) Get the LAN IP Address (lanIP). Error if not valid.
; B) Get the WAN IP Address (wanIP). Error if not valid.
; C) Get current date and time (time)
; D) Get OS Version
; E) Write INI File with the above information in the root of the OneDrive folder
; F) Update Systray's icon tool tip
; 4) Write to Windows System Registry HKLM 'Run' key the EXE Path for automatic startup at boot.
;
; DEBUG ISSUES:
; 1) Using the clipboard to obtain the IP Addresses prevents usage of the clipboard for normal Windows operations.
; 2) The Tool Tip for the Systray is not updating the IP Addresses at all, whereas the double-click 'Open' SysTray Menu label is working correctly. [SOLVED]
; a) Tool Tip for the Sysray for the variable "User" and "OSVer" are working correctly.
; 3) The variable "Time" is not updating. {SOLVED]
; 4) Unable to add the EXE file's path to the System Registry for unknown reason(s). Could be a permission issue?
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Environment Setup:
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#SingleInstance, Force
#Persistent
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;SysTray Menu Setup:
Menu, Tray, NoStandard
Menu, Tray, Add, Exit, Exit
Menu, Tray, Add, Open, Open
Menu, Tray, Default, Open
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Variables:
Global OneDriveFolder := ""
RegRead, OneDriveFolder, HKEY_CURRENT_USER\Environment, OneDrive
OneDriveFolder := OneDriveFolder . "\"
Global WhereAmIKey := "SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
Global WhereAmIString := "C:\Program Files\WhereAmI\WhereAmI.exe"
RegWrite, REG_SZ, HKLM, %WhereAmIKey%, WhereAmI, %WhereAmIString%
clipSave := ClipboardAll
Clipboard := clipSave
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Script:
SetTimer, GetInfo, 1000 ; Timer in milliseconds
GetInfo() ; Immediately call GetInfo()
Return
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Main:
GetInfo()
{
Global Time = A_Now
FormatTime, Time,, yyyy.MM.dd - HH:mm:ss
GetLanIP()
GetWanIP()
Menu, Tray, Tip, User: %A_Username%`nComputer Name: %A_ComputerName%`nLanIP: %lanIP%`nWanIP: %wanIP%
IniWrite, %A_Username%, %OneDriveFolder%%A_ComputerName%.ini, %A_ComputerName%, User
IniWrite, %A_OSVersion%, %OneDriveFolder%%A_ComputerName%.ini, %A_ComputerName%, OSVer
IniWrite, %wanIP%, %OneDriveFolder%%A_ComputerName%.ini, %A_ComputerName%, ExtIP
IniWrite, %lanIP%, %OneDriveFolder%%A_ComputerName%.ini, %A_ComputerName%, IpAddr
IniWrite, %Time%, %OneDriveFolder%%A_ComputerName%.ini, %A_ComputerName%, Time of last update
return
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Labels:
Exit:
ExitApp
Open:
MsgBox, User: %A_Username%`nComputer Name: %A_ComputerName%`nLanIP: %lanIP%`nWanIP: %wanIP%`nTime: %Time%
return
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Functions:
GetLanIP() ; Credit https://www.reddit.com/r/AutoHotkey/comments/6haneq/external_ip_address/
{
Clipboard := ""
run, %ComSpec% /c ipconfig | CLIP, , Hide
ClipWait
lanInfo := Clipboard
loop, Parse, lanInfo, `n
{
if(InStr(A_LoopField, "IPv4"))
{
Global lanIp := Trim(SubStr(A_LoopField, InStr(A_LoopField, ":")+2), "`r`n")
return
}
}
Global lanIP := "Check Network Connection"
Return
}
GetWanIP() ; Credit https://www.reddit.com/r/AutoHotkey/comments/6haneq/external_ip_address/
{
Clipboard := ""
run, %ComSpec% /c nslookup myip.opendns.com resolver1.opendns.com | CLIP, , Hide
ClipWait
wanInfo := Clipboard
if(!InStr(wanInfo, "Name:"))
{
Global wanIP := "Check Network Connection"
return
}
else
{
wanInfo := SubStr(wanInfo, instr(wanInfo, "Name:"))
loop, Parse, wanInfo, `n
{
if(InStr(A_LoopField, "Address"))
{
Global wanIP := Trim(SubStr(A_LoopField, InStr(A_LoopField, ":")+3), "`r`n")
break
}
}
}
return
}
debugQuit()
{
MsgBox Debug Stop.
WinActivate, ahk_class Notepad++
ExitApp
}
EDIT1: Updated to show OP has been solved (thanks to gregster)... now looking for help with Debug Item #1.
EDIT2: Updated to show SP has been solved (Debug Item #1) (thanks again to gregster)... now looking for help on Debug Item #4.