Send key not working for custom application in Auto It - automation

I want to open my application myprogram.exe and hit tab. I have written the following script
Local $Pid = ShellExecute("C:\Program Files\myProgram.exe","-a arg","","")
Sleep(5000)
Send("{TAB}")
But it doesn't work. My application gets open and it works if I manually hit TAB. But it's not accepting any key via the script.
I tried the same thing with notepad and it works without any problem
Local $Pid = ShellExecute("notepad.exe","","","")
Sleep(5000)
Send("{TAB}")

Be sure that the window has focus with WinActivate
Also as suggested try controlsend or controlclick, if ether of those doesn't work it is properly because the program you are trying to access doesn't take simulated inputs

Related

How can i keep focus on my own application or regain it when lost in delphi? [duplicate]

I need to create a simple Delphi application, kiosk style.
It is a very simple thing, a single form where the user writes some personal info to register to an event. 4 TEdit and a TButton.
What I want to achieve is to avoid the user does any action different then typing in TEdit or clicking on the TButton. For example I don't want he does ALT TAB (switchin applications), pressing windows key on keyboard, doing ctrl-alt-canc, etc...
I can add a passowrd protected Button that enables/disables this "Kiosk mode", in this way as I need to exit the kiosk mode I simply press that button and exit.
How to achieve this "kiosk mode" in Delphi without intercepting all the keystrokes manually? Or did anyone already develop this so it can be shared?
I think you'd better create a new desktop, and run your app in there. When your app is done, you can bring back user's desktop. That is how Windows login screen works. Of course Windows login screen uses a special secure desktop. Your app in a separate desktop would be isolated. You will have a desktop background with no start menu, taskbar, or desktop icons because explorer.exe is not running there automatically. Of course a can start a new process, using Task Manager, but desktops in Windows are securable objects; therefore, you can make restrictions if you want. Of course if your app has sufficient permissions.
To create a new desktop, you can use CreateDesktop Windows API, and to switch to the newly created desktop, you can use OpenDesktop function.
You can try Change the Windows Shell.
When you start windows, you don't execute the default shell (explorer.exe), you can execute your application.
Al internet you can find alternative Shell (more attractive) to default windows like:
BlueBox or
SharpE
This option is used for purposes similars at the application that you are developing. Kiosks or TPV.
For change the default applicacion you must modify a registry key:
In Win3.x and Win9x, SYSTEM.INI file:
[boot]
shell=MiAplicacion.exe
In Win2k and WinXP, use Registry:
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon]
Shell=MiAplicacion.exe
If you test this option, think the mode to turn the configuration to the original value (button or option). You must reboot to test changes.
ADDED: In addition, if you search on the web some similar at this "Delphi Change default windows shell", you can find more code, samples and information about this.
Regards
P.D: Excuse me for mistakes with english.
Well but if someone can open the taskmgr he could just create a new task and run explorer.exe from there so its not really secure though...
Ok Taskmgr can be stopped with policies...
Well and for disabling the cad sequence you can use saslibex which Remko Weijnen had created you can find it here: SASLibEx
kindest regrads,
s!

How to schedule a .vbs script with UI elements?

I am new to vb scripting. I need to schedule a windows task which can run a vbs file.
The script opens up a application from its shortcut, feeds username and password and performs login.
In other words, I need to automate the restart process.
The scripts runs as expected when opened manually but scheduler cannot not run it.
I think the problem is with those UI elements(used for login).
Please suggest how to get through it.
Thank you!
AppActivate does not itself restore the window if it is for some reason minimized.
You can try to find the reason why it's minimized (maybe it has something to do with the batch calling the vbs calling the application, I cannot really say) or you can try a little hack in the vbscript like the following:
After the AppActivate do a:
oShell.SendKeys "% r"
This is equivalent of Alt+SpaceBar, r so it opens the windows dialog for Maximize, Minimize, Restore options and choses "Restore".
Note that this might only be r on english copies of windows. If you use another Language manually open that menu by pressing Alt+SpaceBar and looking what the actual hotkey on your system is (it would be underlined in the dialog). Afterwards replace the r in the script with whatever hotkey is used in your language.

Autoit script not working

