how to run ipconfig and copy to clipboard

Get help with using AutoHotkey and its commands and hotkeys
aikeo
Posts: 4
Joined: 22 Aug 2020, 09:17

how to run ipconfig and copy to clipboard

27 Aug 2020, 03:58

dear all
I'd like to have some ahk can press hotkey for check IP address in cmd and automatically copy to clipboard that blind people can view or paste in text editor

thanks for hlep
RubbeH
Posts: 44
Joined: 13 Jul 2020, 08:40

Re: how to run ipconfig and copy to clipboard

27 Aug 2020, 05:25

Perhaps something like this?

Code: Select all

DetectHiddenWindows, On
F2::
{
Run, cmd.exe,,hide,myCMD
WinWait, ahk_pid %myCMD%
ControlSend,, ipconfig | clip {enter}
}
return
Not tested tho

edit; Oh, you probably want to extract only the IP address, um. Idk how exactly :/
Figured out that the string for /f "tokens=14" %a in ('ipconfig ^| find "IPv4"') do echo %a | clip
in cmd makes your clipboard just the ipv4-adress, however I can't seem to incorporate that stringin the ControlSend command ..
Last edited by RubbeH on 27 Aug 2020, 06:19, edited 1 time in total.
User avatar
elModo7
Posts: 189
Joined: 01 Sep 2017, 02:38
GitHub: elModo7
Location: Spain
Contact:

Re: how to run ipconfig and copy to clipboard

27 Aug 2020, 06:01

That or just:

Code: Select all

Run, cmd.exe /c ipconfig | clip,, Hide
:beer:
garry
Posts: 2459
Joined: 22 Dec 2013, 12:50

Re: how to run ipconfig and copy to clipboard

27 Aug 2020, 06:35

@elModo7 obrigado.. aargh gracias , it works

Code: Select all

Runwait, %comspec% /c ipconfig | clip,, Hide
msgbox,%clipboard%
return
RubbeH
Posts: 44
Joined: 13 Jul 2020, 08:40

Re: how to run ipconfig and copy to clipboard

27 Aug 2020, 07:48

RubbeH wrote:
27 Aug 2020, 05:25
in cmd makes your clipboard just the ipv4-adress, however I can't seem to incorporate that stringin the ControlSend command ..
Figured it out.

Code: Select all

