Copy and Paste to remote machine \\hostname\c$

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
seannsp
Posts: 7
Joined: 15 Jun 2022, 22:03

Copy and Paste to remote machine \\hostname\c$

Post by seannsp » 15 Jun 2022, 22:08

Hi guys, i quite new here.
Would kindly need you guys for help regarding the task im working on it daily
I have to access to the hostname \\hostname\c$
with the hostname based on what i copied and automatically open file explorer and go to the \\hostname\c$

I've tried a few of ways but seems it doesnt work

Thanks for the help guys

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Copy and Paste to remote machine \\hostname\c$

Post by BoBo » 15 Jun 2022, 23:47

Welcome.

Code: Select all

F12::                                  ; press F12 to run
   clipboard := ""                     ; clearing the clipboard
   Send ^c                             ; sending CTRL+C to copy
   ClipWait                            ; waiting for clipboard to receive content
   Run % "explorer.exe " . clipboard   ; run explorer with content from clipboard 
   Return                              ; reset the Hotkey
Not sure if these paths gets resolved. Can't test it ATM (iOS). Good luck :)

seannsp
Posts: 7
Joined: 15 Jun 2022, 22:03

Re: Copy and Paste to remote machine \\hostname\c$

Post by seannsp » 16 Jun 2022, 00:56

Hello, Your codes works but maybe is because of my explanation is not that accurate
Example i have to access to

Hostname : \\PC001\c$
The Text only shown "PC001

is there a way if i copied "PC001" and hit F12
It will automatically open \\PC001\c$ on the windows explorer?

User avatar
mikeyww
Posts: 26605
Joined: 09 Sep 2014, 18:38

Re: Copy and Paste to remote machine \\hostname\c$

Post by mikeyww » 16 Jun 2022, 04:52

Perhaps:

Code: Select all

F12::Run, explorer.exe \\%Clipboard%\c$
Or:

Code: Select all

F12::
If Instr(FileExist(dir := "\\" Clipboard "\c$"), "D")
 Run, explorer.exe %dir%
Else MsgBox, 48, Error, Directory not found.`n`n%dir%
Return

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Copy and Paste to remote machine \\hostname\c$

Post by BoBo » 16 Jun 2022, 05:25

@seannsp - a quite common way to describe variable parts of a string is to use <>-characters. So \\<hostname>\c$ would indicate that 'hostname' is variable, and in your case should be replaced with the clipboard's content. HTH

seannsp
Posts: 7
Joined: 15 Jun 2022, 22:03

Re: Copy and Paste to remote machine \\hostname\c$

Post by seannsp » 16 Jun 2022, 20:17

The script does open the file explorer but doesnt automatically go the hostname :(
Is there a way for the clipboards to works?

User avatar
mikeyww
Posts: 26605
Joined: 09 Sep 2014, 18:38

Re: Copy and Paste to remote machine \\hostname\c$

Post by mikeyww » 17 Jun 2022, 05:22

You can use MsgBox to display the clipboard's contents, so that you know what it is. That can help with troubleshooting.

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Copy and Paste to remote machine \\hostname\c$

Post by BoBo » 17 Jun 2022, 06:24

@mikeyww - Maybe the OP expects that the ^c(opy) - event is/should be part of your script as well, and therefore pressing F12 without having copied anything beforehand…? :think:

User avatar
mikeyww
Posts: 26605
Joined: 09 Sep 2014, 18:38

Re: Copy and Paste to remote machine \\hostname\c$

Post by mikeyww » 17 Jun 2022, 06:47

Thank you, BoBo, though I noticed:
based on what i copied
and
if i copied "PC001" and hit F12
If the Clipboard is "wrong" or invalid (not a valid path), then it could explain the findings-- hence the suggestion to check & confirm the clipboard.

Leading or trailing white space could also cause problems, easily fixed with a trim.

seannsp
Posts: 7
Joined: 15 Jun 2022, 22:03

Re: Copy and Paste to remote machine \\hostname\c$

Post by seannsp » 19 Jun 2022, 20:41

Code: Select all

#12::
Send ^c
run, "file explorer"
sleep 1000
Send ^v
Send {enter}
return
i tried this way but i not sure how to run it with "\\PC001\c$"
i mean like attach "\\" and "\c$" in between what i copied

Thanks

User avatar
mikeyww
Posts: 26605
Joined: 09 Sep 2014, 18:38

Re: Copy and Paste to remote machine \\hostname\c$

Post by mikeyww » 19 Jun 2022, 21:37

Code: Select all

F3::
Clipboard =
Send ^c
ClipWait, 0
If ErrorLevel
 MsgBox, 48, Error, An error occurred while waiting for the clipboard.
Else Run, % "explorer.exe \\" Trim(Clipboard) "\c$"
Return

seannsp
Posts: 7
Joined: 15 Jun 2022, 22:03

Re: Copy and Paste to remote machine \\hostname\c$

Post by seannsp » 23 Jun 2022, 20:44

Hi Mikey

Thanks for your help all this while
I try ctrl+c and hit F3
it just open file explorer but doesnt go to the hostname\c$

Any idea?

User avatar
mikeyww
Posts: 26605
Joined: 09 Sep 2014, 18:38

Re: Copy and Paste to remote machine \\hostname\c$

Post by mikeyww » 24 Jun 2022, 06:14

The hotkey routine does the clipping for you, so you can skip Ctrl+C.

seannsp
Posts: 7
Joined: 15 Jun 2022, 22:03

Re: Copy and Paste to remote machine \\hostname\c$

Post by seannsp » 26 Jun 2022, 19:53

it just run explorer.exe without inserting \\hostname\c$ :oops:

User avatar
mikeyww
Posts: 26605
Joined: 09 Sep 2014, 18:38

Re: Copy and Paste to remote machine \\hostname\c$

Post by mikeyww » 26 Jun 2022, 20:22

How do you know what it is inserting? How do you know what is on your Clipboard? You can add a MsgBox to find out. Post your revised script below.

seannsp
Posts: 7
Joined: 15 Jun 2022, 22:03

Re: Copy and Paste to remote machine \\hostname\c$

Post by seannsp » 03 Jul 2022, 19:44

How do you know what it is inserting? How do you know what is on your Clipboard? You can add a MsgBox to find out. Post your revised script below.

i highlighted the text of the hostname
How to add a msgbox?

Code: Select all

F3::
Clipboard =
Send ^c
ClipWait, 0
If ErrorLevel
 MsgBox, 48, Error, An error occurred while waiting for the clipboard.
Else Run, % "explorer.exe \\" Trim(Clipboard) "\c$"
Return
[Mod edit: [code][/code] tags added.]

User avatar
mikeyww
Posts: 26605
Joined: 09 Sep 2014, 18:38

Re: Copy and Paste to remote machine \\hostname\c$

Post by mikeyww » 03 Jul 2022, 21:49

Code: Select all

suffix = \c$
F3::
Clipboard =
Send ^c
ClipWait, 0
If !ErrorLevel ; Clipboard succeeded
 If FileExist(netPath := "\\" Trim(Clipboard) suffix) {
  MsgBox, 64, Command line, % cLine := "explorer.exe " netPath
  Run, %cLine%
 } Else MsgBox, 48, Error, Path not found.`n`n%netPath%
Else MsgBox, 48, Error, An error occurred while waiting for the clipboard.
Return

Post Reply

Return to “Ask for Help (v1)”