VB6 not responding in windows server 2016 - vb6

We have a set of applications written in VB6 running on a Windows 2003 server . X connects to a DB and writes some files. Y reads those and then writes the input files for Z.
We have a .bat which launches apps X, Y and Z. When X finishes it then launches Y and so on. They are independent but run in sequence.
We used a tool CPAU (starting process with runas ) to launch these applications with the login of the user.
The .bat file works like this :
cpau.exe -u user -p pass -profile -wait -ex "d:\recette\X.exe
cpau.exe -u user -p pass -profile -wait -ex "d:\recette\Y.exe
cpau.exe -u user -p pass -profile -wait -ex "d:\recette\Z.exe
It worked fine until we moved them into Windows 2016.
The problem: X,Y and Z are randomly not responding. They take 0% CPU and sit idle forever.
Once the problem happens, all the apps launched by the .bat don't respond. That means if Y isn't responding, and I kill Y by taskmanager, Z which is launched next by the .bat and doesn't respond either.
However, when I start the app Z by myself, it can run normally.
I installed the Visual C++ Runtime 2008, 2010, 2012,2013 and 2015 (x84 and x64 for all of them) and 2017(x86).
Does anyone have an idea why these apps are freezing randomly?

Related

Window opened via psexec is blank when using PowerShell Direct, but is OK when psexec starts locally

I am trying to build a simple environment to take screenshots automatically. I have several Hyper-V VMs and I need to use PowerShell Direct to run commands on them in a special sequence. When I run psexec to open notepad.exe via PowerShell Direct, Notepad's window opens, but it is blank. I can blindly click controls on the window (e.g., on the toolbar) and it appears that they work, but nothing is actually displayed besides a blank window.
The only simple option to open Windows in an existing session I see now is to run psexec (any other suggestions would be greatly appreciated because my attempts to stick to PowerShell-only approach hits a roadblock, see Starting a GUI application on a guest VM with PowerShell Direct).
I run psexec on one of the virtual machines to start notepad.exe in session 2. This PowerShell snippet runs on a host VM, it contacts guest VM via PowerShell Direct.
Invoke-Command -VMName 'client1.example.com' -Credential $credential -ScriptBlock {
C:\bin\psexec.exe \\client1.example.com -i 2 "notepad.exe"
}
notepad.exe starts, but the window is blank. Is this a bug in psexec?
Please see the screenshot:
The problem does not occur when I run psexec directly in a guest VM.
C:\bin\psexec.exe \\client1.example.com -i 2 "notepad.exe"
Solved by adding the -s option. I don't understand why the problem occurs in the first place and how running it "in the system account" helps.
-s Run the remote process in the System account.
The problem does not occur when I start explorer.exe, BTW.

Resizing a PowerShell window on a remote computer using a batch file

