Click here to Skip to main content
15,921,793 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I tried adding a value from CMD with
VB
REG ADD HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce /t REG_SZ /v test /d C:\Users\xxxx\Desktop\xxx.exe

And that worked perfectly, but when i tried doing the same thing in python with
Python
os.system("REG ADD HKEY_LOCAL_MACHINE\\SOFTWARE\Microsoft\\Windows\\CurrentVersion\\RunOnce /t REG_SZ /v test /d C:\\Users\\xxxx\\Desktop\\xxx.exe")

It returned 0, which according to CMD REG /? Means it's succesfull, but there is no value named "test" in RunOnce, i tried the same thing with
Python
subprocess.call([""])
But it gave the same result, also i executed all scripts as an Administrator.
Posted
Updated 15-Nov-15 5:52am
v2
Comments
PythonHeadBanger 16-Nov-15 15:35pm    
Is python interpreting your string as one big string without line breaks?
Member 12141010 16-Nov-15 16:18pm    
im not sure exactly what do u mean, how can i check that?, also thank you for the response
PythonHeadBanger 16-Nov-15 16:33pm    
Ah okay, it was the width of my browser that started new lines in RED ADD string. See solution below:

1 solution

The Following link shows that the default return value is 0. If you added some more code somebody would probably be able to help you more but... With the limited info given , I can only state that yeah, you're getting "0" but thats the default return value.


https://docs.python.org/2/library/os.html

os.system(command)
Execute the command (a string) in a subshell. This is implemented by calling the Standard C function system(), and has the same limitations. Changes to sys.stdin, etc. are not reflected in the environment of the executed command.

On Unix, the return value is the exit status of the process encoded in the format specified for wait(). Note that POSIX does not specify the meaning of the return value of the C system() function, so the return value of the Python function is system-dependent.

On Windows, the return value is that returned by the system shell after running command, given by the Windows environment variable COMSPEC: on command.com systems (Windows 95, 98 and ME) this is always 0; on cmd.exe systems (Windows NT, 2000 and XP) this is the exit status of the command run; on systems using a non-native shell, consult your shell documentation.

The subprocess module provides more powerful facilities for spawning new processes and retrieving their results; using that module is preferable to using this function. See the Replacing Older Functions with the subprocess Module section in the subprocess documentation for some helpful recipes.

Availability: Unix, Windows.
</pre>
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900