Pergunta

So I'm trying to change the ntp server settings in Windows (XP and 7) using the following:

import subprocess
subprocess.call(['net', 'stop', 'w32time'])
subprocess.call(['reg', 'add','HKLM\Software\Microsoft\Windows\CurrentVersion\DateTime\Servers', '/f /v \"0\" /t REG_SZ /d \"ntp.craven.k12.nc.us\"'])
subprocess.call(['reg', 'add', 'HKLM\Software\Microsoft\Windows\CurrentVersion\DateTime\Servers', '/f /v \"(Default)\" /t REG_SZ /d \"0\"'])
subprocess.call(['net', 'start', 'w32time'])
subprocess.call(['w32tm', '/resync'])

But this fails miserably. I'm sure the problem lies in how I'm formatting the parameters, but I have yet to come upon how to do it properly.

Foi útil?

Solução

Your last arguments are not splitted. You probably need to replace '/f /v \"0\" /t REG_SZ ...' with ] + ['/f', '/v', '0', '/t', 'REG_SZ'] + [...].

As an alternative, pass the whole command as a string (as you would on the command line).

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top