F2::
{
Runwait, cmd.exe /c for /f "tokens=14" `%a in ('ipconfig ^| find "IPv4" ^| clip') do cd.,,Hide
Msgbox, %clipboard%
}
This displays a Msgbox containing only the ipv4 info from cmd if thats interesting :p
garry
Posts: 2459
Joined: 22 Dec 2013, 12:50

Re: how to run ipconfig and copy to clipboard

27 Aug 2020, 11:22

@RubbeH , thank you for the interesting DOS command example
can also use ahk commands to check clipboard content : if instr or if x contains y etc ...
see also a_variables

Code: Select all

msgbox,%a_ipaddress1%  
A_VARIABLE's example

Code: Select all

;CREATED  = 20160703
#NoEnv  
#Warn
SendMode Input 
SetWorkingDir, %A_ScriptDir%
SetTitleMatchMode 2
SetBatchLines, -1
FormatTime, Suomi , L1035, dddd MMMM yyyy-MM-dd
Filename1=AHK-A_Variables      User=%a_username%        Computer=%a_computername%        %a_osversion%       AHK-Version=%a_ahkversion%       %suomi%
url=http://www.netikus.net/show_ip.html   ;- to show public IP-address
Adr:= UrlDownloadToVar( URL )             ;- desactivate this when no internetconnection
Gui,2:default
Gui,2: -DPIScale
;Gui,2:Font,s14 , Lucida Console
Gui,2:Font,s14 , Verdana
Gui,2:Color,Black
wa:=A_screenwidth,ha:=A_screenHeight
LH :=(ha*89  )/100  ;- LV  height
GH :=(ha*93  )/100  ;- GUI height
LW :=(wa*98.5)/100  ;- LV  width
GW :=(wa*99  )/100  ;- GUI width
T1 :=(wa*12)/100
T2 :=(wa*10)/100
T3 :=(wa*75)/100
t2a:=(t1+t2)
transform,s,chr,32
Gui,2: Add, ListView,grid backgroundBlack cWhite x2 y2 h%LH% w%lw% gMyLV1 vLV1 +altsubmit -multi, Name|AHK-A_Variable|Show Result ( open Info/Folder/File/URL with mouse-click )
LV_ModifyCol(1, T1), LV_ModifyCol(2, T2), LV_ModifyCol(3, T3)             ;- column width
Gui,2:show,x1 y1 h%gh% w%gw%,%filename1%
gosub,smalltools
gosub,e4xvar
e5x:= % ShellFolder()
e6x=%e4x%%e5x%
gosub,fillx
return
FileExit:
2Guiclose:
exitapp
;--------------------------
fillx:
Gui,2:submit,nohide
Gui,2:ListView, LV1
LV_Delete()
GuiControl, -Redraw, LV1
loop,parse,e6x,`n,`r
   {
   y=%a_loopfield%
   if y=
     continue
   LV_Add("", StrSplit(y,",")*)
   }
LV_ModifyCol(1, "Logical SortAsc")
GuiControl, +Redraw, LV1
return
;----------------------------
mylv1:
Gui,2:ListView, LV1
if A_GuiEvent = Normal
 {
 LV_GetText(C1,A_EventInfo,1)
 LV_GetText(C2,A_EventInfo,2)
 LV_GetText(C3,A_EventInfo,3)
 stringmid,C3a,C3,2,2
 stringmid,C3b,C3,1,2
 stringmid,C3c,C3,1,4
 MouseGetPos,x,y
 {
;if x>%T2a%
    {
    if (c3a=":\" or c3b="::" or c3c="http" or c3c="www.")
       {
       try
       run,%c3%
       return
       }
      else
       {
       msgbox, 262208,INFO ,C1=%c1%`nC2=%c2%`nC3=%c3%
       return
       }
  return
     }
  }
 }
return
;-------------------------------
smalltools:
SysGet, VirtualWidth , 78
SysGet, VirtualHeight, 79
EnvGet, EnvGetVar, Path  ;- see #Noenv
RegRead, ProductID, HKEY_LOCAL_MACHINE, SOFTWARE\Microsoft\Windows NT\CurrentVersion, ProductID

osinstalldate1:=OSInstallDate()
OSInstallDate()
{
    for objItem in ComObjGet("winmgmts:").ExecQuery("SELECT * FROM Win32_OperatingSystem")
    {
        FormatTime, InstOS, % SubStr(objItem.InstallDate, 1, 14), % "dd. MMM yyyy - HH:mm"
        FormatTime, DateFrom, % SubStr(objItem.InstallDate, 1, 14), % "yyyyMMdd"
        DateTo := A_Now
        DateTo -= DateFrom, days
        return InstOS "   |   (" DateTo " days)"
    }
}


return
;-------- http://www.autohotkey.com/forum/topic36688.html ---
;MsgBox  % ShellFolder()                  ; To retrieve all
;MsgBox  % ShellFolder( "My Pictures" )   ; To retrieve Pictures folder
;return
ShellFolder( VN="" ) {
v:=""
Static Subkey:="Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders"
 If ( VN="")
 {
 Loop, HKCU, %SubKey%, 0
    {  VarSetCapacity( Spaces,30,32 )
       RegRead, Value, HKCU, %SubKey%, %A_LoopRegName%
       v .= ((v<>"") ? "`n" : "" ) (A_LoopRegName) ",RegRead," Value
    }
 } Else
 RegRead, V, HKCU, %SubKey%, %VN%
