How to put command with parms directly in Registry RunOnce?


  1. Posts : 244
    win7pro 64bit
       #1

    How to put command with parms directly in Registry RunOnce?


    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


  2. Posts : 721
    Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
       #2

    Hello Pstein,

    pstein said:
    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


  3. Posts : 244
    win7pro 64bit
    Thread Starter
       #3

    Great. Thank you
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 02:21.
Find Us