View unanswered posts | View active topics It is currently 23 Oct 2014 12:30



Post new topic Reply to topic  [ 15 posts ] 
Running a DOS command with options when I reboot the system 
Author Message

Joined: 08 Dec 2011 12:14
Posts: 21
Post Running a DOS command with options when I reboot the system
HI

In Windows 7, there is a registry key/entry that allows to run a DOS command with options when I reboot the system (this command will have to be performed only on the first reboot)?

THANKS

BYE


16 Apr 2012 02:51
Profile

Joined: 10 Feb 2012 02:20
Posts: 4319
Post Re: Running a DOS command with options when I reboot the sys
google for "runonce"


16 Apr 2012 04:39
Profile

Joined: 08 Dec 2011 12:14
Posts: 21
Post Re: Running a DOS command with options when I reboot the sys
There is a problem:

The runonce key is performed in the system starting phase and not during the system shutdown phase. Am I wrong?

THANKS

BYE


16 Apr 2012 10:40
Profile

Joined: 23 Dec 2011 13:59
Posts: 1935
Post Re: Running a DOS command with options when I reboot the sys
You seem to be contradicting yourself. Do you want it to run on startup or shutdown?


16 Apr 2012 10:46
Profile

Joined: 08 Dec 2011 12:14
Posts: 21
Post Re: Running a DOS command with options when I reboot the sys
During the shutdown.

THANKS

BYE


16 Apr 2012 11:12
Profile

Joined: 28 Jun 2010 03:46
Posts: 163
Post Re: Running a DOS command with options when I reboot the sys
- start -> run -> gpedit.msc
- Under computer configuration -> windows settings -> scripts -> right click on shutdown -> select properties -> add the name of the program you want to run (.cmd, .bat, .vbs...). Just try it.
I heared once that there might be a time limit on this - you better check this.

Saso


16 Apr 2012 11:49
Profile

Joined: 08 Dec 2011 12:14
Posts: 21
Post Re: Running a DOS command with options when I reboot the sys
Instead, if I have Windows 7 Home Premium, how do I solve this problem?

THANKS

BYE


16 Apr 2012 12:07
Profile

Joined: 10 Feb 2012 02:20
Posts: 4319
Post Re: Running a DOS command with options when I reboot the sys
.


16 Apr 2012 16:42
Profile

Joined: 26 Oct 2011 22:38
Posts: 1007
Location: Egypt
Post Re: Running a DOS command with options when I reboot the sys
this is the registry keys for runonce jobs:
Code:
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunOnce
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunOnce


u can add jobs using batch like that:
Code:
@echo off
cls
set regkey1=HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunOnce
set regkey2=HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunOnce
:: = = = = = = =
REG add "%regkey1%" /v "job_name" /t "job_type" /d "job_command" /f >nul

Replace the "job_name" with the title of the job u going to add.
Replace the "job_type" with the type of the registry key use "REG_SZ" it will work.
Replace the "job_command with the program u want to launch and u can add special switches to it like "c:\test\example.exe /s"

if running windows 7 u will need permission to modify Registry.


18 Apr 2012 21:03
Profile

Joined: 10 Feb 2012 02:20
Posts: 4319
Post Re: Running a DOS command with options when I reboot the sys
@abc0502 The fellow wasn't clear - he wants to run a task when he *shuts down* the PC.


@op

One batch solution is to run the task in a batch file and then use shutdown.exe after it, so that running the batch file performs your tasks and then your machine shuts down.


19 Apr 2012 00:56
Profile

Joined: 08 Dec 2011 12:14
Posts: 21
Post Re: Running a DOS command with options when I reboot the sys
abc0502 wrote:
this is the registry keys for runonce jobs:
Code:
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunOnce
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunOnce


u can add jobs using batch like that:
Code:
@echo off
cls
set regkey1=HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunOnce
set regkey2=HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunOnce
:: = = = = = = =
REG add "%regkey1%" /v "job_name" /t "job_type" /d "job_command" /f >nul

Replace the "job_name" with the title of the job u going to add.
Replace the "job_type" with the type of the registry key use "REG_SZ" it will work.
Replace the "job_command with the program u want to launch and u can add special switches to it like "c:\test\example.exe /s"

if running windows 7 u will need permission to modify Registry.


There is a problem:

The runonce key is performed in the system starting phase and not during the system shutdown phase. Am I wrong?

THANKS

BYE


19 Apr 2012 01:43
Profile

Joined: 03 Apr 2010 20:27
Posts: 109
Location: Wellington, New Zealand
Post Re: Running a DOS command with options when I reboot the sys
Correct, runonce is for when the system is starting.

Maybe we could rename shutdown.exe to something else and put another exe in its place. This exe could store the argument that was intended for the shutdown command (-s, -r etc.), then runs a batch file we want to run on shutdown and then runs the original shutdown.exe (the one we renamed) with the argument we collected earlier....?

