Solved

Windows Clipboard issue

Posted on 2014-12-19
19
259 Views
Last Modified: 2014-12-22
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
0
Comment
Question by:Genius123
  • 8
  • 7
  • 2
  • +1
19 Comments
 
LVL 79

Expert Comment

by:David Johnson, CD, MVP
ID: 40510432
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.
0
 
LVL 45

Expert Comment

by:aikimark
ID: 40510729
You should try the htmfile object
Set oHTML = CreateObject("htmlfile")

Open in new window

0
 
LVL 37

Expert Comment

by:Gerwin Jansen, EE MVE
ID: 40510766
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

0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

Author Comment

by:Genius123
ID: 40513250
Thanks Gerwin.  I get an error.  Could you help further?

Object required: WshShell.
0
 
LVL 37

Expert Comment

by:Gerwin Jansen, EE MVE
ID: 40513524
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

0
 

Author Comment

by:Genius123
ID: 40513545
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.
0
 
LVL 37

Expert Comment

by:Gerwin Jansen, EE MVE
ID: 40513561
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")
0
 

Author Comment

by:Genius123
ID: 40513572
Yes, I'm on Win 7 64 bit.  I tried that line and it gives me the same error.  Any other ideas?
0
 
LVL 37

Expert Comment

by:Gerwin Jansen, EE MVE
ID: 40513656
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?
0
 

Author Comment

by:Genius123
ID: 40513681
Here's what I get.  See attached.
Document1.pdf
0
 
LVL 45

Expert Comment

by:aikimark
ID: 40513697
you might need to run the clip.exe from the syswow64 directory.
0
 
LVL 37

Accepted Solution

by:
Gerwin Jansen, EE MVE earned 500 total points
ID: 40513701
Looks OK to me (I have the exact same). Maybe some weird path setting.

Can you try and see if clip itself is working:

C:\Windows\system32>echo HELLO | clip

Then paste in some other application, you should paste 'HELLO'.

Then, if that works, try:
Set oExec = WshShell.Exec("C:\Windows\system32\clip.exe") 

Open in new window


Also, try my test script:
Set WshShell = CreateObject("WScript.Shell")
Set oExec = WshShell.Exec("C:\Windows\system32\clip.exe")
Set oIn = oExec.stdIn
oIn.WriteLine "HELLO Genius123"
oIn.Close

Open in new window


Save as somefile.vbs and run it, after which you should be able to past 'Hello Genius123' somewhere.

Tip: you may want to remove some personal info from your pdf writer or Word :)
0
 
LVL 37

Expert Comment

by:Gerwin Jansen, EE MVE
ID: 40513721
>> you might need to run the clip.exe from the syswow64 directory.
It is running just fine from %SYSTEMROOT%\system32 for me ;)
0
 

Author Comment

by:Genius123
ID: 40513856
I tried both and here's what I get.  See attached.
Document2.pdf
0
 
LVL 37

Expert Comment

by:Gerwin Jansen, EE MVE
ID: 40513888
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?
0
 

Author Comment

by:Genius123
ID: 40513917
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
0
 

Author Closing Comment

by:Genius123
ID: 40513920
Yes!  That worked.  It also works from the script.  Thanks very much for your help :-)
0
 
LVL 37

Expert Comment

by:Gerwin Jansen, EE MVE
ID: 40513925
Great, glad we could help you out ;)
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
In this Micro Tutorial viewers will learn how to use Boot Corrector from Paragon Rescue Kit Free to identify and fix the boot problems of Windows 7/8/2012R2 etc. As an example is used Windows 2012R2 which lost its active partition flag (often happen…
This Micro Tutorial will give you a basic overview of Windows DVD Burner through its features and interface. This will be demonstrated using Windows 7 operating system.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question