Skip to content

Instantly share code, notes, and snippets.

@gainskills
Last active November 4, 2016 12:36
Show Gist options
  • Save gainskills/e55e87330c662ad1f27a18563684e12c to your computer and use it in GitHub Desktop.
Save gainskills/e55e87330c662ad1f27a18563684e12c to your computer and use it in GitHub Desktop.
Python copy folders/kill process/start service
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