-1

I am writing a script to use winzip from powershell but I am having problems clicking the mouse inside the address bar of a dialog box.

I have solved the problem using the 7zip method but I want to learn another method.


(I have 2 screens hence the coordinates of the mouse). I tried making a new shell just for the dialog box but that doesn't work. What am I doing wrong?

UPDATE: When I put the Sleep 1 in front of the click, the computer makes a tone. Am I dealing with a focus issue?

Add-Type -AssemblyName System.Windows.Forms
$screen = [System.Windows.Forms.SystemInformation]::VirtualScreen
$screen | Get-Member -MemberType Property
$Width=$screen.Width
$height=$screen.Height


& "C:\Program Files (x86)\WinZip\WINZIP32.EXE"
$wshell = New-Object -ComObject wscript.shell;
$wshell.AppActivate('Winzip Pro')
Sleep 1
$wshell.SendKeys('% ')
$wshell.SendKeys('x')
$wshell.SendKeys('%')
$wshell.SendKeys('o')
$wshell.SendKeys('p')

[Windows.Forms.Cursor]::Position = "2600,40"
Sleep 1
$wshell.SendKeys( {ClickLeft})

#$Dialog = New-Object -ComObject wscript.shell;
#$Dialog.AppActivate('Zip')
#Sleep 1
#$Dialog.Sendkeys({ClickLeft})
Clint Eastwood
  • 135
  • 1
  • 7
  • 1
    sorry for being so straight about it but whats the point of this? if you want the user to be able to pick the file in a gui you could just use a file dialog and then pass the path to the zip application – Paul Dec 16 '14 at 23:14
  • I have many folders coming in daily with loose pdfs and other files. the pdfs and no other file must be zipped and uploaded somewhere. I have another script that isolates the pdfs and I need to zip them up. After searching for powershell solutions to zipping, I came to the conclusion that faking a user is the solution that I am most capable of implementing. (This is Day2 of my using powershell) – Clint Eastwood Dec 16 '14 at 23:21
  • If I may, I'd suggest it would be far easier to automate the command-line version of, say, 7-Zip, which is more or less designed for the purpose. – Nathan Tuggy Dec 16 '14 at 23:24
  • 1
    Powershell is not really good for ui automation, dont waste your time with it. You can actually give winzip a source path that will limit which files it zips, i will provide a link in a second, here you go: http://stackoverflow.com/questions/18606448/how-to-zip-specific-files-from-a-folder-using-winzip-command-line – Paul Dec 16 '14 at 23:27
  • 2
    Here are several more implementations: http://stackoverflow.com/questions/1153126/how-to-create-a-zip-archive-with-powershell UI automation is not the best place to start with Powershell. If I ever need to automate UI stuff, I turn to AutoHotKey or AutoIT – kevmar Dec 17 '14 at 01:02
  • AutoHotKey and @Paul 's link look interesting and I will have a go at incorporating them tomorrow. Previously I have seen posts and blogs about the command line version of 7-zip, but I was not able to follow them well enough to make progress. This zipping function will connect with several other scripts I made that do not use the gui. For now, I would like to solve the problem using this method before I abandon it. Can you see a resolution to this code? – Clint Eastwood Dec 17 '14 at 01:27
  • 1
    I'm with kevmar on using Powershell for UI. Maybe tell us more about the problem (finding the pdfs and zipping them up) rather than only the solution. Powershell can zip files without winzip. – xXhRQ8sD2L7Z Dec 17 '14 at 06:50
  • Every day a script generates several folders that start with a keyword and end with number. There is a processed folder to put these in after they are uploaded elseqhere. I used Get-ChildItems and filtered out non-folders with the mode and filter out the processed folder using the name. I now have the directory name of each folder that generated. These folders contain PDFs, a single csv, and other things. With gci I can isolate the names of the pdfs and the name of the csv. The pdfs need to be zipped and the zip needs to be named after the csv. – Clint Eastwood Dec 17 '14 at 12:07
  • You can use the zip functions described here: http://stackoverflow.com/questions/1153126/how-to-create-a-zip-archive-with-powershell – xXhRQ8sD2L7Z Dec 18 '14 at 04:31
  • I have seen that page and am also working on getting one of those methods to work. For the purposes of this page, does anyone know how to click the mouse? – Clint Eastwood Dec 18 '14 at 12:14

1 Answers1

0

I figured out how to zip the file using the mouse and not through the 7zip command interface.

The first step was to copy in the function seen in the top answer for this question power shell : how to send middle mouse click?

Whenever I want the mouse to click, I script in Click-MouseButton -button left

in place of left, one can also type in right or middle

Then it is a matter of sending the strings containing paths and names and moving and clicking the mouse.

Community
  • 1
  • 1
Clint Eastwood
  • 135
  • 1
  • 7