当前位置: 首页>>代码示例>>Python>>正文


Python shell.IsUserAnAdmin方法代码示例

本文整理汇总了Python中win32com.shell.shell.IsUserAnAdmin方法的典型用法代码示例。如果您正苦于以下问题:Python shell.IsUserAnAdmin方法的具体用法?Python shell.IsUserAnAdmin怎么用?Python shell.IsUserAnAdmin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在win32com.shell.shell的用法示例。


在下文中一共展示了shell.IsUserAnAdmin方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: check_is_admin

# 需要导入模块: from win32com.shell import shell [as 别名]
# 或者: from win32com.shell.shell import IsUserAnAdmin [as 别名]
def check_is_admin():
    global _is_admin
    if _is_admin is None:
        from win32com.shell.shell import IsUserAnAdmin
        import pythoncom
        try:
            _is_admin = IsUserAnAdmin()
        except pythoncom.com_error, exc:
            if exc.hresult != winerror.E_NOTIMPL:
                raise
            # not impl on this platform - must be old - assume is admin
            _is_admin = True 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:14,代码来源:pywin32_testutil.py

示例2: is_user_an_admin

# 需要导入模块: from win32com.shell import shell [as 别名]
# 或者: from win32com.shell.shell import IsUserAnAdmin [as 别名]
def is_user_an_admin():
    if not shell.IsUserAnAdmin():
        print("Please run this program as administrator")
        os.system("pause")
        sys.exit(0) 
开发者ID:yarox24,项目名称:attack_monitor,代码行数:7,代码来源:madvr.py

示例3: is_elevated

# 需要导入模块: from win32com.shell import shell [as 别名]
# 或者: from win32com.shell.shell import IsUserAnAdmin [as 别名]
def is_elevated():
    return shell.IsUserAnAdmin() 
开发者ID:Peter92,项目名称:MouseTracks,代码行数:4,代码来源:main.py

示例4: RegisterPythonServer

# 需要导入模块: from win32com.shell import shell [as 别名]
# 或者: from win32com.shell.shell import IsUserAnAdmin [as 别名]
def RegisterPythonServer(filename, progids=None, verbose=0):
    if progids:
        if isinstance(progids, basestring):
            progids = [progids]
        # we know the CLSIDs we need, but we might not be an admin user
        # and otherwise unable to register them.  So as long as the progids
        # exist and the DLL points at our version, assume it already is.
        why_not = None
        for progid in progids:
            try:
                clsid = pythoncom.MakeIID(progid)
            except pythoncom.com_error:
                # no progid - not registered.
                break
            # have a CLSID - open it.
            try:
                HKCR = _winreg.HKEY_CLASSES_ROOT
                hk = _winreg.OpenKey(HKCR, "CLSID\\%s" % clsid)
                dll = _winreg.QueryValue(hk, "InprocServer32")
            except WindowsError:
                # no CLSID or InProcServer32 - not good!
                break
            if os.path.basename(dll) != os.path.basename(pythoncom.__file__):
                why_not = "%r is registered against a different Python version (%s)" % (progid, dll)
                break
        else:
            #print "Skipping registration of '%s' - already registered" % filename
            return
    # needs registration - see if its likely!
    try:
        from win32com.shell.shell import IsUserAnAdmin
    except ImportError:
        print "Can't import win32com.shell - no idea if you are an admin or not?"
        is_admin = False
    else:
        try:
            is_admin = IsUserAnAdmin()
        except pythoncom.com_error:
            # old, less-secure OS - assume *is* admin.
            is_admin = True
    if not is_admin:
        msg = "%r isn't registered, but I'm not an administrator who can register it." % progids[0]
        if why_not:
            msg += "\n(registration check failed as %s)" % why_not
        # throw a normal "class not registered" exception - we don't report
        # them the same way as "real" errors.
        raise pythoncom.com_error(winerror.CO_E_CLASSSTRING, msg, None, -1)
    # so theoretically we are able to register it.
    cmd = '%s "%s" --unattended > nul 2>&1' % (win32api.GetModuleFileName(0), filename)
    if verbose:
        print "Registering engine", filename
#       print cmd
    rc = os.system(cmd)
    if rc:
        print "Registration command was:"
        print cmd
        raise RuntimeError("Registration of engine '%s' failed" % filename) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:59,代码来源:util.py


注:本文中的win32com.shell.shell.IsUserAnAdmin方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。