AtinK Posted November 7, 2013 Report Share Posted November 7, 2013 Hi Guys, Just signed up, hoping someone would be able to help me out! I'm trying to use macro express to shutdown a program, launch it again, enter in a username-password and hit enter. My problem is that even though the program shutdowns and restarts- none of the text entries (username and password) work. When I log back in to the workstation in morning the program is open and waiting for the username and password to be entered. The macro works perfectly when I test run it while logged into the system. Below is the macro. Any help would be appreciated. Thanks AtinK <IF PROGRAM Option="\x01" Program="XYZ"/><TERMINATE PROCESS Window="FALSE" Name="XYZ" Partial="TRUE" Wildcards="TRUE" Timeout="1000"/><END IF/><DELAY Flags="\x01" Time="5"/><LAUNCH PROGRAM AND ACTIVATE WINDOW Title="XYZ" Exact_Match="FALSE" Wildcards="FALSE" Path="C:\\Program Files\\XYZ.exe" Mode="\x00" Default_Path="TRUE" Wait="1" Wait_For_Program="12"/><IF NOT PROGRAM Option="\x00" Program="XYZ.EXE"/><WINDOW ACTIVATE Title="XYZ" Exact_Match="FALSE" Wildcards="FALSE" _IGNORE="0x0006"/><END IF/><WINDOW ACTIVATE Title="XYZ" Exact_Match="FALSE" Wildcards="FALSE"/><DELAY Flags="\x01" Time="3"/><TEXT TYPE Action="0" Control="%C[1]%" Text="username" _PROMPT="0x0004"/><DELAY Flags="\x01" Time="2"/><TEXT TYPE Action="0" Text="<TAB>"/><DELAY Flags="\x01" Time="2"/><TEXT TYPE Action="0" Text="password"/><DELAY Flags="\x01" Time="2"/> Quote Link to comment Share on other sites More sharing options...
Cory Posted November 8, 2013 Report Share Posted November 8, 2013 Looking at your code now. Some random thoughts. You should use the code tags here in the forum. Checkout the button <>. Also it's nice to have both the code as you have but also right click and opt to copy command text a paste than in another code box. Easier for us to follow. You should recommend cleaning up your code. You can put multiple Text Type keystrokes in the dialog. IE instead of 3 commands make 1 with <space><tab><space>. And what's with noting more than a space? EG line 2. Doesn't seem necessary. I'd start by eliminating them. You don't have to test if the program is focused. If it's not it will just refocus the window. Why do you activate the window twice? Once in the condition. Why the big 2 second delays? It seems all of those lines could be distilled to 3 lines. Terminate, Launch and activate, and one texttype with name, tab, and password. Why does that not work. Sorry, I'd make an example but this stupid form will not let me paste anymore. The superfluous space TextTypes would be my first suspicion. After that I'd want to verify that under normal circumstances the program's user name field is focused. You might need to focus it first.It's a little bit of an advanced technique but if it were me I'd use controls and send the text to controls. Maybe it's too soon for that but you should eventually try to do it that way. We can help you learn that if you're interested. Quote Link to comment Share on other sites More sharing options...
Cory Posted November 8, 2013 Report Share Posted November 8, 2013 Oh, I'm sorry. I just realized the title of your post. If the workstation is locked no GUI activities will work. And it's not MEP's fault. It's because, well, in a sense they do not exist. Or more accurately are in a suspended state. IE you can't do any user input kind of things while the workstation is locked like moving the mouse, clicking, or typing. Quote Link to comment Share on other sites More sharing options...
AtinK Posted November 8, 2013 Author Report Share Posted November 8, 2013 Thanks for the prompt response Cory! I'll clean up the code but is there a way to unlock workstation and run macro? Cheers Quote Link to comment Share on other sites More sharing options...
Cory Posted November 8, 2013 Report Share Posted November 8, 2013 Not that I'm aware of. That's part of the whole point. It's a security measure. It needs a CTRL+ALT+DEL and credentials assuming you're on a Domain. They don't want software to be able to do this or it would be a huge security vulnerability. Disconnected Remote Desktop session are the same way. Quote Link to comment Share on other sites More sharing options...
paul Posted November 8, 2013 Report Share Posted November 8, 2013 is there a way to unlock workstation and run macro? Yes, but it's a little complicated! Here is a summary of the steps needed. If you're interested in the detail, please let me know. - Run a (I suggest password-protected to prevent others looking at the code) macro (scheduled to run at a specific time) to: - - place the machine in a state where it won't ask for a password when restarting (write values to the registry) - - reboot - Using a utility you can download for free, restart the machine and have MEP start a tailored startup macro to: - - reset the machine state to asking for a password - - run the macro you describe above to close and relaunch your app and enter a userid and password Your special startup macro can be run when the relevant registry value you wrote exists. - Quote Link to comment Share on other sites More sharing options...
Samrae Posted November 8, 2013 Report Share Posted November 8, 2013 AtinK: You could use the Windows Task Scheduler to run a macro. When you define a task in the scheduler you can specify that it needs to log in to perform the task. For the process you can either specifiy the Macro Express Player (macexp.exe) or the smaller launcher (meproc.exe) and use a parameter that looks something like "/AYourMacro".Cory: After reading your critique of AtinK's macro I decided to look at it. For anyone else interested, here it is in human readable form: If Program "XYZ" is running Terminate Process: XYZ End If Delay: 5 seconds Launch Program and Activate Window: Program "XYZ.exe", Parameters "", Window "XYZ" If Not Program "XYZ.EXE" is focused Window Activate: XYZ End If Window Activate: XYZ Delay: 3 seconds Text Type (Simulate Keystrokes): username Delay: 2 seconds Text Type (Simulate Keystrokes): <TAB> Delay: 2 seconds Text Type (Simulate Keystrokes): password Delay: 2 seconds Cory, I rarely disagree with your analysis but in this case ... AtinK, The only change I would make is to remove the second "Window Activate" command. That one IS unnecessary. The remainder of the macro I would leave as is until I was certain that it worked. This macro looks just like how I would write it before optimization. Once the macro is working you can either reduce the amount of delay or combine "Text Type" commands. For the record, this: If Not Program "XYZ.EXE" is focused Window Activate: XYZ End If is a published trick to speed up your macro. The "Window Activate" command takes a relatively long time to perform. By checking you can you can avoid the Window Activate command if the window is already focused. Quote Link to comment Share on other sites More sharing options...
terrypin Posted November 10, 2013 Report Share Posted November 10, 2013 For the record, this: If Not Program "XYZ.EXE" is focused Window Activate: XYZEnd Ifis a published trick to speed up your macro. The "Window Activate" command takes a relatively long time to perform. By checking you can you can avoid the Window Activate command if the window is already focused.Thanks, never knew that. Could explain some slow performing macros of mine. It does seem surprising though. Do I have it right. Are you saying that the Window Activate command takes a significant time to determine whether the target window is active? IOW, significantly longer than that 3-line substitute? BTW, I'd say that the most frequent flaw in my macros appear related to Window Activate and Wait for Window. Often I have to replace them with simple longish delays. Terry, East Grinstead, UK Quote Link to comment Share on other sites More sharing options...
Samrae Posted November 12, 2013 Report Share Posted November 12, 2013 Yes, 'Window Activate' takes much longer than 'If Not Program "XYZ.EXE" is focused'. I cannot remember where I read it but it was some time ago. I added it to some of my macros and saw a noticeable improvement in speed. Quote Link to comment Share on other sites More sharing options...
Cory Posted November 12, 2013 Report Share Posted November 12, 2013 Periodically we find performance benefits by using different techniques as in this case. If someone was interested I'd be happy to create an archive of user contributed examples on my webpage. I was thinking of doing exactly this a while back to demonstrate the speed benefit of a binary search given how slowly MEP loops thru arrays. If anyone is ever interested let me know as I'd be happy to host and collaborate. Quote Link to comment Share on other sites More sharing options...
AtinK Posted November 17, 2013 Author Report Share Posted November 17, 2013 Thanks guys for responses. Just to let you know I purchased an auto login tool that logs me in just before the macro is scheduled to run. But no luck. Any suggestions? Cheers Quote Link to comment Share on other sites More sharing options...
paul Posted November 18, 2013 Report Share Posted November 18, 2013 Thanks guys for responses. Just to let you know I purchased an auto login tool that logs me in just before the macro is scheduled to run. But no luck. Any suggestions? Cheers I did outline a solution above - it's up to you to request details if you're interested. Quote Link to comment Share on other sites More sharing options...
AtinK Posted November 18, 2013 Author Report Share Posted November 18, 2013 Thanks Paul. The auto log on tool logs me into windows successfully. After the login, I've scheduled a task (windows scheduled tasks) to restart MEP. The macro activation method I've used is 'Process Event' - When process starts running (MACEXP.EXE). But the macro doesn't run. How do I get it to be a "special start up macro" as you suggested? Thanks again for you help with this! Quote Link to comment Share on other sites More sharing options...
paul Posted November 18, 2013 Report Share Posted November 18, 2013 How do I get it to be a "special start up macro" as you suggested? Thanks again for you help with this! Schedule it to run when MEP starts - and you'll need to be able to distinguish between normal mode, and the special mode created by your auto log on tool, so that you run your desired macro only in this special mode. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.