Hi all,
I never use the admin account and always use the standard account for my day to day activities. Adding HWiNFO to my startup will always ask for admin password since it requires elevated privileges. I wanted to bypass the UAC prompt and spent some time on this topic. Its very difficult but I came across a program called "runasspc" which will store your admin password encyrpted and then during startup, can run HWiNFO during standard login. More research indicated that the program uses the Win32 API, CreateProcessWithLogonW(). Note: There is a slight element of risk since admin password is in clear text when this API will be called. Anyway, "runasspc" satisfied my needs but sometimes it would randomly pop a dialog about its free license. So I decided to write a simple program myself that would start HWiNFO using same API.
I looked at the MSDN example for CreateProcessWithLogonW() and after lots of trials and errors and research, I was able to run HWiNFO as an admin from standard account without password. The trick was to use cmd.exe to start the program. Here is the program I used:
// runasadmin.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <Windows.h>
#include <stdio.h>
#include <UserEnv.h>
void DisplayError(LPWSTR pszAPI)
{
LPVOID lpMsgBuf;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL,
GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPWSTR)&lpMsgBuf, 0, NULL);
wprintf(L"API = %s, Error code=%d, msg=%s\n", pszAPI, GetLastError(), (LPWSTR)lpMsgBuf);
LocalFree(lpMsgBuf);
ExitProcess(GetLastError());
}
int _tmain(int argc, _TCHAR* argv[])
{
PROCESS_INFORMATION pi = { 0 };
STARTUPINFO si = { 0 };
WCHAR szUser[256] = L"admin"; //account that has elevated privileges
WCHAR szDomain[256] = L"domain";
WCHAR szPass[256] = L"password";
WCHAR szApp[256] = L"cmd.exe /C start \"\" D:\\HWiNFO64\\HWiNFO64.exe";
WCHAR szDir[256] = L"D:\\HWiNFO64\\";
si.cb = sizeof(STARTUPINFO);
if (!CreateProcessWithLogonW(szUser, szDomain, szPass, LOGON_WITH_PROFILE,
NULL, szApp, CREATE_UNICODE_ENVIRONMENT, NULL,
szDir, &si, &pi)) {
DisplayError(L"CreateProcess");
}
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
return 0;
}
Compile and put this in your startup path and you will be able to run HWiNFO from standard account without password. Make changes as necessary.
Note: As seen above, the password is in clear text. So use it at your own risk.
Thanks,
- Arun
I never use the admin account and always use the standard account for my day to day activities. Adding HWiNFO to my startup will always ask for admin password since it requires elevated privileges. I wanted to bypass the UAC prompt and spent some time on this topic. Its very difficult but I came across a program called "runasspc" which will store your admin password encyrpted and then during startup, can run HWiNFO during standard login. More research indicated that the program uses the Win32 API, CreateProcessWithLogonW(). Note: There is a slight element of risk since admin password is in clear text when this API will be called. Anyway, "runasspc" satisfied my needs but sometimes it would randomly pop a dialog about its free license. So I decided to write a simple program myself that would start HWiNFO using same API.
I looked at the MSDN example for CreateProcessWithLogonW() and after lots of trials and errors and research, I was able to run HWiNFO as an admin from standard account without password. The trick was to use cmd.exe to start the program. Here is the program I used:
// runasadmin.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <Windows.h>
#include <stdio.h>
#include <UserEnv.h>
void DisplayError(LPWSTR pszAPI)
{
LPVOID lpMsgBuf;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL,
GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPWSTR)&lpMsgBuf, 0, NULL);
wprintf(L"API = %s, Error code=%d, msg=%s\n", pszAPI, GetLastError(), (LPWSTR)lpMsgBuf);
LocalFree(lpMsgBuf);
ExitProcess(GetLastError());
}
int _tmain(int argc, _TCHAR* argv[])
{
PROCESS_INFORMATION pi = { 0 };
STARTUPINFO si = { 0 };
WCHAR szUser[256] = L"admin"; //account that has elevated privileges
WCHAR szDomain[256] = L"domain";
WCHAR szPass[256] = L"password";
WCHAR szApp[256] = L"cmd.exe /C start \"\" D:\\HWiNFO64\\HWiNFO64.exe";
WCHAR szDir[256] = L"D:\\HWiNFO64\\";
si.cb = sizeof(STARTUPINFO);
if (!CreateProcessWithLogonW(szUser, szDomain, szPass, LOGON_WITH_PROFILE,
NULL, szApp, CREATE_UNICODE_ENVIRONMENT, NULL,
szDir, &si, &pi)) {
DisplayError(L"CreateProcess");
}
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
return 0;
}
Compile and put this in your startup path and you will be able to run HWiNFO from standard account without password. Make changes as necessary.
Note: As seen above, the password is in clear text. So use it at your own risk.
Thanks,
- Arun