Last active
November 4, 2016 12:36
-
-
Save gainskills/e55e87330c662ad1f27a18563684e12c to your computer and use it in GitHub Desktop.
Python copy folders/kill process/start service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import shutil | |
''' | |
administrator privliedge is needed | |
''' | |
def cpfolder(srcpath, dstpath): | |
try: | |
shutil.copytree(srcpath, dstpath) | |
except FileExistsError: | |
shutil.move(dstpath, dstpath+'_bak') | |
# shutil.rmtree(dstpath) | |
shutil.copytree(srcpath, dstpath) | |
def check_kill_process(pstring): | |
for line in os.popen('tasklist | find "' + pstring + '"'): | |
fields = line.split() | |
pid = fields[1] | |
if pid: | |
print("%s process id is %s" % (pstring, pid)) | |
os.popen('taskkill /F /PID %s' % (pid)) | |
def startservice(servicename): | |
os.popen("net start " + servicename) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment