Genius123
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.
Thanks,
Joel
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
Thanks,
Joel
You should try the htmfile object
Set oHTML = CreateObject("htmlfile")
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
...
ASKER
Thanks Gerwin. I get an error. Could you help further?
Object required: WshShell.
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
...
ASKER
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.
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" )
Set oExec = WshShell.Exec("%SYSTEMROOT
ASKER
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?
cd %SYSTEMROOT%
dir /a /s clip.exe
and post your results?
ASKER
Here's what I get. See attached.
Document1.pdf
Document1.pdf
you might need to run the clip.exe from the syswow64 directory.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>> you might need to run the clip.exe from the syswow64 directory.
It is running just fine from %SYSTEMROOT%\system32 for me ;)
It is running just fine from %SYSTEMROOT%\system32 for me ;)
ASKER
I tried both and here's what I get. See attached.
Document2.pdf
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?
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?
ASKER
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.Shel l")
Set oExec = WshShell.Exec("C:\Windows\ system32\c lip.exe")
Set oIn = oExec.stdIn
oIn.WriteLine "HELLO Genius123"
oIn.Close
Just so it's documented, this is the final answer:
Set WshShell = CreateObject("WScript.Shel
Set oExec = WshShell.Exec("C:\Windows\
Set oIn = oExec.stdIn
oIn.WriteLine "HELLO Genius123"
oIn.Close
ASKER
Yes! That worked. It also works from the script. Thanks very much for your help :-)
Great, glad we could help you out ;)
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.