Solved

Windows Clipboard issue

Posted on 2014-12-19
19
245 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 78

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
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
 

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
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
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
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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 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
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
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
ID: 40513925
Great, glad we could help you out ;)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Article by: Lee
Windows 7 Ultimate and Enterprise (and 2008 R2) introduced a new feature you may not be aware of - Boot from VHD.   Boot from VHD (or what Microsoft refers to asNative Boot allows you to install Windows to a VHD (Virtual Hard Disk) file that is t…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
This Micro Tutorial will teach you how to the overview of Microsoft Security Essentials. This is a free anti-virus software that guards your PC against viruses, spyware, worms, and other malicious software. This will be demonstrated using Windows…
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now