Return V
}
UrlDownloadToVar(URL) {
 WebRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1")
 WebRequest.Open("GET", URL)
 WebRequest.Send()
 Return WebRequest.ResponseText
}
e4xVar:
e4x=
(
_A-Variables,,https://autohotkey.com/docs/Variables.htm
C_OsInstallDate,,%osinstalldate1%
C_Microsoft-PRODUCT-ID,productid,%productid%
C_MyComputer,CLSID,::{20d04fe0-3aea-1069-a2d8-08002b30309d}
C_MyNetworkPlaces,CLSID,::{208d2c60-3aea-1069-a2d7-08002b30309d}
C_NetworkConnections,CLSID,::{7007acc7-3202-11d1-aad2-00805fc1270e}
C_Printers,CLSID,::{2227a280-3aea-1069-a2de-08002b30309d}
RecycleBin,CLSID,::{645ff040-5081-101b-9f08-00aa002f954e}
ScheduledTasks,CLSID,::{d6277990-4c6a-11cf-8d87-00aa0060f5bf}
ahk-Version,a_ahkversion,%a_ahkversion%
C_ipaddress-1 private,a_ipaddress1,%a_ipaddress1%
C_ipaddress-2,a_ipaddress2,%a_ipaddress2%
C_ipaddress-3,a_ipaddress3,%a_ipaddress3%
C_ipaddress-4,a_ipaddress4,%a_ipaddress4%
C_ipaddress-0 public,www.netikus.net,%adr%
C_64-bit,a_Is64bitOS,%a_Is64bitOS%
appdata,a_appdata,%a_appdata%
appdatacommon,a_appdatacommon,%a_appdatacommon%
personal mydocuments,a_mydocuments,%a_mydocuments%
programfiles,a_programfiles,%a_programfiles%
programs,a_programs,%a_programs%
programsCommon,a_programsCommon,%a_programsCommon%
start Menu,a_StartMenu,%a_StartMenu%
startMenuCommon,a_StartMenuCommon,%a_StartMenuCommon%
startup,a_Startup,%a_Startup%
startupCommon,a_StartupCommon,%a_StartupCommon%
temp,a_Temp,%a_Temp%
C_username,a_username,%a_username%
DATE,a_YYYY-A_MM-a_DD a_hour:a_min:a_sec,%A_YYYY%-%A_MM%-%a_DD% %a_hour%:%a_min%:%a_sec%
DATE_NOW,a_now,%a_now%
DATE_UTC,a_nowUTC,%a_nowUTC%
DATE_Weekday,a_wday,%a_wday%
DATE_WEEK,a_yweek,%a_yweek%
DATE_DAY,a_yday,%a_yday%
desktop,a_desktop,%a_desktop%
desktopcommon,a_desktopcommon,%a_desktopcommon%
C_computername,a_computername,%a_computername%
C_windir,a_windir,%a_windir%
C_language,a_language,%a_language%
C_admin,a_IsAdmin,%a_IsAdmin%
C_osType,a_OsType,%a_OsType%
C_osversion,a_osversion,%a_osversion%
C_os64bit,a_Is64bitOS,%a_Is64bitOS%
MouseSpeed,a_defaultmousespeed,%a_defaultmousespeed%
C_Screen-Virtual,,%VirtualWidth% * %VirtualHeight% 
C_Screen,a_ScreenWidth-Height,%a_ScreenWidth% * %a_ScreenHeight%
C_ScreenDPI,a_ScreenDPI,%a_ScreenDPI%
Envget,Envget,_%envgetvar%
C_cmd command,comspec,%comspec%
ahk-path,a_ahkpath,%a_ahkpath%
ahk-scriptfullpath,a_scriptfullpath,%a_scriptfullpath%
ahk-HWND,a_scriptHwnd,%a_scriptHwnd%
ptr-size,a_ptrsize,%a_ptrsize%
Encoding,a_FileEncoding,%a_FileEncoding%
Compiled,a_iscompiled,%a_iscompiled%
ahk-ScriptName,a_scriptname,%a_scriptname%
ahk-ScriptDir,a_scriptdir,%a_scriptdir%
Workingdir,a_workingdir,%a_workingdir%
Critical,a_IsCritical,%a_IsCritical%
%s%
)
return
;================= END script ===========================

Return to “Ask For Help”

Who is online

Users browsing this forum: mikagenic, Saarthak Kamra, Smoothglobal, TXShooter and 42 guests