I have an AutoIt script that works.
I need to update the script to open an application and to press some buttons in some windows.
The only thing that works is running the application: RunWait(exe file).
When the application is running I need to click an OK button on the window that pops up and then click another button on the next windows but all of that is not working.
RunWait(exe file)
WinWaitActive("win title","",10)
ControlCommand("win title","",1,"check","")
This is the part that is not working.
First of,
Dot use RunWait() , instead use Run().
RunWait will wait until the application is closed.
Use AutoItWindowInfo tool in order to find the info on the control you want to manipulate.
Example:
ControlClick("[CLASS:Notepad]", "", "[CLASS:Edit; INSTANCE:1]")
Also use
Opt("WinSearchChildren", 1) ;0=no, 1=search children also
This will make sure your script can see the child windows.

Ribbon script is running correctly always but on first try

I have created a custom Close Opportunity script which is complete replica of CRM's default opps.js with exception that it has couple lines of code that I've wrote. I replaced default Close Opportunity ribbon buttons with my own and made everything work as it should work. There's one little problem I can't understand though.
I'm using VPN and remote desktop connection when I'm developing in this particular case. Everytime I open VPN and connect to the remote desktop, then open CRM and then click my Close Opportunity ribbon button my script wont work. Opportunity is closed correctly, but my custom logic is not run. If I reactivate the opportunity and close it again or in addition close another opportunity everything works just fine. I can't repeat this problem in any other way than just closing remote desktop and disconnecting VPN and then connecting again.
But that should not have nothing to do with how CRM works right? Or is there some cache or something I'm not aware of but which could cause this problem? Anyway, I'm keeping myself busy with this but any advices are welcome.
Edit: And I have tried to clear Internet Explorer's cache etc.
Can we see an example of the code?
Also when calling a webresource from the ribbon remember to reference using "$"
Example $webresource:SomeScript.js

How do you run another .exe from VB.NET as another User?

How do you run another .exe from VB.NET but as another User?
I expect to launch a .exe like "Left Click -> Run As -> Enter User/Pass -> Click OK"
If I do that, my application runs as expected (I need to run it as another user to get access to some folders in the network)
But if I use this in VB.NET
System.Diagnostics.Process.Start(System.Windows.Forms.Application.ExecutablePath, PARAMETER, USER, PASSWORD, DOMAIN)
The application runs with the other user.. but Excel (inside my App with Interop) fails to open the file in the restricted folder.
(I run again the same app but with a different user, just to avoid creating more .exe files... but I already tried with vbScript)
Again, Process.Start FAILS to open excel using the other User... but Left Click -> Run as succedes at that... why?? another way??
this is what the app does:
Open the app
check if there's a parameter
if no parameter, then relaunch the application with the other user and send some parameter
if there is a parameter open excel
open a xlsx file
but if I double click... Excel opens... uses 50% CPU, and gives me the error that it can't open the file...
if I run it directly with the desired user and pass... everything executes fine
Any suggestions as how to solve this? (impersonate works fine.. but it opens Excel with the actual user.. not the one with rights)
Thanks!
If you get "Handle is invalid" error, you should try something like this:
dim info As New ProcessStartInfo("...")
info.UseShellExecute = False
info.RedirectStandardInput = True //This is the key
info.RedirectStandardError = True //This is the key
info.RedirectStandardOutput = True //This is the key
info.UserName = "username"
info.Password = "password"
Using (install As Process = Process.Start(info))
Dim output As String = install.StandardOutput.ReadToEnd()
install.WaitForExit()
End Using
Specifying any one of
RedirectStandardOutput=true, RedirectStandardError=true, or RedirectStandardInput=true
causes the process to be launched with STARTF_USESTDHANDLES. If your process does not have any of these handles, then CreateProcessWithLogon will fail with "Invalid Handle".
You MUST redirect it (even if you don't intend to write anything to it).
Regards
This is really interesting. By default, I believe the Excel COM components are set up to run as the Interactive User (ie the user logged into the box). If they are configured to run as the Launching User then impersonation should work. Of course, this does not explain why "Run As..." works (I don't know the mechanics of that so perhaps it's not impersonation).
One idea is to restructure the application to copy the files to a location Excel can access, manipulate them, and then copy the back.