Run PowerShell script in window on machine - windows

I am trying to have a PowerShell script run after a machine restart. I want the script to run on restart, not login. Additionally, I want the script to run in a window. I found many questions that are almost identical to mine but don't include having the script running in a window. I've tried including -noexit. I have tried to use task scheduler and while it says that my script is running, no window appears. What do I need to do to make it run in a window?
I do not want to change global keys making all scripts run in a window and I do not want to write anything in my script that prompts the user to close the window.

Related

Running this windows program hidden [duplicate]

This question already has answers here:
Prevent VBscript app from showing Console Window
(1 answer)
How can I run a command silently in VBScript? [duplicate]
(1 answer)
Closed 3 years ago.
I need to run this old telnet scripting client silently in the background. You run it from cmd providing arguments for:
1- a file containing the commands to send
2- a file where to print any output
3- whether to run it minimized to taskbar or not
(note: if it is run without arguments, it displays a help window)
So this is what I type in cmd, and it works like a charm:
TST10.exe /r:mycommands.txt /o:myoutputfile.txt /m
What I can't achieve however, is running it completely hidden in the background. Now, since this program requires arguments, I tried to first achieve this only on the help window that gets spawned (ie: running it without arguments).
I tried with VBScripts using carefully all the answers here. It always starts normally (not hidden). These VBScripts all succeed to hide other programs though.
I also tried with this program that starts processes hidden, oddly enough it only succeeds in hiding the the telnet client from the taskbar. Also, even if it would completely hide it, I still have no idea on how to pass the mentioned arguments.
edit:
How is this even CLOSE to "Prevent VBscript app from showing Console Window" or "How can I run a command silently in VBScript?"? This question VERY clearly asks how to run a normal .exe program in a hidden manner which is not even slightly related to running a VBscript without showing the console or running a command silently in VBScript. + I even stated that the only way to achieve this USING VBScipt (not hiding a VBScript itself) doesn't work. Are the accounts marking this as duplicate bots that simply detect "VBScript" and "hide program" and assume that I want to hide an executing VBScript? Or can they simply not understand English?
Try this... create a run.js or something (make sure you give it a .js extension). Place this line inside the .js:
WScript.CreateObject("WScript.Shell").Run("notepad.exe", 0);
Run it. You should see notepad.exe running in your task manager, but it's window should be hidden. Now try the same with your app instead.

C:\windows\SysWow64\CScript.exe window pop up

I created a macro in Excel and i am running it from a .vbs file. It's working fine on my laptop. I copied the same work on a new laptop and each time i am running the vbs file this window appears on the screen.
I have made some research and read that the situation i mentioned is happening when loading CheckNDISPort service on the startup. But i don't believe it's the reason because when i go to task manager and check in the startUp tab i don't find this service. Also when i restart my laptop i don't get this window, only when i am running my vbs file. I am sure there is any problem with my vbs file too because on the other laptops it's working fine.
Any suggestion please how to get ride of this pop up ? For now i am closing the window each time or ending the task from task manager but everytime i run it again so it pops up again.
Thank you very much.
Windows Scripting Host has two interpreter front-ends, wscript.exe and cscript.exe. cscript.exe is a console application and if cscript.exe is set as the default a console window will open every time you execute a script.
Run cmd.exe elevated as administrator and run wscript.exe //h:wscript.
Depending on the Windows version, you might also be able to right-click a .vbs file, select "Open with...", choose %windir%\system32\wscript.exe and check the "default" checkbox.

VBS: Display message on logon screen

It is possible to set up Windows so that it displays verbose messages during startup or shutdown.
I'm writing a VBScript procedure which will be ran at startup and I would like to display a meaning message instead of the default "Running startup scripts".
How to achieve this in VBS?
You need to use Windows administrative tools which allow you to configure start up for specific users or users group to execute anything on start-up, shutdown even change their backgrounds. Network policy maybe useful for that as well if you are on domain controlled environment.
Also you can use MSCONFIG on a single system to add or define what ever you want to run at startup, for as long as it is valid windows program.
Once you configured what script to run use Windows console (run that under wscript.exe) to execute your VBS file with what ever you want to put there (with wscript you will get dialog with your text in it).
Usually it should look like
Wscript.Echo "Meaningful message goes here"
If you run that under cscript.exe you'll get output in your console window.

How to display the main window of a process in another Windows session?

When running a Scheduled Task under Windows to launched batch processes under a dedicated account, you could want to see output of theses processes.
These sub-processes could be either or both graphical or character based applications
As there are running in a different Windows Logon session, I cannot find way to display their output. There are like ghost processes
I would expect being able to use the show Window command from Process Explorer, but even via running Process Explorer under the dedicated account used to run the task (via runas), it is not working
Is there a way to do it ?
References : http://www.brianbondy.com/blog/id/100/
I believe that once created, a window cannot be transferred to another window station. Also, I doubt it is possible to open windows in another session. For character-based applications you are better off writing the output to some file and examining that file. For graphical applications you are out of luck with task scheduler. You may want to write a simple VBS script that wakes up at a certain time and runs your graphical task(s) and run it upon user logon, e.g. along the lines of a script from this page:
http://social.technet.microsoft.com/Forums/scriptcenter/en-US/d9465815-87e2-43df-a0fe-4a23c16dca99/need-a-time-schedule-in-vbs-script-to-execute-something

Launch batch script before windows login window

I'm working on Windows Server 2003 and Windows server 2008.
I would like to start a batch script just before the login window is displayed.
I read about adding the script in the Group Policy editor (startup/shutdown) but it's not working (it worked for logon and logoff though).
An alternative would be to use the task scheduler service but it's not working either. Plus, I want to be able to see the results in a cmd window. That means the last alternative - creating a service to do the job - is not an option.
Do you have any idea ?
Thanks.
Control Panel -> Scheduled Tasks -> < follow the prompts>
Not as nice as a service, which you can start and stop through well-behaved commands, but if it is a service you want running at all times, it does the job.
Try adding your script as a user defined service
That way it will get executed before the login prompt;
http://support.microsoft.com/default.aspx?kbid=137890
Though this article says it can't be used for batch scripts, you can call the script from an executable.

Resources