I know, I know, it's a bit iffy when messing with system files... Just a thought.

Hmm.. this is an afterthought... if an application uses a system call to shut the computer down, the solution I suggested may not work as Windows may not use shutdown.exe to shut the machine down when a system call is used to initiate a shutdown..... Can anyone confirm this?

Thanks
Phillid


19 Apr 2012 02:15
Profile WWW

Joined: 10 Feb 2012 02:20
Posts: 4319
Post Re: Running a DOS command with options when I reboot the sys
When Windows shuts itself down I'd think it uses an API function and not shutdown.exe

A test would be to rename shutdown.exe and see if Windows can be shut down.


The OP ignored my suggestion, so maybe it wasn't clear enough.
You can have a batch file like this to run a program before the machine shuts down.

@echo off
start "" /w "c:\program files\my application.exe"
shutdown.exe -s


19 Apr 2012 02:48
Profile

Joined: 03 Apr 2010 20:27
Posts: 109
Location: Wellington, New Zealand
Post Re: Running a DOS command with options when I reboot the sys
Yeah that's what I thought.. :/ Time to decompile Windows, edit it and recompile ;)

The only problem with that batch file is that it won't run as a result of a shutdown... I think that's what he wants. Your batch shuts down the computer itself... Maybe he needs to clarify.

Anyway, time for me to have a coffee, enjoy the rest of the evening and get some sleep.

Thanks
Phillid


19 Apr 2012 02:54
Profile WWW

Joined: 26 Oct 2011 22:38
Posts: 1007
Location: Egypt
Post Re: Running a DOS command with options when I reboot the sys
sorry i didn't notice shutdown,
as miskox said use the group policy,
This should add registry keys to the group policy to run when shuting down the pc:
i tested it to add the registry keys but didn't test to start that keys:
Code:
@echo off
cls

:: This is the main key and must be exist once to add jobs,
:: "regkey_main=HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\Scripts\Shutdown\0"

:: This key is for job #1:
:: "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\Scripts\Shutdown\0\0"
::This key is for job #3:
:: "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\Scripts\Shutdown\0\1"
:: If Add 3rd Job the key should look like: "notice the last digits"
:: "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\Scripts\Shutdown\0\2"

:: ===== Change This section Only with your settings =====
set "regkey=%temp%\reg.reg"

set "scriptname1=Test1"
set "parameters1=D:\example1.exe /s"

set "scriptname2=Test2"
set "parameters2=D:\example2.exe /s"

:: you can add more jobs by duplicating the last set of commands and consider the last number in each regkey address "0\0" for job 1 and "0\1" for job 2  etc,...
:: the %regkey_main appear once and don't repaeat it
:: =============== End Section ================
:: This is The Reg.Reg Key that will add the tasks executed at the shutdown ::
IF EXIST "%regkey%" ( DEL /F /Q "%regkey%
) Else ( goto next )
:next
echo: Windows Registry Editor Version 5.00 >>%regkey%
echo:
echo: ^[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\Scripts\Shutdown\0^] >>%regkey%
echo: "GPO-ID"="LocalGPO" >>%regkey%
echo: "SOM-ID"="Local" >>%regkey%
echo: "FileSysPath"="C:\\Windows\\System32\\GroupPolicy\\Machine" >>%regkey%
echo: "DisplayName"="Local Group Policy" >>%regkey%
echo: "GPOName"="Local Group Policy" >>%regkey%
echo: "PSScriptOrder"=dword:00000001 >>%regkey%
echo:
echo: ^[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\Scripts\Shutdown\0\0^] >>%regkey%
echo: "Script"="scriptname1" >>%regkey%
echo: "Parameters"="parameters1" >>%regkey%
echo: "IsPowershell"=dword:00000000 >>%regkey%
echo: "ExecTime"=hex^(b^):00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00 >>%regkey%
echo:
:: The next commands is for a second job u can delete it if u have only one job and add one like it at the end if u have more jobs just notice the last digit of the reg-key
:: >"0\1"<   this mean 2nd job and if add 3rd job it will be like that   >"0\2"<   at the end of the same key name and the only change will be in   >"script"<   and   >"parameters"<.
echo: ^[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\Scripts\Shutdown\0\1^] >>%regkey%
echo: "Script"="scriptname2" >>%regkey%
echo: "Parameters"="parameters2" >>%regkey%
echo: "IsPowershell"=dword:00000000 >>%regkey%
echo: "ExecTime"=hex^(b^):00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00 >>%regkey%

Reg Import "%regkey%" >nul


just change the section pointed to in the batch and run it with administrator rights i tested in win7


19 Apr 2012 03:18
Profile
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 15 posts ] 


Who is online

Users browsing this forum: Yahoo [Bot] and 19 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Forum style by Vjacheslav Trushkin for Free Forums/DivisionCore.