Peter Müller
asked on
C++ :Change value from DisableCMD registry
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\Softwar e\Policies \Microsoft \Windows\S ystem\Disa bleCMD "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 bAlreadyRunningAsAdministr ator = FALSE;
try
{
bAlreadyRunningAsAdministr ator = IsRunAsAdministrator();
}
catch (...)
{
_asm nop
}
if (!bAlreadyRunningAsAdminis trator)
{
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)El evateNow, 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_RI D,
DOMAIN_ALIAS_RID_ADMINS,
0, 0, 0, 0, 0, 0,
&pAdministratorsGroup))
{
dwError = GetLastError();
goto Cleanup;
}
if (!CheckTokenMembership(NUL L, pAdministratorsGroup, &fIsRunAsAdmin))
{
dwError = GetLastError();
goto Cleanup;
}
Cleanup:
if (pAdministratorsGroup)
{
std::cout << "Mal sehnen ob das geht ;)";
FreeSid(pAdministratorsGro up);
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;
}
i would like to change the value from the from (HKEY_CURRENT_USER\Softwar
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 bAlreadyRunningAsAdministr
try
{
bAlreadyRunningAsAdministr
}
catch (...)
{
_asm nop
}
if (!bAlreadyRunningAsAdminis
{
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)El
}
}
}
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_RI
DOMAIN_ALIAS_RID_ADMINS,
0, 0, 0, 0, 0, 0,
&pAdministratorsGroup))
{
dwError = GetLastError();
goto Cleanup;
}
if (!CheckTokenMembership(NUL
{
dwError = GetLastError();
goto Cleanup;
}
Cleanup:
if (pAdministratorsGroup)
{
std::cout << "Mal sehnen ob das geht ;)";
FreeSid(pAdministratorsGro
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;
}
ASKER
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\Sy stem\Disab leCMD "Start (REG_DWORD) data thats my real question
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
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:Hope that helps,
ZOPPO