Sendkeys On Disconnected RDP Session - vb.net

I have a VB application which is scheduled. It focuses on some cmd windows and performs sendkey actions. This works fine when I have the RDP session open, it's only when I disconnect (not logoff) that the issue occurs. (This task is running on a virtualised server).
When I open the RDP session again after the task has ran, the application has thrown an error regarding the login permissions. I presume this is because the user is locked and therefore can't perform the actions?
I need to find a way around this, any help is much appreciated!

Don't use SendKeys.
Instead, if you have a program running in a command prompt, make sure the VB.NET program is the one to open it (or them) with Process.Start, and set the RedirectStandardInput property of the ProcessStartInfo object you pass to True. Then pass commands into the process's StandardInput property as though writing to a file.
This will avoid any focus-change problems, any problems to do with locked screen sessions, most if not all potential problems with integrity levels, most if not all problems with timing, and probably some other stuff I'm not thinking of.

Related

Access VBA: Shell command broken in one particular database

I have two Access databases that I'm opening on the same computer. In one, running this in the immediate window works as expected (opens Notepad):
Shell "notepad.exe"
In the other, I get this error instead:
Run-time error '5': Invalid procedure call or argument
I have not been able to come up with any shell command that will run successfully in that second database. No matter what, I get that error.
What is going on here? Could there be a security setting coming into play? Or perhaps one is an older version?
Edit - More Info
When I go to the definition of Shell in the malfunctioning database, it goes to VBA.Interaction.Shell.
I get the correct IntelliSense tooltip for Shell.
I tried VBA.Shell "notepad.exe" and VBA.Interaction.Shell "notepad.exe" without success (same error).
Here are the references that are checked in both databases:
Decompiling did not help.
The culprit was our anti-virus software! UGH!
Why did it work in one database and not the other then? I'm told that years ago, anti-virus exceptions were made for my computer for the one database but not the other.
I recommend that any others who encounter this problem check their anti-virus logs/policies. Also, running the database from another computer with different policies in place might shed some light on the issue faster. In this case, when I used remote desktop to log into a server, I was able to call shell successfully.

Program recognizes a copy of itself in the operating system

I'm trying to create a piece of software that will not be susceptible to bots. Is there a way for me to code into a program a way to check in the operating system for a process just like it and then put in a shutdown mechanism if it is recognized. Think of something like netflix where if one tab in chrome is running netflix, a second tab being opened will display an "oops" message. Is there anything like this for something that does not run on a web browser? What should I be looking into?
Thanks in advance
There can be plenty of solutions; the first coming into my mind are:
1) your program checks for existence of a particular file; if the files is not found then the program continue, otherwise your programs know that another instance is running and thus can terminate immediately. If the file is not found, your program creates it and then delete it before exting.
2) you can use an operating system call or an o.s. utility program to know if another instance of your program is running (e.g.: in linux, the command ps)
have fun

How to close/stop a .NET application and re-execute it?

My application updates(running a vba script) an excel shared workbook, and since it is shared, there shouldn't be problems when someone else is using the same file at the same time. But for some reason, sometimes it simply freezes, without any error message, just freezes.
Is there a way to programatically make the application stops/closes automatically when frozen or after some minutes(In normal conditions, this updating process shouldn't take more than 1 minute)?
And, if possible, re-launch the app again automatically after some minutes for at least 5 attempts?
This way would ensure process completes succesfully.
I have had to do this same thing before but because I had an application that would look for updates to it's self on the network and then update it locally. Problem is, you cannot update the exe that is running.
What I did to get around it is to create another program that would wait a second, update the exe, then run the exe again.
Because I did this with a few different apps, I made my "Updater" generic so I could send some command line parameters and it would use those to copy and run.
If you want to try something else, you might be able to accomplish this same thing by creating a BAT file and running it. I'm not real good on BAT files so I can't help you there. But, it is another way to handle it.

How to override edit locks

I'm writing a WLST script to deploy some WAR's and an EAR. However, intermittently, the script will time out because it can't seem to get an edit lock (this script is part of a chain of many other scripts). I was wondering, is there a way to override or stop any current locks on the server? This is only a temporary solution, but in the interest of time, it will do for now.
Thanks.
You could try setting a wait period and timeout:
startEdit([waitTimeInMillis], [timeoutInMillis], [exclusive]).
Are other scripts erroring out, leaving the session locked? You could try adding exception handling around those. Also, if you have 'Automatically acquire lock" enabled in the Admin Console and you use the admin console sometimes it can cause problems if you are running scripts at the same time, even though you are not making "lock-requiring" changes.
Also, are you using the same user for the chained scripts?
Within WLST, you can pass a number as a parameter to gain an exclusive lock. This allows the script to grab a different lock than the regular one that's used whenever an administrator locks from the console. It also prevents two instances of the same script from stepping on each other.
However, this creates complex change merge scenarios that are best avoided (by processes).
Oracle's documentation on configuration locks can be found here.
Alternatively, if you want the script to temporarily relieve any existing locks regardless of the pending changes, you may as well disable change management from the console, minimizing the inconvenience caused.
WLST also contains the cancelEdit command that you could run before you startEdit. Hope one of these options pan out!
To take the configuration change lock from another administrator:
If another administrator already has the configuration lock, the following message appears: Another user already owns the lock. You will need to either wait for the lock to be released, or take the lock.
Locate the Change Center in the upper left corner of the
Administration Console.
Click Take Lock & Edit.
Make your configuration changes.
In the Change Center, click Activate Changes. Not all changes take
effect immediately. Some require a restart (see Use the Change
Center).
As long as you're running WLST as an administrative user, you should be able to jump into an existing edit session with the edit() command - I've done a quick test with two admin users, one in the Admin Console, and one using WLST, and it appears to work fine - I can see the changes in the Admin Console session inside the WLST interpreter.
You could put a very simple exception handler around your calls to startEdit that will log the exception's stack trace, but do nothing else. And then rely on the edit call to pop you into the change session.
Relying on that is going to be tricky though if another script has started an edit session and is expecting to be able to commit that change session itself - you'll be getting exceptions and unreliable behaviour across multiple invocations.

How to get information about what code is running in a thread?

I have a Window Forms application (using clickonce installation, running on a terminal server) that occasionaly ends up with a thread that appears to be running in a tight loop. The user doesn't know this happens as the app continues to run as expected. Also I have determined that I can kill the problem thread without any apparent affect on the app.
I can use Process Explorer to find the instance of an app with the problem and can isolate the thread with the problem but haven't found any way to look into the thread to find anything that would help me determine what is causing the problem. Does anyone know of a way to some additional information about a thread, like maybe strings, that would help me zero in on the issue?
Thanks,
Dave
Haven't tried this myself but "Process Monitor" claims it "shows real-time file system, Registry and process/thread activity"
http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx
Hope this helps.
You should be able to attach Visual Studio to the running process to get more information. Provided the .pdb files are included with the application and you have source code for the avialable version you should be able to use the Threads window combined with pausing / stepping through to see just what the code is doing.