Wondering if anyone knows how to/if it is even possible to resize a PowerShell windows that I open on a remote computer using the batch file I used to run it.
1 #ECHO OFF
2 title Remote Start ProgramName Server
3 cd "C:\IT\FOLDER"
4
5 #ECHO OFF
6 SET /p _computer=Computer Name:
7
8 #ECHO "Launching Program Server On Remote PC %_computer%"
9
10 start PowerShell.exe .\psexec -i \\%_computer% '"C:\Program Files\ProgramFolder\programserver.exe"'
11
12 #ECHO "Launching ClientSideProgram on Local Machine"
13 start "" "C:\Program Files\ProgramFolder\programclient.exe"
14
15 PAUSE
16
17 start "" PowerShell.exe .\pskill \\%_computer% programserver.exe
18 ECHO "Program Server Terminated"
19
20 PAUSE
So as far as I have tested this, it works, but when I do start PowerShell.exe on line 10, it, as expected opens a powershell. THIS is the powershell I would like to resize to the smallest possible size, so that it's not as big of a nuisance when it opens.
Thanks in advance for whatever help anyone has
Edit: If resizing is not possible, can I just 'hide' it? or move it to the background at all?
This is a batch file that is just using PowerShell to call psexec.
Either use PowerShell Remoting ---
Running Remote Commands
Start an Interactive Session To start an interactive session with a
single remote computer, use the Enter-PSSession cmdlet. For example,
to start an interactive session with the Server01 remote computer,
type:
Enter-PSSession Server01
Run a Remote Command To run a command on one or more computers, use
the Invoke-Command cmdlet. For example, to run a Get-UICulture command
on the Server01 and Server02 remote computers, type:
Invoke-Command -ComputerName Server01, Server02 -ScriptBlock {Get-UICulture}
--- or use PSexec and target that remote host.
PsExec - Windows Sysinternals | Microsoft Docs
Using psExec to Open a Remote Command Window
https://blogs.technet.microsoft.com/systemcenteressentials/2009/09/01/using-psexec-to-open-a-remote-command-window
psExec \computer cmd
PsExec (SysInternals)
Execute a command-line process on a remote machine.
Much of PSRemoting requires that you use an account that is in the local admin group on the target. However, there are some that do not.
The only reason to use PSExec over PSRemoting is if PSRemoting is not enabled and if you need to run Code in the context of the logged on user.
# PowerShell only via PSRemoting
$TargetComputerName = Read-Host -Prompt 'Enter a computer name.'
Invoke-Command -ComputerName $TargetComputerName -ScriptBlock {
'C:\Program Files\ProgramFolder\programserver.exe'
} -Credential 'contoso\administrator'
# PSExec only
psexec \SomeTargetComputerName -c C:\Program Files\ProgramFolder\programserver.exe
With PSRemoting nothing is ever displayed on the targethost.
With that PSExec command, nothing is ever displayed on the targethost.
If you use PSExec to run in the context of the logged on user on that target host, then stuff will display when you call PowerShell.exe unless you use the minimize or hide switches.
This indicates that you are new to PowerShell and PowerShell remoting commands. Please hit up YouTube and view some of the talks on PSRemoting, running remote command, running remote programs, well, PowerShell in general.
Found the answer from a fellow colleague of mine. Apparently, very easy to just star minimized.
start /MIN
will do just that

Windows Power Shell & Console Windows Host processes will keep running after windows task schduler's task ends

I have windows server 2012 R2 , and i have defined a task inside windows task scheduler, as follow:-
-i create a .ps file, which mainly calls a remote URL:-
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
$request = [System.Net.WebRequest]::Create("https://ipAddress/")
$response = $request.GetResponse()
$response.Close()
-then i create a .bat file to call the power-shell script, as follow:-
"%SYSTEMROOT%\system32\windowspowershell\v1.0\powershell.exe" -Command Start-Process "$PSHOME\powershell.exe" -Verb RunAs -ArgumentList "'-NoExit %~dp0\AppPoolActivation.ps1'"
-i define the task to run daily on each 30 minutes for a duration of day.
-the task will be calling the .bat file.
now i am facing a problem is that when the task runs successfully, two processes will keep running 1)Windows Power Shell & 2)Console Windows host. which will cause my server to became very slow and will stop responding after around 12 hours,, now here is how my task manager will looks like when the task runs for around 5 times-
where many instances of Windows Power Shell & Console Windows host are running,, so can anyone adivce on this please ? i though the related processes will end as soon as the windows task ends..
-NoExit means no exit... So if you want it to close after the script is executed, then don't use it.

Run powershell script whenever a server reboot is initiated and show the script progress in cmd

I need to run a powershell script whenever the server is rebooted/shutdown (whether graceful or disgraceful reboot).
The script will stop 4 application services at an interval of 1 minute and then finally reboots the system.(This is a business requirement, don't ask why)
How can I make server to invoke the .ps1 script whenever a reboot or a shutdown is initiated.
My test results:
I tried to create a test script which will generate a text file with current date/time and added it to the scheduled task on the trigger of event log 6006 (which is created whenever a system reboot/shutdown is initiated.)
I checked the box -"Run with highest privileges" but after system restart no text file was generated as it was supposed to, although it generates when ran manually.
Do we have any better approach to implement this?
(My final expectation should look like this-
On a random day a random user initiated reboot after a monthly patch when a command prompt window opens before him with message something like:
Stopping service abc...
Stopped.
Waiting for 60 seconds.
Stopping service xyz...
Stopped
EDIT: I've been successfully able to invoke the .ps1 file by adding it to the gpedit as suggested by Kory and Alroc but the script runs only in background when computer restart is initiated. It doesn't opens a regular cmd window to show the progress.
I'm adding the .ps1 script as well below which stops 2 services(chosen for testing purpose) at an interval of 10 seconds and will show the timer as well, only when ran manually.When invoked by the shutdown command it'll stop services only in the background without showing the progress to the user. Kindly assist to achieve this?
Write-Host "Shutdown script invoked"
stop-service W32Time -force -PassThru
for($i = 10 ; $i -gt 0 ; $i--)
{
Write-Progress -Activity "`n Waiting for" -status "`$i equals $i seconds"
sleep 1
}
stop-service wuauserv -force -PassThru
You can use GPO to configure a shutdown script for systems.
You might be able to to it via a Win32_ComputerShutdownEvent watcher as well.
After deep digging, I've finally figured out how to make the cmd window visible while system shutdown in progress.
Here is the complete steps of performing above mentioned expectation:
Open gpedit.msc
Navigate to Computer Configuration->Windows
Settings->Scripts(Startup/Shutdown)->Shutdown.
Go to Shutdown properties. In the powershell scripts tab add your
script and select 'Run Windows Powershell script first'
Above steps will enable the invoke of script at every system shutdown. Now to make the script visible and show progress:
Navigate to Computer Configuration->Administrative
Templates->System->Scripts
Among the policies showing in the right pane enable below
properties:
Run Windows Powershell scripts first at computer start,shutdown
Run shutdown scripts visible

Switch displays on locked PC with a script

I have 2 displays attached to my PC (one is my TV) running Windows 7 and I want to switch between them using a script. I know about the "displayswitch.exe" and its parameters (like /clone, /internal, etc). However, I need the script to work while the PC is locked.
Pressing Windows+P works fine, while the system is locked, which also invokes displayswitch. However running a batch script with "displayswitch.exe /clone" does not work while the PC is locked.
To execute the script, I want to use the Remote Launcher Application on my phone. The Remote Launcher works just fine with a script to shutdown my PC while it is locked, so it is in general able to execute scripts on the locked machine.
Is there any other way, to switch between my displays while the system is locked?
That's not a trivial task.
What displayswitch internally does is to call SetDisplayConfig function. this function must be invoked from a process which lives in a interactive console, otherwise it will return ERROR_ACCESS_DENIED
One may think that he can then invoke displayswitch from psexec using the -i option and indicating the currently active user session; usually powershell
(ps winlogon).si
returns all the interactive user sessions
but launched from psexec, displayswitch.exe doesn't works anyway.
I suppose it is because in any case a command line application doesn't need the "graphical" infrastructure to run, and maybe some internal optimization happens in psexec to save to create a proper graphical environment (at least it doesn't work on my machine, i had no luck with the -x option either)
What you can do it is to write a very simple windows form program, it doesn't even need to create the actual form, it could simply invoke SetDisplayConfig and die. But being a windows form application magically do the trick.
This way you can create a script that find the currently active interactive console id, and then use psexec like this (assuming 1 is the id of the interactive session)
psexec -accepteula -nobanner -i 1 C:\path-to-your-exe\your-exe.exe
i had a powershell module loaded in my profile which i can call it from ssh or any remote connection and it switch my display even if my session is locked, or even if there is no user session logged at all.
obviously the user who runs the script must have the required grant to run psexec -i (mine is machine administrator, so it works, but i don't know which exact grant is required, you can create a functional machine administrator and invoke psexec passing these credential with -u -p parameters)
Try this:
create a job in your windows scheduler executing the desired command (linke "displayswitch.exe /clone")
set a user that has the permission to perform this command and save the password inside your new job
don't set a trigger for the job but enable the option to start it manually
use schtasks /Run /S system /U username /P password /TN taskname to trigger the job
This should execute the desired command no matter in which state your windows is as long as it is running and has network connection.

Resources