一,用内置的winreg(推荐)

import winreg
def get_desktop():
    key = winreg.OpenKey(winreg.HKEY_CURRENT_USER,\
                          r'Software\Microsoft\Windows\CurrentVersion\Explorer\ShellFolders',)
    return winreg.QueryValueEx(key, "Desktop")[0]

二,需要win32扩展

import win32api,win32con
def get_desktop():
    key =win32api.RegOpenKey(win32con.HKEY_CURRENT_USER,\
                              r'Software\Microsoft\Windows\CurrentVersion\Explorer\ShellFolders',\
                             0,win32con.KEY_READ)
    return win32api.RegQueryValueEx(key,'Desktop')[0]

三,也需要win32扩展

from win32com.shell import shell, shellcon
def GetDesktopPath():
    ilist =shell.SHGetSpecialFolderLocation(0, shellcon.CSIDL_DESKTOP)
    return shell.SHGetPathFromIDList(ilist)

四,需要内置的os

该方法在用户改变了桌面路径后,会失效

import os
def GetDesktopPath():
    return os.path.join(os.path.expanduser("~"), 'Desktop')

python获取当前系统的桌面的路径的更多相关文章

  1. python,winreg,获取当前系统的桌面绝对路径

    import winreg import os def main(): new_path = os.path.join(desktop_path(), 'aaa.xlsx') # 结果为:C:\\Us ...

  2. Python获取当前系统时间

    Python获取当前系统时间 import time #返回当前时间 def GetNowTime():     return time.strftime("%Y-%m-%d %H:%M:% ...

  3. C# - 获取windows系统特殊文件夹路径

    一.路径分类 1.绝对路径 完整路径,从磁盘符号开始,如:C:\Windows 2.相对路径 以当前路径为起点,不包含磁盘符号,通常使用“..\”符号来访问上级目录中的文件或文件夹. ../Windo ...

  4. 使用Python获取Linux系统的各种信息

    哪个Python版本? 当我提及Python,所指的就是CPython 2(准确的是2.7).我会显式提醒那些相同的代码在CPython 3 (3.3)上是不工作的,以及提供一份解释不同之处的备选代码 ...

  5. (26)Python获取某个文件存放的相对路径(更改任意目录下保持不变)

    import os import platform def getSeparator(): ''' 获取不同平台下的斜杠符号 :return: Created by Wu Yongcong 2017- ...

  6. 转:python获取linux系统及性能信息

    原文:http://amitsaha.github.io/site/notes/articles/python_linux/article.html In this article, we will ...

  7. 【转】Python获取当前系统时间

    转自:https://www.cnblogs.com/-ldzwzj-1991/p/5889629.html 取得时间相关的信息的话,要用到python time模块,python time模块里面有 ...

  8. [python]获取当前路径用来构造相对路径的几种方法

    print('getcwd', os.getcwd()) print('sysargv', sys.argv) print('realpath', os.path.realpath(sys.argv[ ...

  9. 【C#】获取当前系统桌面、我的照片、我的文档等路径

    获取当前系统桌面.我的照片.我的文档等路径   using System; using System.Collections.Generic; using System.ComponentModel; ...

随机推荐

  1. soj1011. Lenny's Lucky Lotto

    1011. Lenny's Lucky Lotto Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description Lenny like ...

  2. 谁说码农不懂浪漫?(js写的'老婆生日快乐'特效)

    一直被老婆抱怨不懂浪漫,老婆的生日又来了,老婆指着闺蜜空间上贴的老公做的胡萝卜心形浪漫晚餐告诉我:必须送她一份用心的礼物.我绞尽脑汁想出这么一法子,还是得用我们码农的独特方式,经过一天多的努力,终于做 ...

  3. 【leetcode 简单】 第七十三题 丑数

    编写一个程序判断给定的数是否为丑数. 丑数就是只包含质因数 2, 3, 5 的正整数. 示例 1: 输入: 6 输出: true 解释: 6 = 2 × 3 示例 2: 输入: 8 输出: true ...

  4. TI的H264 SOC方案

    TI的H264 SOC方案是目前常用的视讯解决方案,TI针对视频会议,视频监控,视频存储等场景细化需求并优化了H264技术. 1. TI H.264背景 如今视频压缩技术在视频领域有非常多的应用需求. ...

  5. ASP.NET mvc下在Controller下action的跳转方式

    在ASP.NET mvc下,action有多种挑战方式: return RedirectToAction("Index");//一个参数时在本Controller下 如果Redir ...

  6. http Get和Post请求方式

      string postURL ="http://xxxxx.ashx"; List<string> paramName = new List<string&g ...

  7. 未来人类T5 安装win10,ubuntu双系统

    1.首先确保win10已经安装,u盘中已刻录好系统,下载好英伟达最新驱动保存在u盘中,压缩100g的磁盘空间给ubuntu. 2.设置双显卡模式,重启时按F7选择进入u盘启动. 3.进入安装界面,选择 ...

  8. Electron build 无法下载 winCodeSign 等资源

    将 7z 文件下载到 以下 cache 目录并解压 macOS: ~/Library/Caches/electron-builder Linux: ~/.cache/electron-builder ...

  9. Hibernate5笔记2--单表的增删改查操作

    单表的增删改查操作: (1)定义获取Session和SessionFactory的工具类: package com.tongji.utils; import org.hibernate.Session ...

  10. vue写出放大镜的效果

    用vue写出放大镜查看图片的效果. 安装 npm install vue2.0-zoom 引入 import imgZoom from 'vue2.0-zoom' 组件 components: { i ...