I'm stuck because my macro seems to be also...

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
tbrahmer
Newbie
Posts: 15
Joined: Thu May 06, 2010 10:14 pm

I'm stuck because my macro seems to be also...

Post by tbrahmer » Thu May 06, 2010 10:33 pm

Hello,
I'm trying to write a macro that will disconnect a network share that is incorrect. Once I select the drive to disconnect and hit the OK button my script just hangs there and I can't seem to hook into the message box that comes up. The message box is titled 'Disconnect Network Drive' and the text inside says 'There are currently files or folders open on H: ...blah blah ... Do you want to disconnect this network drive anyway?'

Doing this manually is fine (no harm done) and I can click on the message box 'Yes' button or press enter - works fine. However, the macro seems to hang as soon as I press the 'OK' button on the initial disconnect window.

Here is the code:

Code: Select all

    Run>RUNDLL32 SHELL32.DLL,SHHelpShortcuts_RunDLL Disconnect
    WaitWindowOpen>Disconnect Network Drives
    Wait>.1
    SetFocus>Disconnect Network Drives
    Sen>h
    Wait>.2
    PushButton>Disconnect Network Drives,OK
    Wait>.2
    MessageModal>This message is not getting hit...
After hitting the 'OK' button the warning message comes up and I can't seem to hook into it, it is like the script stops at that point.

Thanks for any help.

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Thu May 06, 2010 10:49 pm

Wondering if you can just use NET USE \\RESOURCENAME /DELETE ? May only work for some connections like mapped drives, printers, etc.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

User avatar
JRL
Automation Wizard
Posts: 3531
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Thu May 06, 2010 10:50 pm

Your code is probably stopping at "Run>RUNDLL32 SHELL32.DLL,SHHelpShortcuts_RunDLL Disconnect"

Run> is by default a modal function. In other words the script stops until the function has finished and it hasn't finished until buttons are pressed in windows that have opened and since the script has stopped, it can't be used to press those buttons. Try adding a line at teh top of your script that says:

Let>RP_WAIT=0

This tells Macro Scheduler to let the Run> function be non-modal.

User avatar
JRL
Automation Wizard
Posts: 3531
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Thu May 06, 2010 11:52 pm

Ok... now that I've actually tried your code (I need to stop posting before testing) I find that it works flawlessly for me. So I have no idea why it is failing for you. Maybe add another setfocus before teh pushbutton> line?

tbrahmer
Newbie
Posts: 15
Joined: Thu May 06, 2010 10:14 pm

Post by tbrahmer » Fri May 07, 2010 2:18 pm

Thanks, I've tried the RP_WAIT=0 and it's still not working. On my machine, immediately after hitting the OK button to disconnect I get a message opening:

Image

Then the macro stops at this message and I can't seem to hook into the message or find it, anything. The messagemodal won't display until I manually close the message window. Try opening a cmd prompt and browsing to your share before you try to disconnect. Leave the cmd window open that is connected to the share while running the macro and see if you get the same error.

Bob - the net send command won't work because of the same issue. Try opening two command prompts. In one, browse to the share and do a directory listing. In the other, try to disconnect the share (using net send /delete) while both windows are open. I think you'll get an error.

Disconnecting through the GUI interface will work - you can force the disconnection - but my script still sticks when the above message appears.

Thanks for any help.

User avatar
JRL
Automation Wizard
Posts: 3531
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Fri May 07, 2010 2:49 pm

Try this:

Edit: Added a second OnEvent to shut down the killWindow script when the "Disconnect NetWork Drive" window does NOT pop up.

Edit2: Fixed the FILE_NOTEXISTS onevent line. It was not writing the file name to check to the script file.

Code: Select all

Let>file1=%temp_dir%killWindow.scp
WriteLn>file1,wres,OnEvent>WINDOW_OPEN,Disconnect Network Drive,2,Close
WriteLn>file1,wres,OnEvent>FILE_NOTEXISTS,%file1%,0,Quit

WriteLn>file1,wres,SRT>Quit
WriteLn>file1,wres,  Exit>0
WriteLn>file1,wres,END>Quit

WriteLn>file1,wres,SRT>Close
WriteLn>file1,wres,  SetFocus>Disconnect Network Drive
WriteLn>file1,wres,  Wait>0.5
WriteLn>file1,wres,  Send>y
WriteLn>file1,wres,  Exit>0
WriteLn>file1,wres,END>Close

WriteLn>file1,wres,Label>Loop
WriteLn>file1,wres,Wait>0.01
WriteLn>file1,wres,Goto>Loop

ExecuteFile>file1





    Run>RUNDLL32 SHELL32.DLL,SHHelpShortcuts_RunDLL Disconnect
    WaitWindowOpen>Disconnect Network Drives
    Wait>.1
    SetFocus>Disconnect Network Drives
    Sen>h
    Wait>.2
    PushButton>Disconnect Network Drives,OK

    DeleteFile>file1

    MessageModal>This message is not getting hit...
Last edited by JRL on Fri May 07, 2010 3:22 pm, edited 2 times in total.

tbrahmer
Newbie
Posts: 15
Joined: Thu May 06, 2010 10:14 pm

Post by tbrahmer » Fri May 07, 2010 3:05 pm

Thank you so much JRL - works perfectly.

Brilliant... a 'sub' macro that sits there and waits for the message to appear, clears it, stops running, and deletes itself.

Any idea what is so special about the message window that comes up? What is different about that message so that I can't hook into it with the original script? Are there other messages like these in other apps that can halt a macro? I guess I've never seen something like this before.

Thanks again for your help!

User avatar
JRL
Automation Wizard
Posts: 3531
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Fri May 07, 2010 3:08 pm

Are there other messages like these in other apps that can halt a macro?
Don't know but it definitely stops the macro and it stops it at a point where there is no reason for the script to stop.

Be sure to redownload the above script. I added another OnEvent to the "sub" script.

gdyvig
Automation Wizard
Posts: 447
Joined: Fri Jun 27, 2008 7:57 pm
Location: Seattle, WA

Post by gdyvig » Fri May 07, 2010 4:49 pm

Are there 2 windows?
Disconnect Network Drive
Disconnect Network Drives

Is the WaitWindowOpen on the wrong one?

I'm on XP, when I disconnect the message text is similar but the message title is "Windows".

Gale

User avatar
JRL
Automation Wizard
Posts: 3531
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Fri May 07, 2010 5:51 pm

Are there 2 windows?
Disconnect Network Drive
Disconnect Network Drives
Is the WaitWindowOpen on the wrong one?
When the Disconnect program runs, a window named "Disconnect Network Drives" pops up. The WaitWindowOpen> is waiting for THAT window. The script then sends an "h" to the "Disconnect Network Drives" window. If the H:\ drive has an open file or is otherwise busy, almost immediately a window named "Disconnect Network Drive" (sans the "s") opens. It is at this point that the script stops functioning.

My first attempt at making Macro Scheduler close the "Disconnect Network Drive" window was to place a loop immediately following the Send>h line so that there was no "Wait" statement to interfere with an OnEvent. And I had an OnEvent set up to close the window when it opened. This did not work.
I'm on XP, when I disconnect the message text is similar but the message title is "Windows"
I'm also running Windows XP and I see window titles:

1 - Disconnect Network Drives
2 - Disconnect Network Drive

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts