Executing an application with Vboxmanage guestcontrol does not display on guest - windows

I want to use VirtualBox vboxmanage to launch an application on many Guest machine
to perform tests.
In my case I have a Windows host and Windows guest machines.
Using vboxmanage does spawn the application process (in fact you can see it on Task Manager) but
does not show the application on the Guest screen.
Seems like my application does not have a screen to display or does have a different one...
Is possible to display the application using vboxmanage?
What am I missing?
Thanks
Example of a performed command:
"C:\Program Files\Oracle\Virtualbox\VBoxManage.exe" guestcontrol "Win64" --password pw --username admin run --exe c:\windows\system32\cmd.exe --putenv JAVA_PATH=c:\tests\jre -- cmd.exe/arg0 /C C:\tests\jre\bin\java.exe -jar c:\tests\sikulix -r c:\tests\test_app.sikuli

I managed to launch an application on Windows guest and to have the application show on the screen, so I will post here how to do if anyone needs something similar.
After putting in place the virtual machine with only host network in order to be able to connect from Host to Guest,
I used psexec to interact with guest as the follows:
psexec.exe \\ipaddress -i 1 -u WORKGROUP\username -p password c:\path\to\my\application.exe -d
Some notes about the command:
-i 1 is the options that allows to interact with the desktop of the specified session
-d could be used in order not to wait the process to terminate
WORKGROUP\username pay attention to specify the workgroup
In order to automate operation on multiple virtual machines you can determine the ip address parsing the result of this command:
"C:\Program Files\Oracle\Virtualbox\VBoxManage.exe" guestproperty enumerate vmname
or you can parse the result of a systeminfo on guest like the following:
"C:\Program Files\Oracle\Virtualbox\VBoxManage.exe" guestcontrol MyVMname run --username myusername --password my-password --wait-stdout --wait-stderr --exe "C:\Windows\System32\cmd.exe" -- cmd.exe/arg0 /C systeminfo

Related

Windows Server 2019 - Running GUI Application through OpenSSH protocol

I need to run remotely GUI Desktop App when connected through SSH.
Is this even achievable? When I try to run app(any GUI) it just hangs there and does nothing.
I need to explicitly make this work with SSH.
For anyone wondering how to run GUI applications using psexec, this is the solution:
psexec64 is located in C:\Windows
psexec64 -accepteula -nobanner \\SERVER.company.co -u DOMAIN\user -p password -h -i 2 C:\\Windows\notepad.exe
Note: You can run any exe on the server, as well as you can run locally,
also if you need to run it from linux here is solution:
First install winexe: https://sourceforge.net/projects/winexe/ - google for installing from cli
winexe -U DOMAIN/user%password //SERVER.company.co "psexec64 -u DOMAIN\user-p password -accepteula -nobanner -h -i 2 C:\Windows\notepad.exe"
Hopefully this will help someone

PsExec and WindDirStat on a remote system - how to run

