0

cmdスタートアップフォルダーを簡単に変更するためのpythonプログラムを作成しようとしています(cd ...と入力して目的のファイルに移動するのではなく)
しかし、最初に、regedit.exeをcmdに入力せずに変更する方法を理解する必要があります.
Pythonのドキュメントを読んだ後、これが私が得た場所です:

from winreg import*

a=OpenKey(HKEY_CURRENT_USER,"Software\Microsoft\Command Processor\\")
SetValue(HKEY_CURRENT_USER,"Software\Microsoft\Command Processor\\",REG_SZ,"cd\\the path that I want.")

このコードは文字列値を編集します (それがその名前だと思います) デフォルト。
しかし、必要なのは、文字列値の Autorun を編集することです
。その SetValue 関数に Autorun を入れるさまざまな方法を試しましたが、うまくいきませんでした。
注: Default と Autorun はどちらも HKEY_CURRENT_USER\Software\Microsoft\Command Processor にあります。
私も試してみました

SetValueEx(a,"Autorun",0,REG_SZ,"cd\\The path that I wantsss.")#Don't know if this is the right way to use it.  

しかし、これは私にこのエラーを与えます:

Traceback (most recent call last):
  File "<pyshell#10>", line 1, in <module>
    SetValueEx(a,"Autorun",0,REG_SZ,"cd\\The path that I wantsss.")
WindowsError: [Error 5] Access is denied    

私はpython 3.1とwindows7を使用
しています よろしくお願いします。

4

1 に答える 1

1

SetValueExを使用し、次のようにKEY_WRITEまたはKEY_ALL_ACCESSのいずれかの適切なアクセス権でキーを開く必要があります。

from winreg import*

a=OpenKey(HKEY_CURRENT_USER,"Software\\Microsoft\\Command Processor",0,KEY_WRITE)
SetValueEx(a,"Autorun",0,REG_SZ,"cd\\The path that I wantsss.")
CloseKey(a)
于 2012-08-13T21:43:21.703 に答える