How to put command with parms directly in Registry RunOnce?

pstein

New member
Member
VIP
Local time
4:48 AM
Messages
244
Assume I want to perform a command line command with parameters one time at next boot (under 64bit Win 7).

Therefore I want to create this command directly in the appropriate Registy key and not indirectly by
putting it into *.bat batch script and and call this from RunOnce

For simplicity assume I want to perform a "chkdsk" command but it could be others as well.

Now I have difficulties to setup a *.reg script. The following does NOT work:

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\RunOnce]
"doitonce"="\"chkdsk Z: /F /V /R /I /C >C:\log\mychkdsk.log\""

What do I have to change?

Peter
 

My Computer My Computer

At a glance

win7pro 64bit
Computer type
PC/Desktop
OS
win7pro 64bit
Hello Pstein,

What do I have to change?
Quite a bit. You're experiencing multiple problems currently.

For starters, there are mistakes with your example reg snippet, namely, there's a pair of literal double quotes around the whole command, which is incorrect because you are telling the parser to treat the whole line as a single path to a program instead of a program to run with arguments. Secondly, to use a literal backslash you must escape a backslash by backslash-ing a backslash. Last problem about your .reg file is that you are missing the Windows Registry Editor Version 5.00 shebang line at the top of your file. This line is mandatory.

This is what your not-working .reg file should have looked like
Code:
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\RunOnce]
"doitonce"="chkdsk Z: /F /V /R /I /C >C:\\log\\mychkdsk.log"


Now for the more problematic problem: you cannot use redirection outside of a Command Prompt. So you must instruct the Command Prompt to interpret this command by preceding the command line command you want to run with cmd /c.

E.g.
Code:
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\RunOnce]
"doitonce"="cmd /c \"chkdsk Z: /F /V /R /I /C >C:\\log\\mychkdsk.log\""


Also, if something "does not work", please be specific. Are you receiving an error of any kind?
 

My Computer My Computer

At a glance

Windows 10, Windows 8.1 Pro, Windows 7 Profes...
Computer type
PC/Desktop
OS
Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
Great. Thank you
 

My Computer My Computer

At a glance

win7pro 64bit
Computer type
PC/Desktop
OS
win7pro 64bit
Back
Top