Invoking a program which uses GetForegroundWindow() over PSExec returns Idle - psexec

For automation purposes, I need to know the foreground window process running on a remote machine.
I've written small scripts (C#, Python, Powershell) to do this - each of these scripts is using some or the other form of GetForegroundWindow()
These scripts work perfect if I run them on manually the machine.
But when I use PSExec to run these scripts from a remote machine, all of these return process name = Idle
What could have gone wrong?

Related

Run a script to load commands into my main script

I have a powershell file that I have downloaded from ScriptCenter that allows me to control and query virtual desktops on my machine (https://gallery.technet.microsoft.com/scriptcenter/Powershell-commands-to-d0e79cc5).
Using their example, I can run that ps1 file at the start of my script to use those commands that the script creates. All fine here.
The only issue with this is that when I run my script, it asks to confirm to run it. This is something I don't want my script to do.
To work around this, I tried using the "PowerShell" command with "-ExecutionPolicy Bypass" set. This removes the prompt to approve the script, however it stops the script from being loaded into my scripts session as I can't use any of the commands it make available by running it.
How do I either run the script first, without it prompting, or execute the powershell command so that it is run in the session space of my script so that its commands are available?
Thanks

Is it possible to log all powershell commands run on a machine?

We have some .net applications running on a server that run powershell scripts. Is there a setting where we can log every single powershell command run on that machine, without modifying our existing applications? I already tried start-transcript . That command only captures the commands run in the current session.
I believe Microsoft calls what you're after "Over the Shoulder Transcription". It's described here, and will be available in WMF5.

Need to run sikuli script on remote PC using PsExec

I have maintained a sikuli script which runs good for a GUI application on my PC, say PC-A. Also I have PsExec installed on it. My GUI application is installed on PC-B.
What I need to do is, run the sikuli script (on PC-A) to execute for GUI app on (PC-B) using PsExec as mediator, which should pass on my commands at every single line and return the results back to PC-A from GUI application.
SikuliX Script(PC-A) ====== PsExec.exe(PC-A) ======= GUI App(PC-B)
Regards,
Bharath
To run interactively in a specific session of a remote PC you'll need to know the session id on the remote system.
You can then use psexec's -i option to run in that session. From psexec -?
-i Run the program so that it interacts with the desktop of the
specified session on the remote system. If no session is
specified the process runs in the console session.

Launching .exe from PowerShell window SOMETIMES causes it to be run in separate window, so I can't see output or get $lastexitcode

I am by no means a PowerShell expert; I have spent a good while googling this, but haven't found an answer.
The basic idea of my script is to run a Microsoft tool called appcert.exe with command-line arguments. appcert.exe returns 0, 1, or -1; I am checking it with $lastexitcode.
appcert.exe only runs on Windows 7 and Windows 8, so I have run my script on both.
Everything works fine on Windows 7x64 (PS version = 2.0). I can manually run all the same steps. I see the output of appcert.exe in the same PS window.
Different story on Windows 8x64 (RTM), where PS version = 3.0, CLRVersion = 4.0.30319.17929.
Sometimes, appcert.exe runs "inline" (like it did in Win7); other times, a command window is launched, the appcert.exe output flies by, and command window closes. The PS window that called it can't check $lastexitcode (which, by the way, is not set at all).
I tried all PS versions on machine, and results are as follows:
appcert.exe is launched in separate window in these instances:
In PowerGUI 3.2.0.2237 (uses PS 2.0)
In regular PowerShell (non-admin)
In Windows PowerShell ISE (non-admin)
appcert.exe is launched inline in these instances:
Ran Powershell as administrator
Ran ISE as administrator
Behavior above is obtained whether I:
Launch script, which calls the appcert command like this: & $CertToolPath
cd to the home direcotry of the tool and type .\appcert.exe
Run this: Cmd /c appcert.exe
Run this: Invoke-expression –command appcert.exe
Run this: [system.diagnostics.process]::start("appcert.exe")
My colleagues are equally stumped by this.
My machine is in a test domain, not a workgroup. I log into the machine as an admin of the test domain, so theoretically, I'm already an admin.
I install the MS tool as that admin, too. In fact, I never do anything as the machine's local admin. Any ideas? :)
Many thanks in advance,
Tania
Can you repro this with any other exe? Do you have UAC prompts disabled?
Is it possible that appcert.exe requires to be run as Admin, and if not, it automatically re-launches itself as Admin (this should cause a UAC prompt, but if you've turned them off, it would appear to just spawn a new instance automatically)?

How to invoke an opened Exceed window to run a Perl script using a Schedule Task

TASK TO BE ACCOMPLISHED:
To schedule a perl script which is executed on a specific time / day in a week
THINGS I HAVE DONE:
In a schedule Tasks, I have created a new Task by which the Task will call a batch file with below contents
cd "DRIVE\FOLDER\Hummingbird\Connectivity\14.00\Exceed\"
ABCD.xs
cd mDrive/bin
perl baseline.pl -publish -location XXX -email
THINGS NOT WORKING FOR ME / CAUSING THE ISSUE:
Wen I run the scheduler, the prompt opens up the ABCD.xs exceed file window seperately file but the below commands are executed in the command pronpt itself
EXPECTED OUTPUT:
I want the commands
cd mDrive/bin
perl baseline.pl -publish -location XXX -email
to be executed in the exceed window
Any kind of solution wud be great
Thanks in advance.
Haresh
Sounds like you need to start getting into either SendKey stuff (Win32 packages) or else look into writing Exceed/Hummingbird scripts and just executing those.
Some other things to look into... does the remote server have a telnet or ssh server running? Or are there other methods of executing code on the remote server?
For example, my work's mainframe is accessed via a Hummingbird terminal emulator, but I can also telnet to the mainframe and execute commands as well as FTP batch job directly into the JES spool. So when I execute things on the mainframe by way of my PC (Perl scripts, etc.), I don't even fool with Hummingbird.
Good luck...