精华内容
下载资源
问答
  • win7取得管理员权限

    2014-07-07 10:13:24
    首先先停止并禁用Windows Modules Install服务 2 把“管理员取得所有权注册表文件”导入注册表 管理员取得所有权 注册表文件 rar 446 Bytes 下3 对C: Windows servicing Packages这一文件夹 右键“取得管理员权限4...
  • MFC开发的程序,我知道可以通过配置清单文件的UAC执行级别来提示程序的权限.但问题时这样的配置在win7一定会提示UAC...在不关闭系统UAC的情况下,有没有办法不弹出UAC对话框或者不设置UAC级别,依旧可以拥有管理员权限呢?
  • 可以支持在win7下开启管理员权限,做一些高权限的事,比如删掉不能删的东西,不用时可关闭
  • Win7旗舰版如何激活超级管理员权限

    千次阅读 2016-11-28 23:40:07
    Win7旗舰版中,管理员账号Administrator是默认关闭的,而在运行一些软件,或对系统文件夹中的内容进行修改时,往往需要取得管理员权限才行。虽然在Win7的“控制面板-用户账户”中可以将账户类型更改为“管理员”,...

    Win7旗舰版中,管理员账号Administrator是默认关闭的,而在运行一些软件,或对系统文件夹中的内容进行修改时,往往需要取得管理员权限才行。虽然在Win7控制面板-用户账户中可以将账户类型更改为管理员,但此管理员非彼管理员,只是徒有虚名而已,在进行受限操作时,与普通用户的区别仅仅是省去了输入密码的步骤。因此,要想获得Win7旗舰版的所有权限,就要激活沉睡的超级管理员”Administrator账户。

    下面三步搞定:

    1 获得超级管理员权限最简单的办法是,打开Win7旗舰版的控制面板,在系统和安全-管理工具目录下找到并打开计算机管理


    2 在计算机管理窗口左侧展开本地用户和组目录,点击用户文件夹,窗口右侧会列出当前系统中的所有账户。


    3 在默认情况下,Administrator账户是处于禁用状态的,用鼠标右键点击“Administrator”账户,打开属性设置对话框,取消账户已禁用前的对勾,点击确定保存设置后,就可以将Administrator账户激活了。


        Administrator账户激活后,只要注销当前的登录账户,并选择使用Administrator登录Win7旗舰版,就可以获得所有管理员权限了。如果以后只用Administrator登录Win7的话,建议大家再按照以上的方法将其它账户禁用。

    展开全文
  • 最近恰逢公司更换新PC机,重装了Win7...您需要提供管理员权限 拒绝访问 等等…… 这种情况,我宁愿暂时放弃安全性,来提高便利性。 关闭UAC是一个方法,但未必有效,其实有个更简单的方法。 找到C:\Windows\explorer

    最近恰逢公司更换新PC机,重装了Win7,然后有好多东西要复制到C盘,或者是Program Files,或者是system32,每次都会遇到诸如:

    您的权限不足,请点击继续来获得权限

    您需要提供管理员权限

    拒绝访问

    等等……


    这种情况,我宁愿暂时放弃安全性,来提高便利性。

    关闭UAC是一个方法,但未必有效,其实有个更简单的方法。

    找到C:\Windows\explorer.exe ,右键->属性->安全->高级->所有者, 然后将explorer.exe的所有者修改为Administrators,然后安全界面的权限改为完全控制。


    重启电脑后,将会体验到XP一般的便利……

    展开全文
  • win7系统如何设置管理员权限 在控制面板→用户账户→管理其他账户→Aadministrator→双击启用→启用之后重启电脑→选择名字为Aadministrator的账户→进去以后你就是管理员,就有了管理员权限,这时候你可以选择删除...
  • Vista 和 Windows 7 操作系统为了加强安全,增加了 UAC(用户账户控制) 的机制,如果 UAC 被打开,用户即使是以管理员权限登录,其应用程序默认情况下也无法对系统目录,系统注册表等可能影响系统运行的设置进行写...

    Vista 和 Windows 7 操作系统为了加强安全,增加了 UAC(用户账户控制) 的机制,如果 UAC 被打开,用户即使是以管理员权限登录,其应用程序默认情况下也无法对系统目录,系统注册表等可能影响系统运行的设置进行写操作。这个机制大大增强了系统的安全性,但对应用程序开发者来说,我们不能强迫用户去关闭UAC,但有时我们开发的应用程序又需要以 Administrator 的方式运行,即 Win7 中 以 as administrator 方式运行,那么我们怎么来实现这样的功能呢?

    我们在 win7 下运行一些安装程序时,会发现首先弹出一个对话框,让用户确认是否同意允许这个程序改变你的计算机配置,但我们编写的应用程序默认是不会弹出这个提示的,也无法以管理员权限运行。本文介绍了 C# 程序如何设置来提示用户以管理员权限运行。

    首先在项目中增加一个 Application Manifest File

    默认的配置如下:

    <?xml version="1.0" encoding="utf-8"?>
    <asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" 
    xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
      <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
        <security>
          <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
            <!-- UAC Manifest Options
                If you want to change the Windows User Account Control level replace the
                requestedExecutionLevel node with one of the following.
            <requestedExecutionLevel  level="asInvoker" uiAccess="false" />
            <requestedExecutionLevel  level="requireAdministrator" uiAccess="false" />
            <requestedExecutionLevel  level="highestAvailable" uiAccess="false" />
                If you want to utilize File and Registry Virtualization for backward
                compatibility then delete the requestedExecutionLevel node.
            -->
            <requestedExecutionLevel level="asInvoker" uiAccess="false" />
          </requestedPrivileges>
        </security>
      </trustInfo>
    </asmv1:assembly>
    

    我们可以看到这个配置中有一个 requestedExecutionLevel 项,这个项用于配置当前应用请求的执行权限级别。这个项有3个值可供选择,如下表所示:

    Value Description Comment
    asInvoker The application runs with the same access token as the parent process. Recommended for standard user applications. Do refractoring with internal elevation points, as per the guidance provided earlier in this document.
    highestAvailable The application runs with the highest privileges the current user can obtain. Recommended for mixed-mode applications. Plan to refractor the application in a future release.
    requireAdministrator The application runs only for administrators and requires that the application be launched with the full access token of an administrator. Recommended for administrator only applications. Internal elevation points are not needed. The application is already running elevated.

    asInvoker : 如果选这个,应用程序就是以当前的权限运行。

    highestAvailable: 这个是以当前用户可以获得的最高权限运行。

    requireAdministrator: 这个是仅以系统管理员权限运行。

    默认情况下是 asInvoker。

    highestAvailable 和 requireAdministrator 这两个选项都可以提示用户获取系统管理员权限。那么这两个选项的区别在哪里呢?

    他们的区别在于,如果我们不是以管理员帐号登录,那么如果应用程序设置为 requireAdministrator ,那么应用程序就直接运行失败,无法启动。而如果设置为 highestAvailable,则应用程序可以运行成功,但是是以当前帐号的权限运行而不是系统管理员权限运行。如果我们希望程序在非管理员帐号登录时也可以运行(这种情况下应该某些功能受限制) ,那么建议采用 highestAvailable 来配置。

    关于requestedExecutionLevel 设置的权威文档请参考下面链接:

    Create and Embed an Application Manifest (UAC)

    下面是修改后的配置文件:

    <?xml version="1.0" encoding="utf-8"?>
    <asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" 
    xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
      <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
        <security>
          <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
            <!-- UAC Manifest Options
                If you want to change the Windows User Account Control level replace the 
                requestedExecutionLevel node with one of the following.
            <requestedExecutionLevel  level="asInvoker" uiAccess="false" />
            <requestedExecutionLevel  level="requireAdministrator" uiAccess="false" />
            <requestedExecutionLevel  level="highestAvailable" uiAccess="false" />
                If you want to utilize File and Registry Virtualization for backward 
                compatibility then delete the requestedExecutionLevel node.
            -->
            <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
          </requestedPrivileges>
        </security>
      </trustInfo>
    </asmv1:assembly>
    
    配置文件修改后,我们运行应用程序,就会首先弹出这样一个提示框,点 Yes 后,程序才可以继续运行,并且获得系统管理员的权限。
    .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; }

    下面再来看看程序如何知道当前运行在系统管理员权限还是非系统管理员权限:

            public static bool IsAdministrator()
            {
                WindowsIdentity identity = WindowsIdentity.GetCurrent();
                WindowsPrincipal principal = new WindowsPrincipal(identity);
                return principal.IsInRole(WindowsBuiltInRole.Administrator);
            }
    .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; }

    这段代码可以用于判断当前程序是否运行在系统管理员权限下。如果配置为 asInvoker,在win7 下,这个函数会返回 false ,如果是 requireAdministrator  则返回 true。

    转载于:https://www.cnblogs.com/shenchao/archive/2013/03/05/2944660.html

    展开全文
  • #include <windows.h>#include <tchar.h>#include <strsafe.h>#include <aclapi.h>#include <stdio.h>...#pragma comment(lib, "advapi32.lib") ...TCHAR szSvcName...

    #include <windows.h>
    #include <tchar.h>
    #include <strsafe.h>
    #include <aclapi.h>
    #include <stdio.h>

    #pragma comment(lib, "advapi32.lib")

    TCHAR szCommand[10];
    TCHAR szSvcName[80];

    SC_HANDLE schSCManager;
    SC_HANDLE schService;

    VOID __stdcall DisplayUsage(void);

    VOID __stdcall DoStartSvc(void);
    VOID __stdcall DoUpdateSvcDacl(void);
    VOID __stdcall DoStopSvc(void);

    BOOL __stdcall StopDependentServices(void);

    //
    // Purpose:
    // Entry point function. Executes specified command from user.
    //
    // Parameters:
    // Command-line syntax is: svccontrol [command] [service_name]
    //
    // Return value:
    // None
    //
    void _tmain(int argc, TCHAR *argv[])
    {
    printf("\n");
    if( argc != 3 )
    {
    printf("ERROR: Incorrect number of arguments\n\n");
    DisplayUsage();
    return;
    }

    StringCchCopy(szCommand, 10, argv[1]);
    StringCchCopy(szSvcName, 80, argv[2]);

    if (lstrcmpi( szCommand, TEXT("start")) == 0 )
    DoStartSvc();
    else if (lstrcmpi( szCommand, TEXT("dacl")) == 0 )
    DoUpdateSvcDacl();
    else if (lstrcmpi( szCommand, TEXT("stop")) == 0 )
    DoStopSvc();
    else
    {
    _tprintf(TEXT("Unknown command (%s)\n\n"), szCommand);
    DisplayUsage();
    }
    }

    VOID __stdcall DisplayUsage()
    {
    printf("Description:\n");
    printf("\tCommand-line tool that controls a service.\n\n");
    printf("Usage:\n");
    printf("\tsvccontrol [command] [service_name]\n\n");
    printf("\t[command]\n");
    printf("\t start\n");
    printf("\t dacl\n");
    printf("\t stop\n");
    }

    //
    // Purpose:
    // Starts the service if possible.
    //
    // Parameters:
    // None
    //
    // Return value:
    // None
    //
    VOID __stdcall DoStartSvc()
    {
    SERVICE_STATUS_PROCESS ssStatus;
    DWORD dwOldCheckPoint;
    DWORD dwStartTickCount;
    DWORD dwWaitTime;
    DWORD dwBytesNeeded;

    // Get a handle to the SCM database.

    schSCManager = OpenSCManager(
    NULL, // local computer
    NULL, // servicesActive database
    STANDARD_RIGHTS_READ |
    SC_MANAGER_CONNECT |
    SC_MANAGER_ENUMERATE_SERVICE ); // full access rights

    if (NULL == schSCManager)
    {
    printf("OpenSCManager failed (%d)\n", GetLastError());
    return;
    }

    // Get a handle to the service.

    schService = OpenService(
    schSCManager, // SCM database
    szSvcName, // name of service
    SERVICE_QUERY_STATUS | SERVICE_START); // full access

    if (schService == NULL)
    {
    printf("OpenService failed (%d)\n", GetLastError());
    CloseServiceHandle(schSCManager);
    return;
    }

    // Check the status in case the service is not stopped.

    if (!QueryServiceStatusEx(
    schService, // handle to service
    SC_STATUS_PROCESS_INFO, // information level
    (LPBYTE) &ssStatus, // address of structure
    sizeof(SERVICE_STATUS_PROCESS), // size of structure
    &dwBytesNeeded ) ) // size needed if buffer is too small
    {
    printf("QueryServiceStatusEx failed (%d)\n", GetLastError());
    CloseServiceHandle(schService);
    CloseServiceHandle(schSCManager);
    return;
    }

    // Check if the service is already running. It would be possible
    // to stop the service here, but for simplicity this example just returns.

    if(ssStatus.dwCurrentState != SERVICE_STOPPED && ssStatus.dwCurrentState != SERVICE_STOP_PENDING)
    {
    printf("Cannot start the service because it is already running\n");
    CloseServiceHandle(schService);
    CloseServiceHandle(schSCManager);
    return;
    }

    // Save the tick count and initial checkpoint.

    dwStartTickCount = GetTickCount();
    dwOldCheckPoint = ssStatus.dwCheckPoint;

    // Wait for the service to stop before attempting to start it.

    while (ssStatus.dwCurrentState == SERVICE_STOP_PENDING)
    {
    // Do not wait longer than the wait hint. A good interval is
    // one-tenth of the wait hint but not less than 1 second
    // and not more than 10 seconds.

    dwWaitTime = ssStatus.dwWaitHint / 10;

    if( dwWaitTime < 1000 )
    dwWaitTime = 1000;
    else if ( dwWaitTime > 10000 )
    dwWaitTime = 10000;

    Sleep( dwWaitTime );

    // Check the status until the service is no longer stop pending.

    if (!QueryServiceStatusEx(
    schService, // handle to service
    SC_STATUS_PROCESS_INFO, // information level
    (LPBYTE) &ssStatus, // address of structure
    sizeof(SERVICE_STATUS_PROCESS), // size of structure
    &dwBytesNeeded ) ) // size needed if buffer is too small
    {
    printf("QueryServiceStatusEx failed (%d)\n", GetLastError());
    CloseServiceHandle(schService);
    CloseServiceHandle(schSCManager);
    return;
    }

    if ( ssStatus.dwCheckPoint > dwOldCheckPoint )
    {
    // Continue to wait and check.

    dwStartTickCount = GetTickCount();
    dwOldCheckPoint = ssStatus.dwCheckPoint;
    }
    else
    {
    if(GetTickCount()-dwStartTickCount > ssStatus.dwWaitHint)
    {
    printf("Timeout waiting for service to stop\n");
    CloseServiceHandle(schService);
    CloseServiceHandle(schSCManager);
    return;
    }
    }
    }

    // Attempt to start the service.

    if (!StartService(
    schService, // handle to service
    0, // number of arguments
    NULL) ) // no arguments
    {
    printf("StartService failed (%d)\n", GetLastError());
    CloseServiceHandle(schService);
    CloseServiceHandle(schSCManager);
    return;
    }
    else printf("Service start pending...\n");

    // Check the status until the service is no longer start pending.

    if (!QueryServiceStatusEx(
    schService, // handle to service
    SC_STATUS_PROCESS_INFO, // info level
    (LPBYTE) &ssStatus, // address of structure
    sizeof(SERVICE_STATUS_PROCESS), // size of structure
    &dwBytesNeeded ) ) // if buffer too small
    {
    printf("QueryServiceStatusEx failed (%d)\n", GetLastError());
    CloseServiceHandle(schService);
    CloseServiceHandle(schSCManager);
    return;
    }

    // Save the tick count and initial checkpoint.

    dwStartTickCount = GetTickCount();
    dwOldCheckPoint = ssStatus.dwCheckPoint;

    while (ssStatus.dwCurrentState == SERVICE_START_PENDING)
    {
    // Do not wait longer than the wait hint. A good interval is
    // one-tenth the wait hint, but no less than 1 second and no
    // more than 10 seconds.

    dwWaitTime = ssStatus.dwWaitHint / 10;

    if( dwWaitTime < 1000 )
    dwWaitTime = 1000;
    else if ( dwWaitTime > 10000 )
    dwWaitTime = 10000;

    Sleep( dwWaitTime );

    // Check the status again.

    if (!QueryServiceStatusEx(
    schService, // handle to service
    SC_STATUS_PROCESS_INFO, // info level
    (LPBYTE) &ssStatus, // address of structure
    sizeof(SERVICE_STATUS_PROCESS), // size of structure
    &dwBytesNeeded ) ) // if buffer too small
    {
    printf("QueryServiceStatusEx failed (%d)\n", GetLastError());
    break;
    }

    if ( ssStatus.dwCheckPoint > dwOldCheckPoint )
    {
    // Continue to wait and check.

    dwStartTickCount = GetTickCount();
    dwOldCheckPoint = ssStatus.dwCheckPoint;
    }
    else
    {
    if(GetTickCount()-dwStartTickCount > ssStatus.dwWaitHint)
    {
    // No progress made within the wait hint.
    break;
    }
    }
    }

    // Determine whether the service is running.

    if (ssStatus.dwCurrentState == SERVICE_RUNNING)
    {
    printf("Service started successfully.\n");
    }
    else
    {
    printf("Service not started. \n");
    printf(" Current State: %d\n", ssStatus.dwCurrentState);
    printf(" Exit Code: %d\n", ssStatus.dwWin32ExitCode);
    printf(" Check Point: %d\n", ssStatus.dwCheckPoint);
    printf(" Wait Hint: %d\n", ssStatus.dwWaitHint);
    }

    CloseServiceHandle(schService);
    CloseServiceHandle(schSCManager);
    }

    //
    // Purpose:
    // Updates the service DACL to grant start, stop, delete, and read
    // control access to the Guest account.
    //
    // Parameters:
    // None
    //
    // Return value:
    // None
    //
    VOID __stdcall DoUpdateSvcDacl()
    {
    EXPLICIT_ACCESS ea;
    SECURITY_DESCRIPTOR sd;
    PSECURITY_DESCRIPTOR psd = NULL;
    PACL pacl = NULL;
    PACL pNewAcl = NULL;
    BOOL bDaclPresent = FALSE;
    BOOL bDaclDefaulted = FALSE;
    DWORD dwError = 0;
    DWORD dwSize = 0;
    DWORD dwBytesNeeded = 0;

    // Get a handle to the SCM database.

    schSCManager = OpenSCManager(
    NULL, // local computer
    NULL, // ServicesActive database
    STANDARD_RIGHTS_READ |
    SC_MANAGER_CONNECT |
    SC_MANAGER_ENUMERATE_SERVICE); // full access rights

    if (NULL == schSCManager)
    {
    printf("OpenSCManager failed (%d)\n", GetLastError());
    return;
    }

    // Get a handle to the service

    schService = OpenService(
    schSCManager, // SCManager database
    szSvcName, // name of service
    READ_CONTROL | WRITE_DAC); // access

    if (schService == NULL)
    {
    printf("OpenService failed (%d)\n", GetLastError());
    CloseServiceHandle(schSCManager);
    return;
    }

    // Get the current security descriptor.

    if (!QueryServiceObjectSecurity(schService,
    DACL_SECURITY_INFORMATION,
    &psd, // using NULL does not work on all versions
    0,
    &dwBytesNeeded))
    {
    if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
    {
    dwSize = dwBytesNeeded;
    psd = (PSECURITY_DESCRIPTOR)HeapAlloc(GetProcessHeap(),
    HEAP_ZERO_MEMORY, dwSize);
    if (psd == NULL)
    {
    // Note: HeapAlloc does not support GetLastError.
    printf("HeapAlloc failed\n");
    goto dacl_cleanup;
    }

    if (!QueryServiceObjectSecurity(schService,
    DACL_SECURITY_INFORMATION, psd, dwSize, &dwBytesNeeded))
    {
    printf("QueryServiceObjectSecurity failed (%d)\n", GetLastError());
    goto dacl_cleanup;
    }
    }
    else
    {
    printf("QueryServiceObjectSecurity failed (%d)\n", GetLastError());
    goto dacl_cleanup;
    }
    }

    // Get the DACL.

    if (!GetSecurityDescriptorDacl(psd, &bDaclPresent, &pacl,
    &bDaclDefaulted))
    {
    printf("GetSecurityDescriptorDacl failed(%d)\n", GetLastError());
    goto dacl_cleanup;
    }

    // Build the ACE. GUEST

    BuildExplicitAccessWithName(&ea, TEXT("EVERYONE"),
    SERVICE_START | SERVICE_STOP | READ_CONTROL | DELETE,
    SET_ACCESS, CONTAINER_INHERIT_ACE);

    dwError = SetEntriesInAcl(1, &ea, pacl, &pNewAcl);
    if (dwError != ERROR_SUCCESS)
    {
    printf("SetEntriesInAcl failed(%d)\n", dwError);
    goto dacl_cleanup;
    }

    // Initialize a new security descriptor.

    if (!InitializeSecurityDescriptor(&sd,
    SECURITY_DESCRIPTOR_REVISION))
    {
    printf("InitializeSecurityDescriptor failed(%d)\n", GetLastError());
    goto dacl_cleanup;
    }

    // Set the new DACL in the security descriptor.

    if (!SetSecurityDescriptorDacl(&sd, TRUE, pNewAcl, FALSE))
    {
    printf("SetSecurityDescriptorDacl failed(%d)\n", GetLastError());
    goto dacl_cleanup;
    }

    // Set the new DACL for the service object.

    if (!SetServiceObjectSecurity(schService,
    DACL_SECURITY_INFORMATION, &sd))
    {
    printf("SetServiceObjectSecurity failed(%d)\n", GetLastError());
    goto dacl_cleanup;
    }
    else printf("Service DACL updated successfully\n");

    dacl_cleanup:
    CloseServiceHandle(schSCManager);
    CloseServiceHandle(schService);

    if(NULL != pNewAcl)
    LocalFree((HLOCAL)pNewAcl);
    if(NULL != psd)
    HeapFree(GetProcessHeap(), 0, (LPVOID)psd);
    }

    //
    // Purpose:
    // Stops the service.
    //
    // Parameters:
    // None
    //
    // Return value:
    // None
    //
    VOID __stdcall DoStopSvc()
    {
    SERVICE_STATUS_PROCESS ssp;
    DWORD dwStartTime = GetTickCount();
    DWORD dwBytesNeeded;
    DWORD dwTimeout = 30000; // 30-second time-out
    DWORD dwWaitTime;

    // Get a handle to the SCM database.

    schSCManager = OpenSCManager(
    NULL, // local computer
    NULL, // ServicesActive database
    STANDARD_RIGHTS_READ |
    SC_MANAGER_CONNECT |
    SC_MANAGER_ENUMERATE_SERVICE ); // full access rights

    if (NULL == schSCManager)
    {
    printf("OpenSCManager failed (%d)\n", GetLastError());
    return;
    }

    // Get a handle to the service.

    schService = OpenService(
    schSCManager, // SCM database
    szSvcName, // name of service
    SERVICE_STOP |
    SERVICE_QUERY_STATUS |
    SERVICE_ENUMERATE_DEPENDENTS);

    if (schService == NULL)
    {
    printf("OpenService failed (%d)\n", GetLastError());
    CloseServiceHandle(schSCManager);
    return;
    }

    // Make sure the service is not already stopped.

    if ( !QueryServiceStatusEx(
    schService,
    SC_STATUS_PROCESS_INFO,
    (LPBYTE)&ssp,
    sizeof(SERVICE_STATUS_PROCESS),
    &dwBytesNeeded ) )
    {
    printf("QueryServiceStatusEx failed (%d)\n", GetLastError());
    goto stop_cleanup;
    }

    if ( ssp.dwCurrentState == SERVICE_STOPPED )
    {
    printf("Service is already stopped.\n");
    goto stop_cleanup;
    }

    // If a stop is pending, wait for it.

    while ( ssp.dwCurrentState == SERVICE_STOP_PENDING )
    {
    printf("Service stop pending...\n");

    // Do not wait longer than the wait hint. A good interval is
    // one-tenth of the wait hint but not less than 1 second
    // and not more than 10 seconds.

    dwWaitTime = ssp.dwWaitHint / 10;

    if( dwWaitTime < 1000 )
    dwWaitTime = 1000;
    else if ( dwWaitTime > 10000 )
    dwWaitTime = 10000;

    Sleep( dwWaitTime );

    if ( !QueryServiceStatusEx(
    schService,
    SC_STATUS_PROCESS_INFO,
    (LPBYTE)&ssp,
    sizeof(SERVICE_STATUS_PROCESS),
    &dwBytesNeeded ) )
    {
    printf("QueryServiceStatusEx failed (%d)\n", GetLastError());
    goto stop_cleanup;
    }

    if ( ssp.dwCurrentState == SERVICE_STOPPED )
    {
    printf("Service stopped successfully.\n");
    goto stop_cleanup;
    }

    if ( GetTickCount() - dwStartTime > dwTimeout )
    {
    printf("Service stop timed out.\n");
    goto stop_cleanup;
    }
    }

    // If the service is running, dependencies must be stopped first.

    StopDependentServices();

    // Send a stop code to the service.

    if ( !ControlService(
    schService,
    SERVICE_CONTROL_STOP,
    (LPSERVICE_STATUS) &ssp ) )
    {
    printf( "ControlService failed (%d)\n", GetLastError() );
    goto stop_cleanup;
    }

    // Wait for the service to stop.

    while ( ssp.dwCurrentState != SERVICE_STOPPED )
    {
    Sleep( ssp.dwWaitHint );
    if ( !QueryServiceStatusEx(
    schService,
    SC_STATUS_PROCESS_INFO,
    (LPBYTE)&ssp,
    sizeof(SERVICE_STATUS_PROCESS),
    &dwBytesNeeded ) )
    {
    printf( "QueryServiceStatusEx failed (%d)\n", GetLastError() );
    goto stop_cleanup;
    }

    if ( ssp.dwCurrentState == SERVICE_STOPPED )
    break;

    if ( GetTickCount() - dwStartTime > dwTimeout )
    {
    printf( "Wait timed out\n" );
    goto stop_cleanup;
    }
    }
    printf("Service stopped successfully\n");

    stop_cleanup:
    CloseServiceHandle(schService);
    CloseServiceHandle(schSCManager);
    }

    BOOL __stdcall StopDependentServices()
    {
    DWORD i;
    DWORD dwBytesNeeded;
    DWORD dwCount;

    LPENUM_SERVICE_STATUS lpDependencies = NULL;
    ENUM_SERVICE_STATUS ess;
    SC_HANDLE hDepService;
    SERVICE_STATUS_PROCESS ssp;

    DWORD dwStartTime = GetTickCount();
    DWORD dwTimeout = 30000; // 30-second time-out

    // Pass a zero-length buffer to get the required buffer size.
    if ( EnumDependentServices( schService, SERVICE_ACTIVE,
    lpDependencies, 0, &dwBytesNeeded, &dwCount ) )
    {
    // If the Enum call succeeds, then there are no dependent
    // services, so do nothing.
    return TRUE;
    }
    else
    {
    if ( GetLastError() != ERROR_MORE_DATA )
    return FALSE; // Unexpected error

    // Allocate a buffer for the dependencies.
    lpDependencies = (LPENUM_SERVICE_STATUS) HeapAlloc(
    GetProcessHeap(), HEAP_ZERO_MEMORY, dwBytesNeeded );

    if ( !lpDependencies )
    return FALSE;

    __try {
    // Enumerate the dependencies.
    if ( !EnumDependentServices( schService, SERVICE_ACTIVE,
    lpDependencies, dwBytesNeeded, &dwBytesNeeded,
    &dwCount ) )
    return FALSE;

    for ( i = 0; i < dwCount; i++ )
    {
    ess = *(lpDependencies + i);
    // Open the service.
    hDepService = OpenService( schSCManager,
    ess.lpServiceName,
    SERVICE_STOP | SERVICE_QUERY_STATUS );

    if ( !hDepService )
    return FALSE;

    __try {
    // Send a stop code.
    if ( !ControlService( hDepService,
    SERVICE_CONTROL_STOP,
    (LPSERVICE_STATUS) &ssp ) )
    return FALSE;

    // Wait for the service to stop.
    while ( ssp.dwCurrentState != SERVICE_STOPPED )
    {
    Sleep( ssp.dwWaitHint );
    if ( !QueryServiceStatusEx(
    hDepService,
    SC_STATUS_PROCESS_INFO,
    (LPBYTE)&ssp,
    sizeof(SERVICE_STATUS_PROCESS),
    &dwBytesNeeded ) )
    return FALSE;

    if ( ssp.dwCurrentState == SERVICE_STOPPED )
    break;

    if ( GetTickCount() - dwStartTime > dwTimeout )
    return FALSE;
    }
    }
    __finally
    {
    // Always release the service handle.
    CloseServiceHandle( hDepService );
    }
    }
    }
    __finally
    {
    // Always free the enumeration buffer.
    HeapFree( GetProcessHeap(), 0, lpDependencies );
    }
    }
    return TRUE;
    }

    转载于:https://www.cnblogs.com/chengliangkaka/p/3471673.html

    展开全文
  • Vista 和 Windows 7 操作系统为了加强安全,增加了 UAC(用户账户控制) 的机制,如果 UAC 被打开,用户即使是以管理员权限登录,其应用程序默认情况下也无法对系统目录,系统注册表等可能影响系统运行的设置进行写...
  • Vista 和 Windows 7 操作系统为了加强安全,增加了 UAC(用户账户控制) 的机制,如果 UAC 被打开,用户即使是以管理员权限登录,其应用程序默认情况下也无法对系统目录,系统注册表等可能影响系统运行的设置进行写...
  • 当我们从经典的 windows XP 系统升级到 win 7win 10,我们会发现,想要删除一些文件时,总是提示被占用或者是没有权限,很是烦恼。  这里,写下解决这个烦恼的办法,以安慰心里的不平。  1、新建一个 TXT ...
  • 双击运行,即可将“获取超级管理员权限”功能附加到右键菜单,鼠标选中一个文件或文件夹后右键,点击“获取超级管理员权限”即可获取超级管理员权限,下载和使用前关闭360等软件,防止被误删。 win7,win8亲测好使,...
  • 最近要用到windows的telnet功能,本来是很简单的事情,因为管理员权限的问题,花了不少时间,才发现是管理员权限惹的祸,更滑稽的是,自己一直以来都不是管理员,是普通用户,想到之前安装软件时,也有类似的问题,...
  • Vista 和 Windows 7 操作系统为了加强安全,增加了 UAC(用户账户控制) 的机制,如果 UAC 被打开,用户即使是以管理员权限登录,其应用程序默认情况下也无法对系统目录,系统注册表等可能影响系统运行的设置进行写...
  • Vista 和 Windows 7 操作系统为了加强安全,增加了 UAC(用户账户控制) 的机制,如果 UAC 被打开,用户即使是以管理员权限登录,其应用程序默认情况下也无法对系统目录,系统注册表等可能影响系统运行的设置进行写...
  • Win7系统的人应该知道UAC是什么了,关掉UAC可以省掉很多麻烦事,同时也看不到程序图标上的小盾牌,也不会提示获取系统权限的对话框。 这里讨论没有关闭UAC的情况,默认情况下运行的程序是不具有系统权限的,也...
  • Win7/Win8.1一样,Win10的管理员账户Administrator是默认隐藏和关闭的,因为该账户权限极高,被不法分子利用后存在极大风险。但如果你想在某些特殊情况下使用该账户,就需要手动将其开启,并且最好在使用之后及时...
  • 本来想不关闭UAC,保持win7原功能的,但是他的UAC实在太恶心了,无法忍受了!!必须关闭了!! Why/?> 用UAC管理员运行cmd,工作目录总是在system32下,任何批处理运行,也会转到system32下 例如: 许多批处理本来直接...
  • win7 关闭启动修复

    2020-06-17 14:44:48
    1.以管理员权限启动命令提示符,方法:打开「开始」菜单,输入cmd,待系统找到cmd.exe后,在其上点击鼠标右键,选择「以管理员权限运行」 2.依次输入以下命令并回车:bcdedit /set {current} bootstatuspolicy ...
  • 管理员运行Cmd,并输入:netsh wlan set hostednetwork mode=allow ssid=QQ key=805698955 (ssid:账号,key=密码) 帮助:https://jingyan.baidu.com/article/59a015e378f85ff79488659e.html 二、代码 public...
  • 现在买的笔记本后者台式机 有预装系统的家庭版的win7 系统的用户基本上都是个人用户,  大家在使用一些软件的时候需要管理员权限才能使用,有时候很烦。但是家庭版的超级管理员用户又给关闭了。  这里分享个方法...
  • 殊不知道关闭了UAC的WIN7比XP还要流畅许多。WIN7中彻底关闭UAC的方法很简单,在 控制面板里搜索(右上角敲入uac),便可进入 更改用户账户设置,把下拉条拉到从不通知,重启电脑便OK了。这是非adm...

空空如也

空空如也

1 2 3 4 5 ... 11
收藏数 209
精华内容 83
关键字:

win7关闭管理员权限