I'd like to be able to run WinDirStat on a remote machine that I have administrative rights over but it does not work.
This is what I have done:
Run CMD as admin:
psexe.exe -i -s cmd.exe
From the new prompt:
psexec.exe \\host -u username winddirstate.exe
I type in my PW and it does not launch
Both running Windows 7 Enterprise.
Usage: psexec [\\computer[,computer2[,...] | #file]][-u user [-p psswd][-n s][-r servicename][-h][-l][-s|-e][-x][-i [session]][-c [-f|-v]][-w directory][-d][-<priority>][-a n,n,...] cmd [arguments]
-a Separate processors on which the application can run with
commas where 1 is the lowest numbered CPU. For example,
to run the application on CPU 2 and CPU 4, enter:
"-a 2,4"
-c Copy the specified program to the remote system for
execution. If you omit this option the application
must be in the system path on the remote system.
-d Don't wait for process to terminate (non-interactive).
-e Does not load the specified account's profile.
-f Copy the specified program even if the file already
exists on the remote system.
-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.
-h If the target system is Vista or higher, has the process
run with the account's elevated token, if available.
-l Run process as limited user (strips the Administrators group
and allows only privileges assigned to the Users group).
On Windows Vista the process runs with Low Integrity.
-n Specifies timeout in seconds connecting to remote computers.
-p Specifies optional password for user name. If you omit this
you will be prompted to enter a hidden password.
-r Specifies the name of the remote service to create or interact.
with.
-s Run the remote process in the System account.
-u Specifies optional user name for login to remote
computer.
-v Copy the specified file only if it has a higher version number
or is newer on than the one on the remote system.
-w Set the working directory of the process (relative to
remote computer).
-x Display the UI on the Winlogon secure desktop (local system
only).
-arm Specifies the remote computer is of ARM architecture.
-priority Specifies -low, -belownormal, -abovenormal, -high or
-realtime to run the process at a different priority. Use
-background to run at low memory and I/O priority on Vista.
computer Direct PsExec to run the application on the remote
computer or computers specified. If you omit the computer
name PsExec runs the application on the local system,
and if you specify a wildcard (\\*), PsExec runs the
command on all computers in the current domain.
#file PsExec will execute the command on each of the computers listed
in the file.
cmd Name of application to execute.
arguments Arguments to pass (note that file paths must be
absolute paths on the target system).
-accepteula This flag suppresses the display of the license dialog.
-nobanner Do not display the startup banner and copyright message.
First you are in Same Directory of Psexec or set path of PSexec in Environment path then put this command
psexec.exe \host -u username -p password -s cmd /C C:\full_remote_path_of_\windirstat.exe
OR
put one bat file inside your remote machine like C:\abc\run.bat and put this code inside it
echo off
C:\full_path_of_\windirstat.exe
echo "Success"
and run command from your local
below command will run that bat file present on remote
psexec.exe \host -u username -p password -s cmd /C "C:\remote\run.bat"
OR
there is no need to put run.bat file in remote machine put only on local and then give below command
psexec.exe \host -u username -p password -s -i -c -f "C:\local\run.bat"
OR
psexec.exe \host -u username -p password -s -i -c -v "C:\local\run.bat"
-s ----->as a Administrator
-i ----->Interactive
-c ----->copy run.bat to remote
-f -----> if run.bat already exist on remote Computer
-v -----> if higher version on local and lower version on remote then it
will copy otherwise not
USING FILE NAME
If you want to run on many remote machine and all remote machine username and password are same so put one file like host.txt and put all ip's line by line there is no space on starting on line then give below command and it will run serially
PsExec.exe #C:\full_path\host.txt -c -s -u username -p password run.bat
**Parallel Running in All Remote Machines **
if you want to run parallel then give one more parameter -d then it will not wait to finish process until it finished and you can use for loop and put PSexec command inside it
Save Result in some file THREE Variation
**First Variation**
Below will copy the iname.bat file in remote system and execute it and save the result in success.txt inside local machine directory in which we are running PSexec
PsExec.exe \remote_ip -u username -p password -c -f "iname.bat">success.txt
**Second Variation**
below will run test.bat present on remote machine and make Success.txt on localmachine
PsExec.exe \remote_ip -u username -p passowrd cmd /C "C:\abhi\test.bat">success.txt
**Third Variation**
this will run test.bat present on remote machine and make Success.txt on remote machine
PsExec.exe \remote_ip -u username -p password -i cmd /C "C:\abhi\test.bat > C:\abhi\success.txt"

psshutdown fails unless run from admin cmd prompt

Ok here's an interesting problem I've run into. I'm attempting to reboot some computers remotely using psshutdown and getting access denied errors unless I run the cmd from a cmd prompt that was run as admin. I myself am an admin on my machine as well as on the remote computer so my credentials should work just fine.
Example code:
psshutdown /accepteula \\COMPUTER.DOMAIN.COM -u DOMAIN\USER -p Password -r -t 0
Example output:
Could not start PsShutdown service on COMPUTER.DOMAIN.COM:
Access is denied.
However when run from admin cmd window:
COMPUTER.DOMAIN.COM is scheduled to reboot in 00:00:00.
As kludge-y as it seems, is it possible to use psexec to run psshutdown as an elevated user?
After running around in circles with this I ended up using:
runas /netonly /user:DOMAIN\USERNAME "shutdown -m \\XXX.XXX.XXX.XXX -r -f -t 0"
Which isn't ideal but got the job done.
Ok, try this. It will open an external window where you can remotely shutdown computers on your network:
shutdown -i
You can type this straight into the CMD window without needing to create a .bat file.
Hope this helps!

psexec giving the system cannot find the file specified

I'm trying to run this from my win7 CMD (as Admin):
psexec IpAddress -u domain\user -p pword c:\Autobatch\ClientJobSender.exe http://reportserver.net:8070/JobExecutor.asmx c:\AutoBatch\backup\trigger.xml
but am getting a "the system cannot find the file specified" error.
I've also tried it this way:
psexec IpAddress -u domain\user -p pword c:\Autobatch\ClientJobSender.exe http://reportserver.net:8070/JobExecutor.asmx c:\AutoBatch\backup\trigger.xml
but get a unknown user or bad password.
What's weird is that I can connect via Remote desktop with the same IP address and user/pass.
Make sure the server has the settings below:
a) Admin share is enabled: run services.msc and check the Service "Server" is enabled
b) Add the key for the share in the registry and restart:
reg add "HKLM\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters" /v AutoShareServer /t REG_DWORD /d 1
And then use:
psexec \\IpAddress -u domain\user -p pword -w "c:\Autobatch" "ClientJobSender.exe http://reportserver.net:8070/JobExecutor.asmx c:\AutoBatch\backup\trigger.xml"
Actually, I don't see a difference between your 2 command lines. However, the error from the first command is because your syntax is incorrect. You must use
PsExec \\a.b.c.d ...
instead of
PsExec a.b.c.d ...
I got it to work by elevating the local batch file to execute with administrator privileges, that is to say, the terminal window was operating with administrator privileges.
If you're trying to use automation services, you can use the ClientJobSender.exe on the local machine (or on the machine where you set up the scheduling). Just copy the ClientJobSender.exe and the related config file from the install pack to the scheduler server and refer it locally.
You might have the directory path wrong. Try change the .exe path into cmd.exe and cd into your intended path to see if it is actually the correct path.

How to execute a Windows command on a remote PC?

Is it possible to execute a Windows shell command on a remote PC when I know its login name and password?
Is it possible to do it using client PC's Windows shell?
If you are in a domain environment, you can also use:
winrs -r:PCNAME cmd
This will open a remote command shell.
psexec \\RemoteComputer cmd.exe
or use ssh or TeamViewer or RemoteDesktop!
This can be done by using PsExec which can be downloaded here
psexec \\computer_name -u username -p password ipconfig
If this isn't working try doing this :-
Open RegEdit on your remote server.
Navigate to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System.
Add a new DWORD value called LocalAccountTokenFilterPolicy
Set its
value to 1.
Reboot your remote server.
Try running PSExec again from
your local server.
You can use native win command:
WMIC /node:ComputerName process call create “cmd.exe /c start.exe”
The WMIC is part of wbem win folder: C:\Windows\System32\wbem

Resources