当前位置:   article > 正文

python工具 - 程序员开机要做的事_python实现调用winlogon中的defaultpassword

python实现调用winlogon中的defaultpassword

定时开机

如何设置电脑自动开关机

自动登录(权限问题,需手动设置)

  1. 打开注册表,可以选择在“开始菜单”中搜索“regedit”
  2. 依次找到“HKEY_LOCAL_MACHINE SOFTWARE Microsoft Windows NT CurrentVersion Winlogon”项;
  3. 在右边的窗口中创建字符串值:“AutoAdminLogon”,并将其值设为“1”(值为1时启用自动登陆功能,为0时禁用自动登录功能);
  4. 再创建字符串值:“DefaultUserName”,将其键值修改为登录时所用的用户名。
  5. 最后创建字符串值:“DefaultPassword”,将其键值修改为登录时的密码(对应用户名)。

开机自动执行程序并打开项目(利用应用程序的命令行)

autoStart.py

# encoding: utf-8
# -*- coding: utf-8 -*-
import sys
import os
import ctypes
import subprocess

default_encoding = 'utf-8'
if sys.getdefaultencoding() != default_encoding:
   reload(sys)
   sys.setdefaultencoding(default_encoding)

##########################################################################

def setAutoOpenUnity():
    # 使用Unity命令行打开项目
    cmd = ur'C:\"Program Files"\\Unity2018.2.0f2\Editor\\Unity.exe -projectPath D:\proj'
    try:
        subprocess.Popen(cmd.encode('gbk'),stdin=subprocess.PIPE, stderr=subprocess.PIPE,shell=True)
    except subprocess.CalledProcessError as err:
        msg = err.output.replace('\r\n','').decode('gbk')
        print msg

def setAutoOpenVS():
    # 使用VS命令行打开项目
    cmd = ur'C:\"Program Files (x86)"\"Microsoft Visual Studio"\2017\Enterprise\Common7\IDE\devenv.exe D:\proj\proj.sln'
    try:
        subprocess.Popen(cmd.encode('gbk'),stdin=subprocess.PIPE, stderr=subprocess.PIPE,shell=True)
    except subprocess.CalledProcessError as err:
        msg = err.output.replace('\r\n','').decode('gbk')
        print msg


def updateSvn():
    projPaths = [ur'D:\proj1',ur'D:\proj2']

    for path in projPaths:
        if svn_cmd_isSvnPath(path):
            returncode,svnmsg = svn_cmd_update(path)
            if returncode:
                if returncode == 1 or returncode == 3:
                    msg = u'[error] %s\r' % svnmsg
                    print(msg)
                elif returncode == 2:
                    msg = u'[warning] %s\n' % svnmsg
                    print(msg)
            else:
                print(u'svn update succuss!')


PATH_CUR = u''
if getattr(sys, 'frozen', False):
    PATH_CUR = os.path.dirname(sys.executable)
elif __file__:
    PATH_CUR = os.path.dirname(__file__)
# svn_cmd_line命令行工具所在路径
SVN_CMD_LINE_PATH = os.path.join(PATH_CUR.decode('gbk'),ur'svn_cmd_line/bin/')
def _judgeSvnCmdExist():
    if not os.path.exists(SVN_CMD_LINE_PATH+'svn.exe'):
        outstr=u'[error] cannot find svn_cmd_line! path = %s\n'%SVN_CMD_LINE_PATH
        printRed(outstr)
        return False,outstr
    else:
        return True,''

def svn_cmd_isSvnPath(path):
    if _judgeSvnCmdExist()[0]:
        cmd = ur'%ssvn info %s --show-item revision' % (SVN_CMD_LINE_PATH,path)

        si = subprocess.STARTUPINFO()
        si.dwFlags |= subprocess.STARTF_USESHOWWINDOW
        si.wShowWindow = subprocess.SW_HIDE
        returncode=subprocess.call(cmd.encode('gbk'),startupinfo=si)
        return returncode == 0 and True or False
    return False

def svn_cmd_update(path):
    cmdok,msg = _judgeSvnCmdExist()
    if not cmdok:
        return (1,msg)

    # svn update冲突 不会引发异常,retruncode==0; 
    # 这里通过分析output字符串行中‘C  ’前缀 判断是否出现冲突

    returnItems = [
        (0,u''), #没有获取到新内容
        (1,u'svn更新出错! '),
        (2,u'从svn获取到了新的变更,请确认!'),
        (3,u'svn更新遇到了冲突项,请手动处理!')
    ]

    # svn update path -r:版本号 --accept postpone:冲突延迟处理
    cmd = ur'%ssvn update %s -r HEAD --accept postpone' % (SVN_CMD_LINE_PATH,path)
    try:
        si = subprocess.STARTUPINFO()
        si.dwFlags |= subprocess.STARTF_USESHOWWINDOW
        si.wShowWindow = subprocess.SW_HIDE

        output = subprocess.check_output(cmd.encode('gbk'),stdin=subprocess.PIPE, stderr=subprocess.PIPE,startupinfo=si)
        output = output.strip('\r\n')
        if output and str(output):
            print output
            lines = output.split('\r\n')
            noNew = lines and len(lines)<=2 and True or False
            if noNew:
                return returnItems[0]

            for line in lines:
                ret = re.match(r'^C\s+\S+',line.strip())
                if ret:
                    return returnItems[3]

            return returnItems[2]
        return returnItems[0]

    except subprocess.CalledProcessError as err:
        msg = err.output.replace('\r\n','').decode('gbk')
        return (returnItems[1][0],returnItems[1][1]+msg)

##########################################################################
if __name__ == '__main__':
    print(u'[1] update svn.')
    updateSvn()
    print(u'[2] open unity proj.')
    setAutoOpenUnity()
    print(u'[3] open vs proj.')
    setAutoOpenVS()
    print(u'--- End ---')
    exit(0)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129

autoStart.bat

@echo off
python D:\program\autoStart\autoStart.py
pause
  • 1
  • 2
  • 3

autoStart.bat 放到开机启动目录下
开机启动目录:C:\Users\xxx\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

  • svn更新需要依赖svn_cmd_line
  • 修改devenv默认VS版本: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\AppPaths\devenv.exe

svn_cmd_line下载地址

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/71346
推荐阅读
相关标签
  

闽ICP备14008679号