Link to home
Start Free TrialLog in
Avatar of Genius123
Genius123Flag for United States of America

asked on

Windows Clipboard issue

Hello,

From VBScript, I use Internet Explorer to copy a network path to my Windows clipboard.  Due to a recent Windows security update, it does not work now.  Rather than figure out what security update caused it, I just want to stop using IE for this function.  Is there a shell command or something like that I can use?  Here's my code.
Sub CommandButtonClipBoard_Click()

    On Error Resume Next

Dim strCopy
Dim objIE

JobYear = cstr(Year(Item.UserProperties("JobInitiatedDate")))

strCopy = "\\TGPS13VM1\drawing$\Jobs-"+JobYear+"\"+Item.UserProperties("JobNumber")+" "+Item.UserProperties("JobName")

Set objIE = CreateObject("InternetExplorer.Application")
objIE.Navigate("about:blank")
objIE.document.parentwindow.clipboardData.SetData "text", strCopy
objIE.Quit

End Sub

Open in new window


Thanks,
Joel
Avatar of David Johnson, CD
David Johnson, CD
Flag of Canada image

Have you tried this?
a. Open Internet Explorer.
b. Click on Tools.
c. Click on Internet Options.
d. Under Security tab, Click on Internet and then click on Custom level.
e. Scroll down and under Scripting, you will find an option “Allow Programmatic clipboard access”.
f. Under that click on Enable and click OK and again OK.
You should try the htmfile object
Set oHTML = CreateObject("htmlfile")

Open in new window

Using clip maybe an option as well, I don't get any security warnings with that. Can you try:

...
strCopy = "\\TGPS13VM1\drawing$\Jobs-"+JobYear+"\"+Item.UserProperties("JobNumber")+" "+Item.UserProperties("JobName")

Set oExec = WshShell.Exec("clip")
Set oIn = oExec.stdIn
oIn.WriteLine strCopy
oIn.Close
...

Open in new window

Avatar of Genius123

ASKER

Thanks Gerwin.  I get an error.  Could you help further?

Object required: WshShell.
Oops, missed a line copying from my example. Can you try again? The missin CreateObject is added below.

...
strCopy = "\\TGPS13VM1\drawing$\Jobs-"+JobYear+"\"+Item.UserProperties("JobNumber")+" "+Item.UserProperties("JobName")

Set WshShell = CreateObject("WScript.Shell")
Set oExec = WshShell.Exec("clip")
Set oIn = oExec.stdIn
oIn.WriteLine strCopy
oIn.Close
...

Open in new window

Thanks for your help on this.  Now I get this error on this line:

Set oExec = WshShell.Exec("clip")

The system cannot find the specified file.
Hmm, this is a Windows7 machine you are working on, right? I am and clip.exe is in the path. But if it is not, you can do this:

Set oExec = WshShell.Exec("%SYSTEMROOT%\system32\clip.exe")
Yes, I'm on Win 7 64 bit.  I tried that line and it gives me the same error.  Any other ideas?
Strange, I have WIn7 64 bit as well, can you try and find "clip.exe" on a cmd prompt"

cd %SYSTEMROOT%
dir /a /s clip.exe

and post your results?
Here's what I get.  See attached.
Document1.pdf
you might need to run the clip.exe from the syswow64 directory.
ASKER CERTIFIED SOLUTION
Avatar of Gerwin Jansen
Gerwin Jansen
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>> you might need to run the clip.exe from the syswow64 directory.
It is running just fine from %SYSTEMROOT%\system32 for me ;)
I tried both and here's what I get.  See attached.
Document2.pdf
Instead of posting PDF's you can also just paste the text from your CMD prompt ;)

You must not copy the complete text I pasted above, that will not work.

- open a cmd prompt
- type: cd \windows\system32
- type: echo HELLO | clip
- open notepad and paste (ctrl-v) there.

Does that work?
Yes!  That worked.  It also works from the script.  Thanks very much for your help :-)

Just so it's documented, this is the final answer:

Set WshShell = CreateObject("WScript.Shell")
Set oExec = WshShell.Exec("C:\Windows\system32\clip.exe")
Set oIn = oExec.stdIn
oIn.WriteLine "HELLO Genius123"
oIn.Close
Yes!  That worked.  It also works from the script.  Thanks very much for your help :-)
Great, glad we could help you out ;)