I'm running
chkdsk /f /r
to schedule a check disk when I restart the PC.
Is there a way to automatically shutdown the PC after the check disk has completed??
You can try via Startup; Press Windows + R and type shell:startup and click on ok. This is will open the startup folder, create a notepad and type shutdown -s -t 300 this will give 300s or 5mins before shutdown happens. Save the file as shutdown.bat save as type: All files. Copy that file to the start up folder and schedule the chkdsk when the system boot it will trigger the shutdown. To abort the timer just press Windows + R and type shutdown -a This will abort the process. Go to the startup folder and delete the file.
Related
We may run Firebird as application using command line:
firebird.exe -a -p 3050
Is that possible to shutdown the firebird process using command line too?
There is no "easy" way to do it. If you started firebird.exe as an application, you can quit it by right-clicking on its icon in the taskbar, and selecting shutdown.
The only alternative is to kill it using taskkill, for example:
taskkill /IM firebird.exe
This has the following downsides:
if you have active connections, this will produce a popup to ask for confirmation of shutdown (just like when doing this from the taskbar)
if you have multiple firebird.exe processes, they will all be terminated
You can also force kill to shutdown, this will not produce the popup; open connections will be killed without prompting:
taskkill /F /IM firebird.exe
However, if you regularly need to do this, it might be better to install Firebird as a Window service that doesn't startup automatically. You can then control the service using NET START and NET STOP (or using instsvc).
For example, install Firebird as a service (require administrator command prompt):
instsvc install -demand -name firebird3
This creates a service called "Firebird Server - firebird3"
You can then start and stop the service using NET START "Firebird Server - firebird3" and NET STOP "Firebird Server - firebird3", although this also requires elevated administrator privileges.
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
I have the following batch script:
echo %time% >> C:\file.txt
C:\MyProgram\program.exe /arg1 >> C:\file.txt
echo ------- >> C:\file.txt
I have created a service with
sc create ProgramRun type= own start= auto binPath= "cmd /c cd /d c:\MyProgram\ && start script.bat"
After a reboot, in file.txt I have printed the correct time, but without my program ouput. In that program, I have some simple printf
What can I do to write the output to a file without editing the program?
As a Windows Service, your program is being run in the context of the Local System account, which may not have the rights necessary to launch and run your program properly. Try editing the service and setting the Log On credentials to a Windows account that you know can execute your program properly.
Also, while the Windows Service Control Manager (SCM) will happily start your batch file, the outcome reported will always be failure, specifically "Error 1053: The service did not respond to the start or control request in a timely fashion". This is because your batch file can not communicate with the SCM! Have a look at Microsoft's free (and basic) Srvany "service wrapper" to avoid this problem.
Remote shutting down Windows computer with cmd. Possible?
I have searched over the internet, and I have found many solutions for this problem,
BUT
No one has worked. I don't have got the password for the other computer, or permission to shutdown it, I get everytime: Access denied. (5) So my quetions are:
Is there any software tool to do that?
Is it possible at all?
Can I make it in Windows on both computers?
Not exactly needed cmd, but must be shutted down by remotely, without installing any software on the second computer.
Many thanks for help
I found the solution for you.
RUN secpol.msc in CMD (on the computer u want to enable the remote shutdown)
Go to Local Policies -> User Rights Assignment and search for "Force shutdown from a remote system"
Double click it and then "Add User or Group..." and type "Everyone" and then add it.
This SHOULD work! I've set this configuration on my computer and then executed this command on my brother's PC while we are on the same LAN network and i've got the shutdown message AND the computer did restart.
shutdown -m \\mypcname -r -c "this pc will shutdown in 60 secs" -t 60
Be sure that u can see the computer u want to shutdown trought net view. But u already see it, because u are getting the Access denied. (5).
Report back to the question if it works!
Kind Regards
Look at:
http://www.wikihow.com/Do-a-Remote-Shutdown-for-a-PC-on-a-LAN
quote:
"At your local command prompt type in shutdown -m \computername, replacing "computername" with the name of the computer you wish to shutdown or the computer's IP address."
Or from within a remote session:
shutdown /s /t 0
(meaning: shut down in 0 seconds)
Open cmd
Write net view
Find the computer you want to kick form your wifi or turn off
Write ping ex: USER
Find ip address
Write shutdown -I
I am trying to start windows 7 unattended using the startnet.cmd file. The problem is that when the start setup.exe command is triggered, the setup runs and closes, but cannot reboot because the startnet.cmd is still open. If I put "exit", it starts the setup and exits immediately. Is there a way to check uf the setup ran successfully and then perform an exit?
wpeinit
net use u: \\192.168.2.10\windows
u:
start setup.exe /unattend:\\192.168.2.10\windows\unattend.xml /noreboot
REM ping -n 30 127.0.0.1
REM exit
I think your commands are correct but you explicitly state that setup.exe shall not initiate a reboot after the first phase of the setup procedure has completed.
The black cmd.exe Window will have to remain open during the setup procedure. If it's terminated then Windows PE performs an immediate reboot. Hence your setup.exe process will be terminated. I think your comment using ping to delay the exit very well shows that you have tried to delay terminating the shell process. But as you can't know how long the setup process will take you cannot fill any good value in the delay algorithm.
Although I think you don't need to. You are launching setup.exe using start which detaches the process and returns to the shell immediately. In fact since setup.exe is the last command you run you could also live with the fact that setup.exe is not detached. Either by not using start or by using start /wait
wpeinit
net use u: \\192.168.2.10\windows
u:
setup.exe /unattend:\\192.168.2.10\windows\unattend.xml /noreboot
exit
or
wpeinit
net use u: \\192.168.2.10\windows
u:
start /wait setup.exe /unattend:\\192.168.2.10\windows\unattend.xml /noreboot
exit
Although I think the entire purpose of this would be to return to the shell and perform the exit (which initiates a reboot) command after setup.exe terminates.
As there are no more commands to be executed I suggest letting setup.exe do the reboot itself by removing the /noreboot flag:
wpeinit
net use u: \\192.168.2.10\windows
u:
start setup.exe /unattend:\\192.168.2.10\windows\unattend.xml
This should keep the shell process (cmd.exe) open while setup is running. At the end of the setup process it will initiate a reboot (initiated by setup.exe) and therefore also te