自己主动检測&后台复制光盘内容
原理:利用python的win32模块,注冊服务,让代码在后台执行,检測光盘并复制文件
启动的方法就是直接在cmd下,main.py install ,然后去windows 的服务下就能够看到The smallestpossible Python Service 这个服务,你能够启动,停止。还能够设置成开机自己主动启动。
启动服务后,会自己主动检測光盘并在后台复制文件
main.py
import win32serviceutil
import win32service
import win32event
import CopyDvd2Hard
class SmallestPythonService(win32serviceutil.ServiceFramework):
_svc_name_ = "SmallestPythonService"
_svc_display_name_ = "The smallest possible Python Service"
def __init__(self, args):
win32serviceutil.ServiceFramework.__init__(self, args)
# Create an event which we will use to wait on.
# The "service stop" request will set this event.
self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)
def SvcStop(self):
# Before we do anything, tell the SCM we are starting the stop process.
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
# And set my event.
win32event.SetEvent(self.hWaitStop)
def SvcDoRun(self):
#实际执行代码#
CopyDvd2Hard.copydvd2hard()
win32event.WaitForSingleObject(self.hWaitStop, win32event.INFINITE)
if __name__=='__main__':
win32serviceutil.HandleCommandLine(SmallestPythonService)
CopyDvd2Hard.py
__author__ = 'M'
import os
import win32file
import shutil
import time
def copydvd2hard(dstdir='temp'):
#检測本地的最后一个光驱和硬盘分区
letters = [l.upper() + ':' for l in 'abcdefghijklmnopqrstuvwxyz']
cdrom = ''
harddrive = ''
for drive in letters:
if win32file.GetDriveType(drive) == 3:
harddrive = drive
if win32file.GetDriveType(drive) == 5:
cdrom = drive
cdrom += '/'
harddrive = harddrive + '/' + dstdir
#检測光驱内是否有光盘,等待光盘插入
while os.system('cd /d' + cdrom):
time.sleep(5)
#复制文件
shutil.copytree(cdrom, harddrive)
if __name__ == '__main__':
copydvd2hard()自己主动检測&后台复制光盘内容的更多相关文章
- Android Studio代码自己主动检測错误提示
Android Studio的代码自己主动检測的错误提示方式感觉有点奇葩.和Eclipse区别非常大,Eclipse检測到某个资源文件找不到或者错误,都会在Project中相应的文件前面打叉.可是An ...
- 从头认识Spring-2.7 自己主动检測Bean(1)-@Component @Repository @Service @Controller
这一章节我们来讨论一下自己主动检測Bean. 1.domain 厨师类: package com.raylee.my_new_spring.my_new_spring.ch02.topic_1_19; ...
- 使用UIDataDetectorTypes自己主动检測电话、网址和邮箱
支付宝公布最新版本号9.0.再一次引发一场撕逼大战.微信说支付宝抄袭了它.支付宝说微信一直都在抄袭自己.在我看来.微信和支付宝都抄袭了对方.对于大佬们的抄袭.我们也是司空见惯了. 支付宝这一次更新,真 ...
- Android自己主动检測版本号及自己主动升级
步骤: 1.检測当前版本号的信息AndroidManifest.xml-->manifest-->android:versionName. 2.从server获取版本号号(版本号号存在于x ...
- 从头认识Spring-2.7 自己主动检測Bean(2)-过滤器<context:include-filter/>
这一章节我们来讨论一下过滤器<context:include-filter/>的使用. 1.domain Person接口: package com.raylee.my_new_sprin ...
- MySQL高可用之组复制技术(2):配置单主模型的组复制
MySQL组复制系列文章: MySQL组复制大纲 MySQL组复制(1):组复制技术简介 MySQL组复制(2):配置单主模型的组复制 MySQL组复制(3):配置多主模型的组复制 MySQL组复制( ...
- MySQL高可用之组复制技术(3):配置多主模型的组复制
MySQL组复制系列文章: MySQL组复制大纲 MySQL组复制(1):组复制技术简介 MySQL组复制(2):配置单主模型的组复制 MySQL组复制(3):配置多主模型的组复制 MySQL组复制( ...
- Zclip复制页面内容到剪贴板兼容各浏览器
Zclip:复制页面内容到剪贴板兼容各浏览器 WEB开发中,要让用户复制页面中的一段代码.URL地址等信息,为了避免用户拖动鼠标再进行右键复制操作而可能出现的差错,我们可以直接在页面中放置一个复制按钮 ...
- C语言memmove()函数: 复制内存内容(可以重叠的内存块)
头文件:#include <string.h> memmove() 用来复制内存内容,其原型为: void * memmove(void *dest, const void *src, s ...
随机推荐
- fstrict-aliasing
承如“optimization blocks”文中所述,由于相同的指针可能指向相关的内存区,因此编译器将不做过分的优化…… 特意搜了下编译器在不同的优化等级下都有哪些默认优化,因此有了此记录(比较长, ...
- Oracle行列转换的思考与总结
最近几天一直在弄Oracle-SQL的问题,涉及到了一些平时没有用到的东西,也因此而在这里郁闷了好久.现在问题得到了解决虽说不算完美.但是还是和大家一起分享一下. 行列转换之一:sum(case wh ...
- oracle当前月添加一列显示前几个月的累计值
create table test_leiji(rpt_month_id number(8), current_month NUMBER(12,2)); ...
- linux mint 19解决 输入法问题
安装搜狗后出现 You're currently running Fcitx with GUI, but fcitx-configtool couldn't be found, the package ...
- 编辑框添加灰色提示字(html+VC)
Html中添加灰色提示字,使用属性placeholder即可! <input type="text" placeholder="要显示的文字"> 但 ...
- mysql数据库中,查看数据库的字符集(所有库的字符集或者某个特定库的字符集)
需求描述: mysql中,想要查看某个数据库的字符集.通过information_schma模式下的schemata表来查询 环境描述: mysql版本:5.7.21-log 操作过程: 1.查看in ...
- mybatis由浅入深day02_2一对一查询_2.3方法二:resultMap_resultType和resultMap实现一对一查询小结
2.3 方法二:resultMap 使用resultMap,定义专门的resultMap用于映射一对一查询结果. 2.3.1 sql语句 同resultType实现的sql SELECT orders ...
- 7 -- Spring的基本用法 -- 4... 使用 Spring 容器:Spring 容器BeanFactory、ApplicationContext;ApplicationContext 的国际化支持;ApplicationContext 的事件机制;让Bean获取Spring容器;Spring容器中的Bean
7.4 使用 Spring 容器 Spring 有两个核心接口:BeanFactory 和 ApplicationContext,其中ApplicationContext 是 BeanFactory ...
- EasyUI 每页展示100条数据
$(function() { //$("#bgAddTime").datebox("setValue", getTimeString()+" 00:0 ...
- CALayer的position,anchorPoint属性 与UIView的frame 属性
彻底理解CALayer的position,anchorPoint属性 与UIView的frame 属性 一.position,anchorPoint两者都是CALayer的属性,都是CGPoint点 ...