How can you bring a background process to the foreground (make it possible to select the GUI) [duplicate] - psexec

This question already has answers here:
PsExec run remote batch file in visible mode
(4 answers)
Closed 5 years ago.
I have written a small script to access a remote machine then run an executable however the executable runs only in the background.
Is it possible to run so I am able to see the gui?
psexec IPADDRESS -u USERNAME -p PASSWORD -i SESSIONID -d "C:\Windows\system32\notepad.exe"

Thanks for your help Avshalom.
The answer for me was to change my sessionid from 0 to 2.

Related

Can not open "help" with \h or \? in psql on Windows 10. Command "more" is not written corectly, it says [duplicate]

This question already has answers here:
What causes "More is not recognized..." error when running Postgresql 11 on a Windows machine?
(1 answer)
psql "more is not recognized" error
(8 answers)
Closed 2 years ago.
I'm very new to coding and these things so I already have problems with the post-installation phase. I'm using Windows 10 and downloaded PostgreSQL11.
I've already downloaded psql and watched a few tutorials. After the shell demands me to type in my password etc. I pressed " help" and then I pressed "\h". The last command "\h" , the shell doesn't recognize it, and it says something like (I have it in German so it may not be 1:1):
The command "more" is not written correctly or could not be found.
I have already tried to insert the path of my bin folder (C:\Program Files\PostgreSQL\11\bin) into the system variables of my pc. And also inserted the new variable for my lib (C:\Program Files\PostgreSQL\11\lib). But it still doesn't work.
What can I do to fix it?

What's the equivalent of 'set -e' (exit on any errors) in Powershell? [duplicate]

This question already has answers here:
How to stop a PowerShell script on the first error?
(11 answers)
Closed 3 years ago.
I've been using Unix for about 20 years, but only started using Powershell recently. I have a ps1 script that does a number of tasks.
I know I could check each of them, and throw if they error, but it would be good for the entire script just to exit on any errors - like set -e does in bash.
How can I make a Powershell script exit immediately upon any error?
Using pwsh 6.2.1.
Having just found the answer to my own question:
ErrorActionPreference does this.
$ErrorActionPreference='Stop'
at the top of the ps1 file.

Startup Parameters within the Script? [duplicate]

This question already has answers here:
Is there a way to programmatically set the ApartmentState to STA?
(2 answers)
Closed 7 years ago.
I have a script that needs to run in single-threaded mode, and I currently start it up with the -sta parameter with a batch. Is it possible to run the script in -sta mode only executing the Script? I thought about moving the whole script into one function and execute this function in single-threaded mode.
Is that possible? I don't want to give out a batch file and my ps1.
I think if you were to get PowerGUI and put the script into this, you would be able to package the PS1 file into an exe file which can just be executed like a normal program.
Once PowerGUI is installed you can do this from Tools, Complile Script.

How to launch program from Perl as a separate process? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How can I fire and forget a process in Perl?
I'm looking for a way to invoke a new process from a Perl script, that will let a launched program and a Perl script, from which it's launched, proceed to work concurrently.
The program is SIPp, if it's important.
Thank you.
If you actually want separate processes, then another option is fork and exec.
if (fork) {
# In the parent program
# Continue as usual
...
} else {
# In the new child program
# Replace with another program
exec $some_other_program;
}
SIPp has "-bg" commandline parameter.
This parameter launches SIPp in background mode.
Use Proc::Background
In Windows system you may use "start" command.
For example:
start notepad
OR
start /d"C\Program Files\Sipp3.1" sipp.exe -sn uac

How to run an application as "run as administrator" from the command prompt? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I have a batch file called test.bat. I am calling the below instructions in the test.bat file:
start /min powershell.exe %sysdrive%\testScripts\testscript1.ps1
When I run this through the command prompt, my testscript is running successfully. I want to run it as administrator (as if I have created a desktop shortcut and run as administrator. It shouldn't prompt for any username or password).
I have tried adding /elevate and /NOUAC parameters in the above test.bat, but no luck. How do I fix this issue?
I know how to do it manually, but I want this to be executed from the command prompt.
(By Marnix Klooster): ...without using any additional tools, like those suggested in an answer to Super User question How to run program from command line with elevated rights.)
Try this:
runas.exe /savecred /user:administrator "%sysdrive%\testScripts\testscript1.ps1"
It saves the password the first time and never asks again. Maybe when you change the administrator password you will be prompted again.
See this TechNet article: Runas command documentation
From a command prompt:
C:\> runas /user:<localmachinename>\administrator cmd
Or, if you're connected to a domain:
C:\> runas /user:<DomainName>\<AdministratorAccountName> cmd
It looks like psexec -h is the way to do this:
-h If the target system is Windows Vista or higher, has the process
run with the account's elevated token, if available.
Which... doesn't seem to be listed in the online documentation in Sysinternals - PsExec.
But it works on my machine.