Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

Need some help with python coding


fuser's Avatar
Member
0 -1

I'm currently writing a prank program in python for linux.

The main idea is that the program should start up by itself, asks the user to press enter, claims it is destroying the operating system( when it's not ), and shuts it down.

I found several issues concerning my program.

a) the user has to run the program itself, in this case they have to go to BASH and type "python program.py". I want my program to be a self - executing program.

b) This is concerning the shutdown part as a user has to be root. so i tried to do something like os.system("sudo su") (i'm running ubuntu) but when i tested it, it simply switches to root and doesn't begin the shutdown, i exited back to a normal user shell, but then it says: shutdown:user must be root.

so i tried os.system("sudo su && shutdown -r -h 5"), but it seems to yield the same result.

so i'm thinking of a way for the user to simply switch to root, and then automatically starts shutting down without the user entering the shutdown command.

Does anyone here know what i should add on my code, maybe along with some code and websites.

I'm going to work on the windows version as soon i manage to finish this one first.


ghost's Avatar
0 0

fuser wrote:

a) the user has to run the program itself, in this case they have to go to BASH and type "python program.py". I want my program to be a self - executing program.

autorun? That's easy to google…

b) This is concerning the shutdown part as a user has to be root. so i tried to do something like os.system("sudo su") (i'm running ubuntu) but when i tested it, it simply switches to root and doesn't begin the shutdown, i exited back to a normal user shell, but then it says: shutdown:user must be root.

They'd still have to enter their password for the sudo command, right?

so i tried os.system("sudo su && shutdown -r -h 5"), but it seems to yield the same result.

I think you should do 2 commands for this…though it might not be necessary, idk, but it might..

os.system("sudo su") os.system("shutdown -r -h 5")

I'm going to work on the windows version as soon i manage to finish this one first.

That will be really easy…

"Everything in this [post] could be wrong." – Modded Illusions quote :)


fuser's Avatar
Member
0 -1

yeah. the user has to enter thier own password. ( I know cuz i tested it several times)

The main idea is that, well, the program asks the user to enter the root password, after the password is entered and the user changes to root, the program would then automatically shuts down the computer without any user input

The main problem with this app is that right now, it simply switches to root and that's it.


ghost's Avatar
0 0

Wait…you're trying to make an app that the user trusts and then have shutdown code in it? They trust it, so they enter their password and get shutdown? Hmm…I still don't know what you need help with…


ynori7's Avatar
Future Emperor of Earth
0 0

as far as getting the program to auto run, just make it a scheduled task. i dont use linux, but i'm sure there must be an easy way to do that. in windows it's in the control panel.

as far as writing the windows version, i'm pretty sure the built in shutdown command should work fine, but if it doesnt, i have a nice batch file i could give you that'll do the job.


ghost's Avatar
0 0

for windows: have it edit the registry and make itself autostart at runtime OR put it in the scheduled tasks There is a command line way for both (i've done it)

for linux: put it in the start up OR put it into cron again both are command line

as for the shutdown, you may be able to do it with just os.system(sudo shutdown) but that will require a password. os.system(init 0) may work without a password tho, tbh, in not sure tho


SET's Avatar

SET

Peumonoultramicroscopicsilico
0 0

windows will be crazy easy just make a windows form maximize it remove control buttons an make it look like a Console run shutdown.exe -t 1 -s

could be done in 2-5 minutes coding wise


richohealey's Avatar
Python Ninja
0 0

ok.. for one.. do you know how sudo works??

os.system("sudo shutdown -h now")

and then.. add to the first line,

#!/usr/local/bin/python

or #!/bin/env python

essentially it's the place where it can find python…

i forgot the rest.. hit me up on msn if you need more


fuser's Avatar
Member
0 -1

oh yeah. totally forgot about "sudo app /service " i use it all the time, but it escaped me during coding as it keeps in requesting to be root. thanks