Solved

C++ :Change value from  DisableCMD registry

Posted on 2016-11-24
4
86 Views
Last Modified: 2016-11-24
Hey i have big problem i rly dunno how to do it i found  100 kinds of ways to do this but its not working:
i would like to change the value from the from (HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\System\DisableCMD "Start (REG_DWORD)") data to 0. I know i need admin rights to do this so i already have a code for this (scroll down) can someone give me an example how to do this?

p.s i would like to run this programm on a different pc so dont tell me could just change the (Standard) value,
 thanks for helping ;)







//Elevation.cpp
#include <Windows.h>
#include <iostream>

BOOL IsRunAsAdministrator();
void ElevateNow()
{
Reask:
      BOOL bAlreadyRunningAsAdministrator = FALSE;
      try
      {
            bAlreadyRunningAsAdministrator = IsRunAsAdministrator();
      }
      catch (...)
      {
            _asm nop
      }
      if (!bAlreadyRunningAsAdministrator)
      {
            char szPath[MAX_PATH];
            if (GetModuleFileName(NULL, szPath, ARRAYSIZE(szPath)))
            {


                  SHELLEXECUTEINFO sei = { sizeof(sei) };

                  sei.lpVerb = "runas";
                  sei.lpFile = szPath;
                  sei.hwnd = NULL;
                  sei.nShow = SW_NORMAL;

                  if (!ShellExecuteEx(&sei))
                  {
                        DWORD dwError = GetLastError();
                        if (dwError == ERROR_CANCELLED)
                              //Annoys you to Elevate it LOL
                              CreateThread(0, 0, (LPTHREAD_START_ROUTINE)ElevateNow, 0, 0, 0);
                  }
            }

      }
      else
      {
            goto Reask;
      }
}

 


//Determination.cpp
#include <Windows.h>
#include <iostream>

BOOL IsRunAsAdministrator()
{
      BOOL fIsRunAsAdmin = FALSE;
      DWORD dwError = ERROR_SUCCESS;
      PSID pAdministratorsGroup = NULL;

      SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY;
      if (!AllocateAndInitializeSid(
            &NtAuthority,
            2,
            SECURITY_BUILTIN_DOMAIN_RID,
            DOMAIN_ALIAS_RID_ADMINS,
            0, 0, 0, 0, 0, 0,
            &pAdministratorsGroup))
      {
            dwError = GetLastError();
            goto Cleanup;
      }

      if (!CheckTokenMembership(NULL, pAdministratorsGroup, &fIsRunAsAdmin))
      {
            dwError = GetLastError();
            goto Cleanup;
      }

Cleanup:

      if (pAdministratorsGroup)
      {
            std::cout << "Mal sehnen ob das geht ;)";
            FreeSid(pAdministratorsGroup);
            pAdministratorsGroup = NULL;
      }

      if (ERROR_SUCCESS != dwError)
      {
            throw dwError;
      }

      return fIsRunAsAdmin;
}

//main.cpp
int main()
{
      {
            if (IsRunAsAdministrator())
            {
            }
            else
            {
                  if (MessageBox(0, "Need To Elevate", "Critical Disk Error", MB_SYSTEMMODAL | MB_ICONERROR | MB_YESNO) == IDYES) //Adminrechte bekommen
                  {
                        ElevateNow();
                        std::cout << "Tst";
                  }
                  else
                  {
                        std::cout << "Tst";
                        MessageBox(0, "You Better give me Elevation or I will attack u", "System Critical Error", MB_SYSTEMMODAL | MB_OK | MB_ICONERROR);
                        ElevateNow();
                  }
            }

      }
  }
  return 0;
}
0
Comment
Question by:Peter Müller
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 31

Expert Comment

by:Zoppo
ID: 41900642
Hi Peter Müller,

which Visual Studio version do you use? And in what Windows versions should this run at minimum?

I ask because at least since VS 2010 (I had no older version to check) there's a really simple way to ensure an application can only be started as administator via a linker option, but this won't work on Windows versions before Windows Vista because it's using UAC via a manifest:UAC exection levelHope that helps,

ZOPPO
0
 

Author Comment

by:Peter Müller
ID: 41900657
Thanks for your anwser Zoppo!

Im using Visual Studio 2013 and min windows 7,
but that is not my problem i can easyly run my programm as admin with my code!  I want to know how change the value from this HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\System\DisableCMD "Start (REG_DWORD) data thats my real question
0
 
LVL 31

Accepted Solution

by:
Zoppo earned 500 total points
ID: 41900784
ok, sorry, I misunderstood.

The functions to open, read and set a value in registry are:

- open the registry: RegOpenKeyEx
- query the value: RegQueryValueEx
- set the value: RegSetValueEx
- close the registry: RegCloseKey

So what you want to do should work somehow like this (untested) sample:
HKEY hKey;
if ( FAILED( RegOpenKeyEx( HKEY_CURRENT_USER, "Software\\Policies\\Microsoft\\Windows\\System\\DisableCMD", 0, KEY_READ| KEY_WRITE , &hKey ) ) )
{
 return; // error
}

DWORD dwValue, dwSize = sizeof( DWORD );

if ( !FAILED( RegQueryValueEx( hKey, "Start", NULL, NULL, (LPBYTE)&dwValue, &dwSize ) ) )
{
  dwValue = 0;

  if ( !FAILED( RegSetValueEx( hKey, "Start", NULL, REG_DWORD, (LPBYTE)&dwValue, sizeof( DWORD ) ) ) )
  {
    // everything worked
  }
}

RegCloseKey( hKey );

Open in new window


ZOPPO
0
 

Author Closing Comment

by:Peter Müller
ID: 41900794
Thanks that worked for me i ll play i little bit with the commands and try to figure out how u did it thanks <3
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question